This commit is contained in:
afrokick 2019-12-15 13:27:56 +03:00
parent d46628067b
commit 17e0177670
3 changed files with 18 additions and 9 deletions

17
package-lock.json generated
View File

@ -160,6 +160,15 @@
"@types/mime": "*" "@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": { "@types/ws": {
"version": "6.0.2", "version": "6.0.2",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-6.0.2.tgz", "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", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
"integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM="
}, },
"uuid4": { "uuid": {
"version": "1.1.4", "version": "3.3.3",
"resolved": "https://registry.npmjs.org/uuid4/-/uuid4-1.1.4.tgz", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.3.tgz",
"integrity": "sha512-Gr1q2k40LpF8CokcnQFjPDsdslzJbTCTBG5xQIEflUov431gFkY5KduiGIeKYAamkQnNn4IfdHJbLnl9Bib8TQ==" "integrity": "sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ=="
}, },
"v8-compile-cache": { "v8-compile-cache": {
"version": "2.1.0", "version": "2.1.0",

View File

@ -34,13 +34,14 @@
"cors": "~2.8.4", "cors": "~2.8.4",
"express": "^4.17.1", "express": "^4.17.1",
"optimist": "~0.6.1", "optimist": "~0.6.1",
"uuid4": "^1.1.4", "uuid": "3.3.3",
"ws": "^7.1.2" "ws": "^7.1.2"
}, },
"devDependencies": { "devDependencies": {
"@types/chai": "^4.1.7", "@types/chai": "^4.1.7",
"@types/mocha": "^5.2.7", "@types/mocha": "^5.2.7",
"@types/node": "^10.14.16", "@types/node": "^10.14.16",
"@types/uuid": "^3.4.6",
"@typescript-eslint/eslint-plugin": "^2.0.0", "@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0", "@typescript-eslint/parser": "^2.0.0",
"chai": "^4.2.0", "chai": "^4.2.0",

View File

@ -1,3 +1,4 @@
import uuidv4 from "uuid/v4";
import { IClient } from "./client"; import { IClient } from "./client";
import { IMessage } from "./message"; import { IMessage } from "./message";
import { IMessageQueue, MessageQueue } from "./messageQueue"; import { IMessageQueue, MessageQueue } from "./messageQueue";
@ -69,12 +70,10 @@ export class Realm implements IRealm {
} }
public generateClientId(): string { public generateClientId(): string {
const randomId = () => (Math.random().toString(36) + "0000000000000000000").substr(2, 16); let clientId = uuidv4();
let clientId = randomId();
while (this.getClientById(clientId)) { while (this.getClientById(clientId)) {
clientId = randomId(); clientId = uuidv4();
} }
return clientId; return clientId;