video call with imperfect reconnect, persistent id, possibly many clients

This commit is contained in:
bel
2020-05-07 19:39:27 -06:00
parent 9ffd54d4bf
commit fa959a2570
7 changed files with 105 additions and 65 deletions

View File

@@ -5,9 +5,12 @@
<script src="webrtc.js"></script>
<style>
video {
max-width: 100%;
min-width: 100%;
width: 100%;
width: 100%;
max-width: 400px;
min-width: 400px;
border: 1px solid black;
display: inline-block;
}
</style>
</head>

View File

@@ -12,13 +12,40 @@ var peerConnectionConfig = {
]
};
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function setCookie(cname, cvalue) {
var d = new Date();
d.setTime(d.getTime() + (1*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function pageReady() {
uuid = createUUID();
uuid = getCookie("uuid");
if (!uuid) {
uuid = createUUID();
setCookie("uuid", uuid);
}
localVideo = document.getElementById('localVideo');
remoteVideo = document.getElementById('remoteVideo');
serverConnection = new WebSocket('wss://' + window.location.hostname + '/abc');
serverConnection = new WebSocket('wss://' + window.location.hostname + '/abc?uuid=' + uuid);
serverConnection.onmessage = gotMessageFromServer;
var constraints = {