Remove optionality from session socket

This reverts commit 99a27365ae.
This commit is contained in:
Mitchell McCaffrey 2021-10-21 13:37:46 +11:00
parent c6597dda31
commit 863f20be95

View File

@ -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<string, SessionPeer>;
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");
}
}