mirror of
https://github.com/ianramzy/decentralized-video-chat.git
synced 2025-02-23 00:15:04 +08:00
added graceful disconnect handling
This commit is contained in:
parent
804ace168f
commit
ff1c6fdec3
@ -199,7 +199,16 @@ var VideoChat = {
|
|||||||
// VideoChat.socket.off("offer");
|
// VideoChat.socket.off("offer");
|
||||||
break;
|
break;
|
||||||
case "disconnected":
|
case "disconnected":
|
||||||
logIt("disconnected");
|
logIt("disconnected - UUID " + uuid);
|
||||||
|
VideoChat.remoteVideoWrapper.removeChild(document.querySelectorAll(`[uuid="${uuid}"]`)[0]);
|
||||||
|
VideoChat.connected.delete(uuid);
|
||||||
|
VideoChat.peerConnections.delete(uuid);
|
||||||
|
dataChannel.delete(uuid);
|
||||||
|
|
||||||
|
if (VideoChat.peerConnections.size === 0) {
|
||||||
|
displayWaitingCaption();
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "failed":
|
case "failed":
|
||||||
logIt("failed");
|
logIt("failed");
|
||||||
// VideoChat.socket.connect
|
// VideoChat.socket.connect
|
||||||
@ -332,6 +341,7 @@ var VideoChat = {
|
|||||||
node.setAttribute("autoplay", "");
|
node.setAttribute("autoplay", "");
|
||||||
node.setAttribute("playsinline", "");
|
node.setAttribute("playsinline", "");
|
||||||
node.setAttribute("id", "remote-video");
|
node.setAttribute("id", "remote-video");
|
||||||
|
node.setAttribute("uuid", uuid);
|
||||||
VideoChat.remoteVideoWrapper.appendChild(node);
|
VideoChat.remoteVideoWrapper.appendChild(node);
|
||||||
// Update remote video source
|
// Update remote video source
|
||||||
VideoChat.remoteVideoWrapper.lastChild.srcObject = event.stream;
|
VideoChat.remoteVideoWrapper.lastChild.srcObject = event.stream;
|
||||||
@ -900,7 +910,15 @@ function togglePictureInPicture() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Picture in picture
|
|
||||||
|
// Helper function for displaying waiting caption
|
||||||
|
function displayWaitingCaption() {
|
||||||
|
// Set caption text on start
|
||||||
|
captionText.text("Waiting for other user to join...").fadeIn();
|
||||||
|
|
||||||
|
// Reposition captions on start
|
||||||
|
rePositionCaptions();
|
||||||
|
}
|
||||||
|
|
||||||
function startUp() {
|
function startUp() {
|
||||||
// Try and detect in-app browsers and redirect
|
// Try and detect in-app browsers and redirect
|
||||||
@ -994,11 +1012,7 @@ function startUp() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set caption text on start
|
displayWaitingCaption();
|
||||||
captionText.text("Waiting for other user to join...").fadeIn();
|
|
||||||
|
|
||||||
// Reposition captions on start
|
|
||||||
rePositionCaptions();
|
|
||||||
|
|
||||||
// On change media devices refresh page and switch to system default
|
// On change media devices refresh page and switch to system default
|
||||||
navigator.mediaDevices.ondevicechange = () => window.location.reload();
|
navigator.mediaDevices.ondevicechange = () => window.location.reload();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user