diff --git a/src/network/Session.ts b/src/network/Session.ts index b046c51..daac356 100644 --- a/src/network/Session.ts +++ b/src/network/Session.ts @@ -33,7 +33,10 @@ class Session extends EventEmitter { /** * The socket io connection */ - socket?: Socket; + socket = io(process.env.REACT_APP_BROKER_URL!, { + withCredentials: true, + parser: msgParser, + }); /** * A mapping of socket ids to session peers @@ -43,7 +46,7 @@ class Session extends EventEmitter { peers: Record; get id() { - return this.socket?.id || ""; + return this.socket.id; } _iceServers: RTCIceServer[] = []; @@ -181,7 +184,7 @@ class Session extends EventEmitter { this._gameId = gameId; this._password = password; - this.socket?.emit( + this.socket.emit( "join_game", gameId, password, @@ -214,7 +217,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 = () => { @@ -363,7 +366,7 @@ class Session extends EventEmitter { } _handleForceUpdate() { - this.socket?.disconnect(); + this.socket.disconnect(); this.emit("status", "needs_update"); } }