Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 0 additions & 9 deletions pnpm-lock.yaml

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

32 changes: 13 additions & 19 deletions src/plugins/music-together/connection.ts
Original file line number Diff line number Diff line change
@@ -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 };
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(),
),
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/music-together/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down Expand Up @@ -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': {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/music-together/queue/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export class Queue {
this.ignoreFlag = true;
this.broadcast({
type: 'CLEAR_QUEUE',
payload: {},
payload: null,
});
return;
}
Expand Down