$ git clone https://ion.nu/git/webchat
commit b0fe287d0b9ac8467fd1dbe8c71b146f055c4c96
Author: Alicia <...>
Date: Sat Jan 9 01:52:14 2016 +0100
Tweaked cam code for compatibility with Chrome.
diff --git a/cams.js b/cams.js
index 94a46c9..1980068 100644
--- a/cams.js
+++ b/cams.js
@@ -49,7 +49,14 @@ function broadcast()
}else{
broadcasting=false;
clearInterval(mycam.interval);
- broadcaststream.stop();
+ var tracks=broadcaststream.getTracks();
+ var i=0;
+ while(i<tracks.length)
+ {
+ tracks[i].stop();
+ ++i;
+ }
+ mediarec.stop();
document.getElementById('broadcastbutton').textContent='Broadcast';
document.getElementById('cams').removeChild(mycam.video);
var index=cams.indexOf(mycam);
@@ -78,10 +85,12 @@ function broadcast_success(stream)
document.getElementById('cams').appendChild(mycam.video);
cams.push(mycam);
// Streaming to the server
- mediarec=new MediaRecorder(stream, {videoBitsPerSecond:32000});
+ var options=new Array();
+ options.videoBitsPerSecond=32000;
+ mediarec=new MediaRecorder(stream, options);
mediarec.ondataavailable=function(data)
{
- if(data.data.size==0){return;} // Don't send 0-byte data
+ if(!data.data || data.data.size==0){return;} // Don't send 0-byte data
connection.send('media');
connection.send(data.data);
};
@@ -91,6 +100,7 @@ function broadcast_success(stream)
}
function opencam(user)
{
+ closecam(user); // Only one cam per user
var cam=new Object();
cam.user=user;
cam.video=document.createElement('video');
@@ -99,10 +109,13 @@ function opencam(user)
cam.video.poster='mic.png';
cam.sourcebuffer=false;
user.cam=cam;
+/* MediaSource seems to have some issues on Chrome, but the httpcam fallback works fine, so default to that
if(!window.MediaSource)
{
chatnote('MediaSource missing, using httpcam fallback');
+*/
connection.send("httpcamkey:"+user.nickname);
+/*
}else{
cam.mediasource=new MediaSource();
cam.mediasource.addEventListener('sourceopen', function()
@@ -122,6 +135,7 @@ function opencam(user)
}
connection.send('mediasubscribe:'+user.nickname);
}
+*/
cam.cambox=document.createElement('div');
cam.cambox.className='cambox';
var info=document.createElement('span');