Anton Shestakov <engored@ya.ru>, Wed, 20 Nov 2013 19:41:52 +0900
Cosmetic changes in the template.
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'); audio: $('#audio').prop('checked'), video: $('#video').prop('checked') if (constraints.audio || constraints.video) { getUserMedia(constraints, connect, fail); function connect(stream) { pc = new RTCPeerConnection(null); $('#local').attachStream(stream); pc.onaddstream = function(event) { $('#remote').attachStream(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, ' ')); $('#status').addClass('error'); console.error.apply(console, arguments); jQuery.fn.attachStream = function(stream) { this.src = URL.createObjectURL(stream);