--- a/static/js/main.js Tue Mar 12 02:23:34 2013 +0900
+++ b/static/js/main.js Tue Mar 12 13:56:00 2013 +0900
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);
+ if (constraints.audio || constraints.video) {
+ getUserMedia(constraints, connect, fail);
+function connect(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));
+ $('#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);
- ws.onmessage = function (event) {
- var signal = JSON.parse(event.data);
- } else if (signal.candidate) {
- pc.addIceCandidate(new RTCIceCandidate(signal));
- log('waiting for offer...');
+ } else if (signal.candidate) {
+ pc.addIceCandidate(new RTCIceCandidate(signal));
+ log('waiting for offer...');
$('#status').text(Array.prototype.join.call(arguments, ' '));
console.error.apply(console, arguments);
+jQuery.fn.attachStream = function(stream) {
+ this.src = URL.createObjectURL(stream);