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

@ -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;
}