From 5158b9cd0420de8dc52f5cb20756c97936990573 Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Sun, 11 May 2025 23:19:16 +0900 Subject: [PATCH] fix(music-together): fix duplicate client issue --- src/plugins/music-together/connection.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/plugins/music-together/connection.ts b/src/plugins/music-together/connection.ts index d1246018..d634ab66 100644 --- a/src/plugins/music-together/connection.ts +++ b/src/plugins/music-together/connection.ts @@ -70,11 +70,12 @@ export class Connection { //ignored } } - this._mode = 'disconnected'; this.waitOpen.reject(err); this.connectionListeners.forEach((listener) => listener()); - console.error(err); + this.disconnect(); + + console.trace(err); }); } @@ -97,6 +98,8 @@ export class Connection { this._mode = 'disconnected'; this.connections = {}; + this.connectionListeners = []; + this.peer.disconnect(); this.peer.destroy(); } @@ -134,10 +137,10 @@ export class Connection { private async registerConnection(conn: DataConnection) { return new Promise((resolve, reject) => { this.peer.once('error', (err) => { - this._mode = 'disconnected'; - reject(err); this.connectionListeners.forEach((listener) => listener()); + + this.disconnect(); }); conn.on('open', () => { @@ -167,7 +170,15 @@ export class Connection { if (err) reject(err); delete this.connections[conn.connectionId]; + this.connectionListeners.forEach((listener) => listener(conn)); + this.connectionListeners = []; + + if (conn.open) { + conn.close({ + flush: true, + }); + } }; conn.on('error', onClose); conn.on('close', onClose);