From 00041fd146fae094347cfb43a30b58660a5fc669 Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Sun, 27 Apr 2025 06:04:52 +0900 Subject: [PATCH] fix(music-together): fix reconnect logic --- src/plugins/music-together/connection.ts | 24 ++++++++++++------------ src/plugins/music-together/index.ts | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/plugins/music-together/connection.ts b/src/plugins/music-together/connection.ts index 5d211fe5..d1246018 100644 --- a/src/plugins/music-together/connection.ts +++ b/src/plugins/music-together/connection.ts @@ -59,7 +59,17 @@ export class Connection { this._mode = 'host'; await this.registerConnection(conn); }); - this.peer.on('error', (err) => { + 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._mode = 'disconnected'; this.waitOpen.reject(err); @@ -123,17 +133,7 @@ export class Connection { /* privates */ private async registerConnection(conn: DataConnection) { return new Promise((resolve, reject) => { - this.peer.once('error', async (err) => { - if (err.type === PeerErrorType.Network) { - // retrying after 10 seconds - await delay(10000); - try { - this.peer.reconnect(); - return; - } catch { - //ignored - } - } + this.peer.once('error', (err) => { this._mode = 'disconnected'; reject(err); diff --git a/src/plugins/music-together/index.ts b/src/plugins/music-together/index.ts index ae3757ab..dca3ed71 100644 --- a/src/plugins/music-together/index.ts +++ b/src/plugins/music-together/index.ts @@ -550,7 +550,7 @@ export default createPlugin< }, onStop() { - this.connection?.disconnect(); + if (this.connection?.mode !== 'disconnected') this.connection?.disconnect(); this.queue?.rollbackInjection(); this.queue?.removeQueueOwner(); if (this.rollbackInjector) {