From 816320c1c2cba7d19fa9bada121b28865cc1ab98 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Thu, 2 Sep 2021 11:03:27 +1000 Subject: [PATCH] Update session to remove rogue socket connection --- src/network/Session.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/network/Session.ts b/src/network/Session.ts index de04cc1..a85b8ad 100644 --- a/src/network/Session.ts +++ b/src/network/Session.ts @@ -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; 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"); } }