mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-17 05:02:06 +00:00
fix(music-together): fix duplicate client issue
This commit is contained in:
@ -70,11 +70,12 @@ export class Connection {
|
|||||||
//ignored
|
//ignored
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._mode = 'disconnected';
|
|
||||||
|
|
||||||
this.waitOpen.reject(err);
|
this.waitOpen.reject(err);
|
||||||
this.connectionListeners.forEach((listener) => listener());
|
this.connectionListeners.forEach((listener) => listener());
|
||||||
console.error(err);
|
this.disconnect();
|
||||||
|
|
||||||
|
console.trace(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,6 +98,8 @@ export class Connection {
|
|||||||
|
|
||||||
this._mode = 'disconnected';
|
this._mode = 'disconnected';
|
||||||
this.connections = {};
|
this.connections = {};
|
||||||
|
this.connectionListeners = [];
|
||||||
|
this.peer.disconnect();
|
||||||
this.peer.destroy();
|
this.peer.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,10 +137,10 @@ export class Connection {
|
|||||||
private async registerConnection(conn: DataConnection) {
|
private async registerConnection(conn: DataConnection) {
|
||||||
return new Promise<DataConnection>((resolve, reject) => {
|
return new Promise<DataConnection>((resolve, reject) => {
|
||||||
this.peer.once('error', (err) => {
|
this.peer.once('error', (err) => {
|
||||||
this._mode = 'disconnected';
|
|
||||||
|
|
||||||
reject(err);
|
reject(err);
|
||||||
this.connectionListeners.forEach((listener) => listener());
|
this.connectionListeners.forEach((listener) => listener());
|
||||||
|
|
||||||
|
this.disconnect();
|
||||||
});
|
});
|
||||||
|
|
||||||
conn.on('open', () => {
|
conn.on('open', () => {
|
||||||
@ -167,7 +170,15 @@ export class Connection {
|
|||||||
if (err) reject(err);
|
if (err) reject(err);
|
||||||
|
|
||||||
delete this.connections[conn.connectionId];
|
delete this.connections[conn.connectionId];
|
||||||
|
|
||||||
this.connectionListeners.forEach((listener) => listener(conn));
|
this.connectionListeners.forEach((listener) => listener(conn));
|
||||||
|
this.connectionListeners = [];
|
||||||
|
|
||||||
|
if (conn.open) {
|
||||||
|
conn.close({
|
||||||
|
flush: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
conn.on('error', onClose);
|
conn.on('error', onClose);
|
||||||
conn.on('close', onClose);
|
conn.on('close', onClose);
|
||||||
|
|||||||
Reference in New Issue
Block a user