Anton Shestakov <engored@ya.ru>, Tue, 12 Mar 2013 02:23:34 +0900
Status bar. Also could not resist dragging jQuery in.
static/js/main.js
Permissions: -rw-r--r--
var ws = new WebSocket('ws://' + location.host + '/ws'); $('#btn-call').addClass('btn-active'); $('#btn-receive').addClass('btn-active'); function init(initiator) { audio: $('#audio').prop('checked'), video: $('#video').prop('checked') getUserMedia(constraints, function(stream) { pc = new RTCPeerConnection(null); $('#local').prop('src', URL.createObjectURL(stream)); pc.onaddstream = function(event) { $('#remote').prop('src', URL.createObjectURL(event.stream)); pc.onicecandidate = function(event) { ws.send(JSON.stringify(event.candidate)); ws.onmessage = function (event) { var signal = JSON.parse(event.data); } else if (signal.candidate) { pc.addIceCandidate(new RTCIceCandidate(signal)); log('waiting for offer...'); log('creating offer...'); pc.createOffer(function(offer) { pc.setLocalDescription(offer, function() { log('sending to remote...'); ws.send(JSON.stringify(offer)); function receiveOffer(offer) { log('received offer...'); pc.setRemoteDescription(new RTCSessionDescription(offer), function() { log('creating answer...'); pc.createAnswer(function(answer) { log('created answer...'); pc.setLocalDescription(answer, function() { ws.send(JSON.stringify(answer)); function receiveAnswer(answer) { pc.setRemoteDescription(new RTCSessionDescription(answer)); $('#status').text(Array.prototype.join.call(arguments, ' ')); console.log.apply(console, arguments); function logStreaming(streaming) { $('#streaming').text(streaming ? '[streaming]' : '[..]'); $('#status').text(Array.prototype.join.call(arguments, ' ')); console.error.apply(console, arguments);