Fix bug with player joining

This commit is contained in:
Mitchell McCaffrey 2021-02-20 18:10:00 +11:00
parent 064ccbf65f
commit b372e4504d

View File

@ -74,12 +74,18 @@ export function PlayerProvider({ session, children }) {
setPlayerState({ ...playerState, sessionId: session.id });
}
session.on("connected", handleSocketConnect);
function handleSocketStatus(status) {
if (status === "joined") {
setPlayerState({ ...playerState, sessionId: session.id });
}
}
session.on("status", handleSocketStatus);
session.socket?.on("connect", handleSocketConnect);
session.socket?.on("reconnect", handleSocketConnect);
return () => {
session.off("connected", handleSocketConnect);
session.off("status", handleSocketStatus);
session.socket?.off("connect", handleSocketConnect);
session.socket?.off("reconnect", handleSocketConnect);
};