fixed party names only showing two members

This commit is contained in:
Mitchell McCaffrey 2020-04-06 00:20:17 +10:00
parent 99ed04b52a
commit af202fb19b
2 changed files with 6 additions and 6 deletions

View File

@ -80,7 +80,7 @@ function useSession(partyId, onPeerConnected, onPeerDisconnected, onPeerData) {
};
}, [peers, onPeerConnected, onPeerDisconnected, onPeerData]);
return { peers, id: socket.id };
return { peers, socket };
}
export default useSession;

View File

@ -14,7 +14,7 @@ import Map from "../components/Map";
function Game() {
const { id: gameId } = useParams();
const { peers, id } = useSession(
const { peers, socket } = useSession(
gameId,
handlePeerConnected,
handlePeerDisconnected,
@ -65,22 +65,22 @@ function Game() {
function handleNicknameChange(nickname) {
setNickname(nickname);
for (let peer of Object.values(peers)) {
const data = { [id]: nickname };
const data = { [socket.id]: nickname };
peer.send({ id: "nickname", data });
}
}
function handlePeerConnected({ id, peer, initiator }) {
function handlePeerConnected({ peer, initiator }) {
if (!initiator) {
if (mapSource) {
peer.send({ id: "map", data: mapDataRef.current });
}
peer.send({ id: "tokenEdit", data: mapTokens });
}
peer.send({ id: "nickname", data: { [id]: nickname } });
peer.send({ id: "nickname", data: { [socket.id]: nickname } });
}
function handlePeerData({ id, peer, data }) {
function handlePeerData({ data }) {
if (data.id === "map") {
const blob = new Blob([data.data.file]);
mapDataRef.current = { ...data.data, file: blob };