Anton Shestakov <engored@ya.ru>, Sat, 09 Mar 2013 13:51:40 +0900
Sort of works.
This is as fragile as it sounds actually, because it works only in perfect cases. Ice candidates from Chrome produce errors in Firefox; also Firefox cannot create answer to Chrome's offer; sound is missing in Firefox(?).
static/js/main.js
Permissions: -rw-r--r--
var ws = new WebSocket('ws://' + location.host + '/ws'); init({audio: true, video: true}, true); init({audio: true, video: true}, false); function init(constraints, initiator) { 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));