Skip to content

Commit

Permalink
replace uuid module with crypto version
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Dec 25, 2024
1 parent 521aaf8 commit ed53b99
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 23 deletions.
14 changes: 0 additions & 14 deletions package-lock.json

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

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"srt-webvtt": "^2.0.0",
"stripe": "^8.222.0",
"twitch-m3u8": "^1.1.5",
"uuid": "^9.0.1",
"webtorrent": "^2.1.34"
},
"scripts": {
Expand Down Expand Up @@ -104,7 +103,6 @@
"@types/react-transition-group": "^4.4.10",
"@types/recharts": "^1.8.29",
"@types/ssh2-streams": "^0.1.12",
"@types/uuid": "^9.0.7",
"@types/webtorrent": "^0.109.7",
"@types/youtube": "^0.0.50",
"husky": "^4.3.8",
Expand Down
6 changes: 3 additions & 3 deletions server/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { AssignedVM } from './vm/base';
import { getStartOfDay } from './utils/time';
import { postgres, updateObject, upsertObject } from './utils/postgres';
import { fetchYoutubeVideo, getYoutubeVideoID } from './utils/youtube';
import { v4 as uuidv4 } from 'uuid';
//@ts-ignore
import twitch from 'twitch-m3u8';
import { QueryResult } from 'pg';
Expand Down Expand Up @@ -806,7 +805,8 @@ export class Room {
if (data?.mediasoup) {
// TODO validate the user has permissions to ask for a mediasoup
// TODO set up the room on the remote server rather than letting the remote server create
mediasoupSuffix = '@' + config.MEDIASOUP_SERVER + '/' + uuidv4();
mediasoupSuffix =
'@' + config.MEDIASOUP_SERVER + '/' + crypto.randomUUID();
redisCount('mediasoupStarts');
}
if (data && data.file) {
Expand Down Expand Up @@ -977,7 +977,7 @@ export class Room {
let assignment: AssignedVM | undefined = undefined;
try {
if (stateless) {
const pass = uuidv4();
const pass = crypto.randomUUID();
const id = await stateless.startVM(pass);
assignment = {
...(await stateless.getVM(id)),
Expand Down
3 changes: 1 addition & 2 deletions server/vm/base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import config from '../config';
import axios from 'axios';
import { v4 as uuidv4 } from 'uuid';
import { redis, redisCount } from '../utils/redis';
import { postgres as pg } from '../utils/postgres';
import { PoolConfig, PoolRegion } from './utils';
Expand Down Expand Up @@ -221,7 +220,7 @@ export abstract class VMManager {

public startVMWrapper = async () => {
// generate credentials and boot a VM
const password = uuidv4();
const password = crypto.randomUUID();
const id = await this.startVM(password);
// We might fail to record it if crashing here but cleanup will reset it
await postgres.query(
Expand Down
13 changes: 11 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//@ts-ignore
import canAutoplay from 'can-autoplay';
import { v4 as uuidv4 } from 'uuid';
import { MD5 } from './md5';
import firebase from 'firebase/compat/app';
import { XMLParser } from 'fast-xml-parser';
Expand Down Expand Up @@ -343,7 +342,8 @@ export function getOrCreateClientId() {
let clientId = window.localStorage.getItem('watchparty-clientid');
if (!clientId) {
// Generate a new clientID and save it
clientId = uuidv4();
// This requires https, so fallback to JS implementation if needed
clientId = crypto.randomUUID ? crypto.randomUUID() : uuidv4();
window.localStorage.setItem('watchparty-clientid', clientId);
}
return clientId;
Expand Down Expand Up @@ -398,3 +398,12 @@ export const isEmojiString = (input: string): boolean => {
input,
);
};

function uuidv4() {
return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c) =>
(
+c ^
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (+c / 4)))
).toString(16),
);
}

0 comments on commit ed53b99

Please sign in to comment.