Skip to content

Commit

Permalink
Update frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuNatsu committed Aug 25, 2023
1 parent aac3819 commit d8df47e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion frontend/utils/p2p_recv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function startRecvService(
let totSize: number = 0;
let tPerNum: number = 1;
let tNum: number = 0;
let retry: number = 0;

cbReady(socket, peerConn);

Expand Down Expand Up @@ -108,8 +109,17 @@ export function startRecvService(
socket.emit('candidate', peerId, ev.candidate);
}
});
peerConn.addEventListener('connectionstatechange', (): void => {
peerConn.addEventListener('connectionstatechange', async (): Promise<void> => {
if (peerConn.connectionState === 'failed') {
if (retry < 5) {
const offer: RTCSessionDescriptionInit = await peerConn.createOffer({
iceRestart: true
});
await peerConn.setLocalDescription(offer);
socket.emit('offer', peerId, offer);
retry++;
return;
}
cbError(RecvServiceError.WebRTCConnectFail);
socket.disconnect();
}
Expand Down

0 comments on commit d8df47e

Please sign in to comment.