Anton Shestakov <engored@ya.ru>, Mon, 11 Mar 2013 23:44:44 +0900
User can choose to use audio/video or both. Also visually mark pressed button.
static/js/main.js
Permissions: -rw-r--r--
var ws = new WebSocket('ws://' + location.host + '/ws'); document.getElementById('btn-call').className += ' btn-active'; document.getElementById('btn-receive').className += ' btn-active'; function init(initiator) { audio: document.getElementById('audio').checked, video: document.getElementById('video').checked getUserMedia(constraints, function(stream) { pc = new RTCPeerConnection(null); attachMediaStream(document.getElementById('local'), stream); pc.onaddstream = function(event) { attachMediaStream(document.getElementById('remote'), 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)); console.log('creating offer'); pc.createOffer(function(offer) { console.log('created offer'); pc.setLocalDescription(offer, function() { console.log('setLocalDescription done, sending to remote'); ws.send(JSON.stringify(offer)); function receiveOffer(offer) { console.log('received offer'); pc.setRemoteDescription(new RTCSessionDescription(offer), function() { console.log('creating answer'); pc.createAnswer(function(answer) { console.log('created answer'); pc.setLocalDescription(answer, function() { console.log('setLocalDescription done, sending to remote'); ws.send(JSON.stringify(answer)); function receiveAnswer(answer) { console.log('received answer'); pc.setRemoteDescription(new RTCSessionDescription(answer));