disconnect websocket and refresh page on disconnect

This commit is contained in:
Ian Ramzy 2020-04-02 10:20:31 -04:00
parent 510d11b457
commit 73edc600f2
3 changed files with 39 additions and 0 deletions

6
package-lock.json generated
View File

@ -819,6 +819,12 @@
"resolved": "https://registry.npmjs.org/pop-iterate/-/pop-iterate-1.0.1.tgz",
"integrity": "sha1-zqz9q0q/NT16DyqqLB/Hs/lBO6M="
},
"prettier": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.0.2.tgz",
"integrity": "sha512-5xJQIPT8BraI7ZnaDwSbu5zLrB6vvi8hVV58yHQ+QK64qrY40dULy0HSRlQ2/2IdzeBpjhDkqdcFBnFeDEMVdg==",
"dev": true
},
"proxy-addr": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz",

View File

@ -15,5 +15,8 @@
"heroku-ssl-redirect": "0.0.4",
"socket.io": "^2.2.0",
"twilio": "^3.34.0"
},
"devDependencies": {
"prettier": "2.0.2"
}
}

View File

@ -133,6 +133,36 @@ var VideoChat = {
VideoChat.socket.on("recieveCaptions", (captions) =>
recieveCaptions(captions)
);
VideoChat.peerConnection.onconnectionstatechange = function (event) {
switch (VideoChat.peerConnection.connectionState) {
case "connected":
logIt("connected");
// alert("connected");
function onConnect() {
VideoChat.socket.disconnect();
// VideoChat.peerConnection = null;
}
setTimeout(onConnect, 100);
break;
case "disconnected":
case "failed":
logIt("failed/disconnected");
logIt(VideoChat);
// VideoChat.socket = io();
// VideoChat.socket.on("candidate", VideoChat.onCandidate);
// VideoChat.socket.on("answer", VideoChat.onAnswer);
location.reload();
// startUp();
// alert("failed/disconnected");
break;
case "closed":
logIt("closed");
// alert("closed");
break;
}
};
callback();
};