refactor(music-together): Removed delay dependency (#4201)

This commit is contained in:
its-iris
2026-02-03 10:55:51 +01:00
committed by GitHub
parent eab9f8ebcb
commit f403700bf7
5 changed files with 16 additions and 32 deletions

View File

@ -92,7 +92,6 @@
"conf": "14.0.0",
"custom-electron-prompt": "1.6.1",
"deepmerge-ts": "7.1.5",
"delay": "6.0.0",
"electron-debug": "4.1.0",
"electron-is": "3.0.0",
"electron-localshortcut": "3.2.1",

9
pnpm-lock.yaml generated
View File

@ -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
@ -2125,10 +2122,6 @@ packages:
resolution: {integrity: sha512-gPqh0mKTPvaUZGAuHbrBUYKZWBNAeHG7TU3QH5EhVwPMyKvmfJaNXhcD2jTcXsJRRcffuho4vaYweu80dRrMGA==}
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'}
@ -6705,8 +6698,6 @@ snapshots:
presentable-error: 0.0.1
slash: 5.1.0
delay@6.0.0: {}
delayed-stream@1.0.0: {}
detect-libc@2.1.2: {}

View File

@ -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(),
),
);
}

View File

@ -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': {

View File

@ -316,7 +316,7 @@ export class Queue {
this.ignoreFlag = true;
this.broadcast({
type: 'CLEAR_QUEUE',
payload: {},
payload: null,
});
return;
}