mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-17 05:02:06 +00:00
fix(music-together): fix reconnect logic
This commit is contained in:
@ -59,7 +59,17 @@ export class Connection {
|
|||||||
this._mode = 'host';
|
this._mode = 'host';
|
||||||
await this.registerConnection(conn);
|
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._mode = 'disconnected';
|
||||||
|
|
||||||
this.waitOpen.reject(err);
|
this.waitOpen.reject(err);
|
||||||
@ -123,17 +133,7 @@ export class Connection {
|
|||||||
/* privates */
|
/* privates */
|
||||||
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', async (err) => {
|
this.peer.once('error', (err) => {
|
||||||
if (err.type === PeerErrorType.Network) {
|
|
||||||
// retrying after 10 seconds
|
|
||||||
await delay(10000);
|
|
||||||
try {
|
|
||||||
this.peer.reconnect();
|
|
||||||
return;
|
|
||||||
} catch {
|
|
||||||
//ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this._mode = 'disconnected';
|
this._mode = 'disconnected';
|
||||||
|
|
||||||
reject(err);
|
reject(err);
|
||||||
|
|||||||
@ -550,7 +550,7 @@ export default createPlugin<
|
|||||||
},
|
},
|
||||||
|
|
||||||
onStop() {
|
onStop() {
|
||||||
this.connection?.disconnect();
|
if (this.connection?.mode !== 'disconnected') this.connection?.disconnect();
|
||||||
this.queue?.rollbackInjection();
|
this.queue?.rollbackInjection();
|
||||||
this.queue?.removeQueueOwner();
|
this.queue?.removeQueueOwner();
|
||||||
if (this.rollbackInjector) {
|
if (this.rollbackInjector) {
|
||||||
|
|||||||
Reference in New Issue
Block a user