Update session to remove rogue socket connection

This commit is contained in:
Mitchell McCaffrey 2021-09-02 11:03:27 +10:00
parent 4a9229e229
commit 816320c1c2

View File

@ -35,7 +35,7 @@ class Session extends EventEmitter {
*
* @type {io.Socket}
*/
socket: Socket = io();
socket?: Socket;
/**
* A mapping of socket ids to session peers
@ -45,7 +45,7 @@ class Session extends EventEmitter {
peers: Record<string, SessionPeer>;
get id() {
return this.socket && this.socket.id;
return this.socket?.id || "";
}
_iceServers: RTCIceServer[] = [];
@ -191,7 +191,7 @@ class Session extends EventEmitter {
this._gameId = gameId;
this._password = password;
this.socket.emit(
this.socket?.emit(
"join_game",
gameId,
password,
@ -224,7 +224,7 @@ class Session extends EventEmitter {
};
const handleSignal = (signal: SignalData) => {
this.socket.emit("signal", JSON.stringify({ to: peer.id, signal }));
this.socket?.emit("signal", JSON.stringify({ to: peer.id, signal }));
};
const handleConnect = () => {
@ -373,7 +373,7 @@ class Session extends EventEmitter {
}
_handleForceUpdate() {
this.socket.disconnect();
this.socket?.disconnect();
this.emit("status", "needs_update");
}
}