/** * @licstart The following is the entire license notice for the * JavaScript code in this page. * * Copyright (C) 2015 Alicia ( https://ion.nu/ ) * * The JavaScript code in this page is free software: you can * redistribute it and/or modify it under the terms of the GNU * Affero General Public License (GNU AGPL) as published by the Free Software * Foundation, version 3 of the License. * The code is distributed WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU AGPL for more details. * * As additional permission under GNU AGPL version 3 section 7, you * may distribute non-source (e.g., minimized or compacted) forms of * that code without the copy of the GNU AGPL normally required by * section 4, provided you include this license notice and a URL * through which recipients can access the Corresponding Source. * * @licend The above is the entire license notice * for the JavaScript code in this page. */ var cams=new Array(); var mycam; var broadcasting=false; var broadcaststream; var mediarec; var usermediaerror; function broadcast() { if(!window.MediaRecorder) { // Check useragent and if it's chrome, suggest enabling "experimental web platform features", if it's not firefox, suggest trying that, if it is firefox, suggest upgrading if(navigator.userAgent.indexOf(' Chrome/')>-1) { chatnote("MediaRecorder API is not available in your browser, cannot broadcast. Enabling \"Experimental web platform features\" in chrome://flags might enable it."); }else if(navigator.userAgent.indexOf(' Firefox/')==-1) { chatnote("MediaRecorder API is not available in your browser, cannot broadcast. Firefox provides this API, as does Chrome if you enable \"Experimental web platform features\"."); }else{ chatnote("MediaRecorder API is not available in your browser, cannot broadcast"); } return; } if(!broadcasting) { // TODO: Try to constrain video to a low enough resolution for shit connections navigator.getUserMedia({video:true, audio:true}, broadcast_success, function(e){alert('getUserMedia failed (is your camera connected?)'); usermediaerror=e;}); }else{ broadcasting=false; clearInterval(mycam.interval); broadcaststream.stop(); document.getElementById('broadcastbutton').textContent='Broadcast'; document.getElementById('cams').removeChild(mycam.video); var index=cams.indexOf(mycam); if(index>-1){cams.splice(index,1);} mycam=undefined; // TODO: check that a video isn't playing if(cams.length==0){hidecams();} connection.send('mediastop'); } } function broadcast_success(stream) { broadcasting=1; document.getElementById('broadcastbutton').textContent='Stop broadcasting'; connection.send('mediastart'); broadcaststream=stream; showcams(); mycam=new Object(); mycam.video=document.createElement('video'); mycam.video.autoplay=true; mycam.video.mozSrcObject=stream; mycam.video.src=window.URL.createObjectURL(stream); mycam.video.style.height='100%'; mycam.video.muted=true; // Don't echo ourselves document.getElementById('cams').appendChild(mycam.video); cams.push(mycam); // Streaming to the server mediarec=new MediaRecorder(stream); mediarec.ondataavailable=function(data) { if(data.data.size==0){return;} // Don't send 0-byte data connection.send('media'); connection.send(data.data); }; mediarec.start(); mycam.interval=setInterval(function(){mediarec.requestData();}, 100); } function opencam(user) { var cam=new Object(); cam.user=user; cam.video=document.createElement('video'); cam.video.autoplay=true; cam.video.style.height='100%'; cam.video.poster='mic.png'; cam.sourcebuffer=false; if(!window.MediaSource) { chatnote('MediaSource missing, using httpcam fallback'); connection.send("httpcamkey:"+user.nickname); }else{ cam.mediasource=new MediaSource(); cam.mediasource.addEventListener('sourceopen', function() { if(!cam.sourcebuffer){cam.sourcebuffer=this.addSourceBuffer('video/webm');} }); cam.video.src=window.URL.createObjectURL(cam.mediasource); cam.filereader=new FileReader(); cam.filereader.onloadend=function(progress) { cam.sourcebuffer.appendBuffer(this.result); if(!cam.video.played.length) { cam.video.play(); } cam.video.currentTime+=3600; } connection.send('mediasubscribe:'+user.nickname); } cam.cambox=document.createElement('div'); cam.cambox.className='cambox'; var info=document.createElement('span'); info.textContent=user.nickname; info.oncontextmenu=function(e){usermenu(user, e.pageX, e.pageY);return false;}; cam.cambox.appendChild(cam.video); cam.cambox.appendChild(info); document.getElementById('cams').appendChild(cam.cambox); cams.push(cam); showcams(); } function handlecamdata(user, data) { var i=0; while(i