Skip to content

Commit

Permalink
Replace uuid package with built-in crypto.randomUUID()
Browse files Browse the repository at this point in the history
  • Loading branch information
piranna committed Aug 11, 2023
1 parent be98f0f commit fd8968f
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 69 deletions.
5 changes: 3 additions & 2 deletions node/src/PipeTransport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { v4 as uuidv4 } from 'uuid';
import { randomUUID } from 'crypto';

import { Logger } from './Logger';
import * as ortc from './ortc';
import {
Expand Down Expand Up @@ -322,7 +323,7 @@ export class PipeTransport<PipeTransportAppData extends AppData = AppData>

const reqData =
{
consumerId : uuidv4(),
consumerId : randomUUID(),
producerId,
kind : producer.kind,
rtpParameters,
Expand Down
15 changes: 8 additions & 7 deletions node/src/Router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { v4 as uuidv4 } from 'uuid';
import { randomUUID } from 'crypto';

import { Logger } from './Logger';
import { EnhancedEventEmitter } from './EnhancedEventEmitter';
import * as ortc from './ortc';
Expand Down Expand Up @@ -413,7 +414,7 @@ export class Router<RouterAppData extends AppData = AppData>

const reqData =
{
transportId : uuidv4(),
transportId : randomUUID(),
webRtcServerId : webRtcServer ? webRtcServer.id : undefined,
listenIps,
port,
Expand Down Expand Up @@ -525,7 +526,7 @@ export class Router<RouterAppData extends AppData = AppData>

const reqData =
{
transportId : uuidv4(),
transportId : randomUUID(),
listenIp,
port,
rtcpMux,
Expand Down Expand Up @@ -627,7 +628,7 @@ export class Router<RouterAppData extends AppData = AppData>

const reqData =
{
transportId : uuidv4(),
transportId : randomUUID(),
listenIp,
port,
enableSctp,
Expand Down Expand Up @@ -697,7 +698,7 @@ export class Router<RouterAppData extends AppData = AppData>

const reqData =
{
transportId : uuidv4(),
transportId : randomUUID(),
direct : true,
maxMessageSize
};
Expand Down Expand Up @@ -1083,7 +1084,7 @@ export class Router<RouterAppData extends AppData = AppData>

const reqData =
{
rtpObserverId : uuidv4(),
rtpObserverId : randomUUID(),
interval
};

Expand Down Expand Up @@ -1137,7 +1138,7 @@ export class Router<RouterAppData extends AppData = AppData>

const reqData =
{
rtpObserverId : uuidv4(),
rtpObserverId : randomUUID(),
maxEntries,
threshold,
interval
Expand Down
12 changes: 6 additions & 6 deletions node/src/Transport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { v4 as uuidv4 } from 'uuid';
import { randomUUID } from 'crypto';
import { Logger } from './Logger';
import { EnhancedEventEmitter } from './EnhancedEventEmitter';
import * as utils from './utils';
Expand Down Expand Up @@ -595,7 +595,7 @@ export class Transport
// do not include CNAME, create a random one.
else if (!this.#cnameForProducers)
{
this.#cnameForProducers = uuidv4().substr(0, 8);
this.#cnameForProducers = randomUUID().substring(0, 8);
}

// Override Producer's CNAME.
Expand All @@ -615,7 +615,7 @@ export class Transport

const reqData =
{
producerId : id || uuidv4(),
producerId : id ?? randomUUID(),
kind,
rtpParameters,
rtpMapping,
Expand Down Expand Up @@ -747,7 +747,7 @@ export class Transport

const reqData =
{
consumerId : uuidv4(),
consumerId : randomUUID(),
producerId,
kind : producer.kind,
rtpParameters,
Expand Down Expand Up @@ -844,7 +844,7 @@ export class Transport

const reqData =
{
dataProducerId : id || uuidv4(),
dataProducerId : id ?? randomUUID(),
type,
sctpStreamParameters,
label,
Expand Down Expand Up @@ -967,7 +967,7 @@ export class Transport

const reqData =
{
dataConsumerId : uuidv4(),
dataConsumerId : randomUUID(),
dataProducerId,
type,
sctpStreamParameters,
Expand Down
7 changes: 4 additions & 3 deletions node/src/Worker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as process from 'process';
import * as path from 'path';
import { spawn, ChildProcess } from 'child_process';
import { v4 as uuidv4 } from 'uuid';
import { randomUUID } from 'crypto';

import { Logger } from './Logger';
import { EnhancedEventEmitter } from './EnhancedEventEmitter';
import * as ortc from './ortc';
Expand Down Expand Up @@ -635,7 +636,7 @@ export class Worker<WorkerAppData extends AppData = AppData>

const reqData =
{
webRtcServerId : uuidv4(),
webRtcServerId : randomUUID(),
listenInfos
};

Expand Down Expand Up @@ -676,7 +677,7 @@ export class Worker<WorkerAppData extends AppData = AppData>
// This may throw.
const rtpCapabilities = ortc.generateRouterRtpCapabilities(mediaCodecs);

const reqData = { routerId: uuidv4() };
const reqData = { routerId: randomUUID() };

await this.#channel.request('worker.createRouter', undefined, reqData);

Expand Down
29 changes: 1 addition & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,13 @@
"h264-profile-level-id": "^1.0.1",
"node-fetch": "^3.3.2",
"supports-color": "^9.4.0",
"tar": "^6.1.15",
"uuid": "^9.0.0"
"tar": "^6.1.15"
},
"devDependencies": {
"@octokit/rest": "^20.0.1",
"@types/debug": "^4.1.8",
"@types/jest": "^29.5.3",
"@types/node": "^20.4.9",
"@types/uuid": "^9.0.2",
"@typescript-eslint/eslint-plugin": "^6.3.0",
"@typescript-eslint/parser": "^6.3.0",
"eslint": "^8.46.0",
Expand Down
22 changes: 2 additions & 20 deletions worker/scripts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fd8968f

Please sign in to comment.