mirror of https://github.com/jetkvm/kvm.git
fix(WebRTC): improve error handling during peer connection creation and add connection error overlay
This commit is contained in:
parent
3b711db781
commit
12811b23ca
|
@ -153,6 +153,7 @@ export default function KvmIdRoute() {
|
||||||
// However, the onconnectionstatechange event doesn't fire when close() is called manually
|
// However, the onconnectionstatechange event doesn't fire when close() is called manually
|
||||||
// So we need to explicitly update our state to maintain consistency
|
// So we need to explicitly update our state to maintain consistency
|
||||||
// I don't know why this is happening, but this is the best way I can think of to handle it
|
// I don't know why this is happening, but this is the best way I can think of to handle it
|
||||||
|
// ALSO, this will render the connection error overlay linking to docs
|
||||||
setPeerConnectionState("closed");
|
setPeerConnectionState("closed");
|
||||||
},
|
},
|
||||||
[peerConnection, setPeerConnectionState],
|
[peerConnection, setPeerConnectionState],
|
||||||
|
@ -255,12 +256,19 @@ export default function KvmIdRoute() {
|
||||||
setStartedConnectingAt(new Date());
|
setStartedConnectingAt(new Date());
|
||||||
setConnectedAt(null);
|
setConnectedAt(null);
|
||||||
|
|
||||||
const pc = new RTCPeerConnection({
|
let pc: RTCPeerConnection;
|
||||||
// We only use STUN or TURN servers if we're in the cloud
|
try {
|
||||||
...(isInCloud && iceConfig?.iceServers
|
pc = new RTCPeerConnection({
|
||||||
? { iceServers: [iceConfig?.iceServers] }
|
// We only use STUN or TURN servers if we're in the cloud
|
||||||
: {}),
|
...(isInCloud && iceConfig?.iceServers
|
||||||
});
|
? { iceServers: [iceConfig?.iceServers] }
|
||||||
|
: {}),
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error creating peer connection: ${error}`);
|
||||||
|
closePeerConnection();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Set up event listeners and data channels
|
// Set up event listeners and data channels
|
||||||
pc.onconnectionstatechange = () => {
|
pc.onconnectionstatechange = () => {
|
||||||
|
@ -296,8 +304,10 @@ export default function KvmIdRoute() {
|
||||||
setPeerConnection(pc);
|
setPeerConnection(pc);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`Error creating offer: ${e}`);
|
console.error(`Error creating offer: ${e}`);
|
||||||
|
closePeerConnection();
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
|
closePeerConnection,
|
||||||
iceConfig?.iceServers,
|
iceConfig?.iceServers,
|
||||||
sdp,
|
sdp,
|
||||||
setDiskChannel,
|
setDiskChannel,
|
||||||
|
|
Loading…
Reference in New Issue