diff --git a/package-lock.json b/package-lock.json index b327dae..fe10007 100644 --- a/package-lock.json +++ b/package-lock.json @@ -160,6 +160,15 @@ "@types/mime": "*" } }, + "@types/uuid": { + "version": "3.4.6", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-3.4.6.tgz", + "integrity": "sha512-cCdlC/1kGEZdEglzOieLDYBxHsvEOIg7kp/2FYyVR9Pxakq+Qf/inL3RKQ+PA8gOlI/NnL+fXmQH12nwcGzsHw==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/ws": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-6.0.2.tgz", @@ -4738,10 +4747,10 @@ "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" }, - "uuid4": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/uuid4/-/uuid4-1.1.4.tgz", - "integrity": "sha512-Gr1q2k40LpF8CokcnQFjPDsdslzJbTCTBG5xQIEflUov431gFkY5KduiGIeKYAamkQnNn4IfdHJbLnl9Bib8TQ==" + "uuid": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.3.tgz", + "integrity": "sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ==" }, "v8-compile-cache": { "version": "2.1.0", diff --git a/package.json b/package.json index 47dc2e8..4c8c956 100644 --- a/package.json +++ b/package.json @@ -34,13 +34,14 @@ "cors": "~2.8.4", "express": "^4.17.1", "optimist": "~0.6.1", - "uuid4": "^1.1.4", + "uuid": "3.3.3", "ws": "^7.1.2" }, "devDependencies": { "@types/chai": "^4.1.7", "@types/mocha": "^5.2.7", "@types/node": "^10.14.16", + "@types/uuid": "^3.4.6", "@typescript-eslint/eslint-plugin": "^2.0.0", "@typescript-eslint/parser": "^2.0.0", "chai": "^4.2.0", diff --git a/src/models/realm.ts b/src/models/realm.ts index 3f6fd1a..7b3ce19 100644 --- a/src/models/realm.ts +++ b/src/models/realm.ts @@ -1,3 +1,4 @@ +import uuidv4 from "uuid/v4"; import { IClient } from "./client"; import { IMessage } from "./message"; import { IMessageQueue, MessageQueue } from "./messageQueue"; @@ -69,12 +70,10 @@ export class Realm implements IRealm { } public generateClientId(): string { - const randomId = () => (Math.random().toString(36) + "0000000000000000000").substr(2, 16); - - let clientId = randomId(); + let clientId = uuidv4(); while (this.getClientById(clientId)) { - clientId = randomId(); + clientId = uuidv4(); } return clientId;