mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 18:41:47 +00:00
fix(music-together): Removing a connection on error
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import { DataConnection, Peer, PeerErrorType } from 'peerjs';
|
import { DataConnection, Peer, PeerError, PeerErrorType } from 'peerjs';
|
||||||
import delay from 'delay';
|
import delay from 'delay';
|
||||||
|
|
||||||
import type { Permission, Profile, VideoData } from './types';
|
import type { Permission, Profile, VideoData } from './types';
|
||||||
@ -89,8 +89,11 @@ export class Connection {
|
|||||||
listener({ type: 'CONNECTION_CLOSED', payload: null }, null);
|
listener({ type: 'CONNECTION_CLOSED', payload: null }, null);
|
||||||
}
|
}
|
||||||
this.listeners = [];
|
this.listeners = [];
|
||||||
|
|
||||||
|
this.connectionListeners.forEach((listener) => listener());
|
||||||
this.connectionListeners = [];
|
this.connectionListeners = [];
|
||||||
this.connections = {};
|
this.connections = {};
|
||||||
|
|
||||||
this.peer.disconnect();
|
this.peer.disconnect();
|
||||||
this.peer.destroy();
|
this.peer.destroy();
|
||||||
});
|
});
|
||||||
@ -207,18 +210,26 @@ export class Connection {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const onClose = (err?: Error) => {
|
const onClose = (
|
||||||
if (err) reject(err);
|
err?: PeerError<
|
||||||
|
| 'not-open-yet'
|
||||||
delete this.connections[conn.connectionId];
|
| 'message-too-big'
|
||||||
|
| 'negotiation-failed'
|
||||||
this.connectionListeners.forEach((listener) => listener(conn));
|
| 'connection-closed'
|
||||||
|
>,
|
||||||
|
) => {
|
||||||
if (conn.open) {
|
if (conn.open) {
|
||||||
conn.close({
|
conn.close({
|
||||||
flush: true,
|
flush: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete this.connections[conn.connectionId];
|
||||||
|
this.connectionListeners.forEach((listener) => listener(conn));
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
conn.on('error', onClose);
|
conn.on('error', onClose);
|
||||||
conn.on('close', onClose);
|
conn.on('close', onClose);
|
||||||
|
|||||||
Reference in New Issue
Block a user