diff --git a/package.json b/package.json index 431dd80f2f..5d8cbc0576 100644 --- a/package.json +++ b/package.json @@ -92,7 +92,6 @@ "conf": "14.0.0", "custom-electron-prompt": "1.5.8", "deepmerge-ts": "7.1.5", - "delay": "6.0.0", "electron-debug": "4.1.0", "electron-is": "3.0.0", "electron-localshortcut": "3.2.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index adbea23a12..97a2789bf6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -123,9 +123,6 @@ importers: deepmerge-ts: specifier: 7.1.5 version: 7.1.5 - delay: - specifier: 6.0.0 - version: 6.0.0 electron-debug: specifier: 4.1.0 version: 4.1.0 @@ -2130,10 +2127,6 @@ packages: resolution: {integrity: sha512-R6ep6JJ+eOBZsBr9esiNN1gxFbZE4Q2cULkUSFumGYecAiS6qodDvcPx/sFuWHMNul7DWmrtoEOpYSm7o6tbSA==} engines: {node: '>=18'} - delay@6.0.0: - resolution: {integrity: sha512-2NJozoOHQ4NuZuVIr5CWd0iiLVIRSDepakaovIN+9eIDHEhdCAEvSy2cuf1DCrPPQLvHmbqTHODlhHg8UCy4zw==} - engines: {node: '>=16'} - delayed-stream@1.0.0: resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} engines: {node: '>=0.4.0'} @@ -6832,8 +6825,6 @@ snapshots: p-map: 7.0.3 slash: 5.1.0 - delay@6.0.0: {} - delayed-stream@1.0.0: {} detect-libc@2.0.4: {} diff --git a/src/plugins/music-together/connection.ts b/src/plugins/music-together/connection.ts index 7758fc5e2d..dd8590ef34 100644 --- a/src/plugins/music-together/connection.ts +++ b/src/plugins/music-together/connection.ts @@ -1,15 +1,9 @@ -import { - type DataConnection, - Peer, - type PeerError, - PeerErrorType, -} from 'peerjs'; -import delay from 'delay'; +import { type DataConnection, Peer, type PeerError } from 'peerjs'; import type { Permission, Profile, VideoData } from './types'; export type ConnectionEventMap = { - CLEAR_QUEUE: {}; + CLEAR_QUEUE: null; ADD_SONGS: { videoList: VideoData[]; index?: number }; REMOVE_SONG: { index: number }; MOVE_SONG: { fromIndex: number; toIndex: number }; @@ -104,16 +98,14 @@ export class Connection { this.peer.disconnect(); this.peer.destroy(); }); - this.peer.on('error', async (err) => { - if (err.type === PeerErrorType.Network) { - // retrying after 10 seconds - await delay(10000); - try { - this.peer.reconnect(); - return; - } catch { - //ignored - } + this.peer.on('error', (err) => { + if (err.type === 'network') { + setTimeout(() => { + try { + this.peer.reconnect(); + } catch {} + }, 10000); + return; } this.waitOpen.reject(err); @@ -176,7 +168,9 @@ export class Connection { after?: ConnectionEventUnion[], ) { await Promise.all( - this.getConnections().map((conn) => conn.send({ type, payload, after })), + this.getConnections().map( + (conn) => conn.send({ type, payload, after }) ?? Promise.resolve(), + ), ); } diff --git a/src/plugins/music-together/index.ts b/src/plugins/music-together/index.ts index d9590ca5a1..71a39384c5 100644 --- a/src/plugins/music-together/index.ts +++ b/src/plugins/music-together/index.ts @@ -224,7 +224,7 @@ export default createPlugin< } this.queue?.clear(); - await this.connection?.broadcast('CLEAR_QUEUE', {}); + await this.connection?.broadcast('CLEAR_QUEUE', null); break; } case 'SET_INDEX': { @@ -413,7 +413,7 @@ export default createPlugin< this.ignoreChange = true; switch (event.type) { case 'CLEAR_QUEUE': { - await this.connection?.broadcast('CLEAR_QUEUE', {}); + await this.connection?.broadcast('CLEAR_QUEUE', null); break; } case 'SET_INDEX': { diff --git a/src/plugins/music-together/queue/queue.ts b/src/plugins/music-together/queue/queue.ts index 0503af7616..edbfc51800 100644 --- a/src/plugins/music-together/queue/queue.ts +++ b/src/plugins/music-together/queue/queue.ts @@ -316,7 +316,7 @@ export class Queue { this.ignoreFlag = true; this.broadcast({ type: 'CLEAR_QUEUE', - payload: {}, + payload: null, }); return; }