Skip to content

Commit

Permalink
revert(uuid): revert uuid useage
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib committed Dec 15, 2022
1 parent b52cab1 commit cac8bfc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-transport",
"version": "3.3.3",
"version": "3.3.4",
"description": "A simple and responsible transport",
"main": "lib/index.js",
"unpkg": "dist/index.umd.js",
Expand Down
14 changes: 13 additions & 1 deletion src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,19 @@ export abstract class Transport<T = any, P = any> {
const hasRespond = params.respond ?? true;
const timeout = params.timeout ?? this[timeoutKey];
const name = params.name ?? options;
const transportId = uuid();
const transportId = uuid({
// In nodejs, crypto.getRandomValues() not supported.
// workaround: https://github.com/uuidjs/uuid/issues/375
rng() {
const randomNumbers: number[] = new Array(16);
let r;
for (let i = 0; i < 16; i++) {
if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
randomNumbers[i] = ((r as number) >>> ((i & 0x03) << 3)) & 0xff;
}
return randomNumbers;
},
});
if (__DEV__ && (!name || typeof name !== 'string')) {
throw new Error(`The event name should be a string, and it's required.`);
}
Expand Down

0 comments on commit cac8bfc

Please sign in to comment.