Added error handling for peer errors when socket is fine
This commit is contained in:
+12
-9
@@ -46,16 +46,19 @@ class Peer extends SimplePeer {
|
||||
}
|
||||
|
||||
send(data) {
|
||||
const packedData = encode(data);
|
||||
|
||||
if (packedData.byteLength > MAX_BUFFER_SIZE) {
|
||||
const chunks = this.chunk(packedData);
|
||||
for (let chunk of chunks) {
|
||||
super.send(encode(chunk));
|
||||
try {
|
||||
const packedData = encode(data);
|
||||
if (packedData.byteLength > MAX_BUFFER_SIZE) {
|
||||
const chunks = this.chunk(packedData);
|
||||
for (let chunk of chunks) {
|
||||
super.send(encode(chunk));
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
super.send(packedData);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
super.send(packedData);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-11
@@ -143,16 +143,19 @@ function useSession(
|
||||
// Setup event listeners for the socket
|
||||
useEffect(() => {
|
||||
function addPeer(id, initiator, sync) {
|
||||
const connection = new Peer({
|
||||
initiator,
|
||||
trickle: true,
|
||||
config: { iceServers },
|
||||
});
|
||||
|
||||
setPeers((prevPeers) => ({
|
||||
...prevPeers,
|
||||
[id]: { id, connection, initiator, sync },
|
||||
}));
|
||||
try {
|
||||
const connection = new Peer({
|
||||
initiator,
|
||||
trickle: true,
|
||||
config: { iceServers },
|
||||
});
|
||||
setPeers((prevPeers) => ({
|
||||
...prevPeers,
|
||||
[id]: { id, connection, initiator, sync },
|
||||
}));
|
||||
} catch (error) {
|
||||
onPeerError && onPeerError({ error });
|
||||
}
|
||||
}
|
||||
|
||||
function handlePartyMemberJoined(id) {
|
||||
@@ -214,7 +217,7 @@ function useSession(
|
||||
socket.off("signal", handleSignal);
|
||||
socket.off("auth error", handleAuthError);
|
||||
};
|
||||
}, [peers, setAuthenticationStatus, iceServers, joinParty]);
|
||||
}, [peers, setAuthenticationStatus, iceServers, joinParty, onPeerError]);
|
||||
|
||||
return { peers, socket, connected };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user