diff --git a/package-lock.json b/package-lock.json index 77a70e4e7..4878e04d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,7 +50,6 @@ "srt-webvtt": "^2.0.0", "stripe": "^8.222.0", "twitch-m3u8": "^1.1.5", - "uuid": "^9.0.1", "webtorrent": "^2.1.34" }, "devDependencies": { @@ -67,7 +66,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", @@ -2830,12 +2828,6 @@ "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.10.tgz", "integrity": "sha512-IfYcSBWE3hLpBg8+X2SEa8LVkJdJEkT2Ese2aaLs3ptGdVtABxndrMaxuFlQ1qdFf9Q5rDvDpxI3WwgvKFAsQA==" }, - "node_modules/@types/uuid": { - "version": "9.0.7", - "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.7.tgz", - "integrity": "sha512-WUtIVRUZ9i5dYXefDEAI7sh9/O7jGvHg7Df/5O/gtH3Yabe5odI3UWopVR1qbPXQtvOxWu3mM4XxlYeZtMWF4g==", - "dev": true - }, "node_modules/@types/webtorrent": { "version": "0.109.7", "resolved": "https://registry.npmjs.org/@types/webtorrent/-/webtorrent-0.109.7.tgz", @@ -15287,12 +15279,6 @@ "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.10.tgz", "integrity": "sha512-IfYcSBWE3hLpBg8+X2SEa8LVkJdJEkT2Ese2aaLs3ptGdVtABxndrMaxuFlQ1qdFf9Q5rDvDpxI3WwgvKFAsQA==" }, - "@types/uuid": { - "version": "9.0.7", - "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.7.tgz", - "integrity": "sha512-WUtIVRUZ9i5dYXefDEAI7sh9/O7jGvHg7Df/5O/gtH3Yabe5odI3UWopVR1qbPXQtvOxWu3mM4XxlYeZtMWF4g==", - "dev": true - }, "@types/webtorrent": { "version": "0.109.7", "resolved": "https://registry.npmjs.org/@types/webtorrent/-/webtorrent-0.109.7.tgz", diff --git a/package.json b/package.json index 77a5da8f8..34fbbaee0 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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", diff --git a/server/room.ts b/server/room.ts index 5b75c2de8..1522bec5b 100644 --- a/server/room.ts +++ b/server/room.ts @@ -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'; @@ -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) { @@ -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)), diff --git a/server/vm/base.ts b/server/vm/base.ts index 408fd57d4..bb1a253fb 100644 --- a/server/vm/base.ts +++ b/server/vm/base.ts @@ -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'; @@ -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( diff --git a/src/utils/index.ts b/src/utils/index.ts index 09bbe7bb8..f91a667d8 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -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'; @@ -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; @@ -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), + ); +}