From 239f033e9357e05838dad4283e2324bba4f95519 Mon Sep 17 00:00:00 2001 From: Ben Brittain Date: Fri, 10 Aug 2012 16:17:58 +0000 Subject: [PATCH 01/36] update for 0.0.1 release --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9692824..6564439 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ #webrtc.io-demo ============== -webrtc.io modified to supply the client files - You can have a look at the demo on http://multiwebrtc.nodejitsu.com ##Instructions on how to setup the demo: @@ -31,11 +29,11 @@ node server.js In a version of Chrome that have webRTC support. -go to [localhost:8000/#1](http://localhost:8000/#1) +go to [localhost:8000](http://localhost:8000) click allow to see your camera -go to [localhost:8000/#1](http://localhost:8000/#1) +go to [localhost:8000](http://localhost:8000) click allow to see your camera and the connection will be made between your to open windows. From 31e6a74c6a68a9e5fcf803e6b642af4a98f26080 Mon Sep 17 00:00:00 2001 From: Ben Brittain Date: Fri, 10 Aug 2012 16:30:57 +0000 Subject: [PATCH 02/36] update for 0.0.1 release --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6564439..39e6c4f 100644 --- a/README.md +++ b/README.md @@ -38,9 +38,9 @@ go to [localhost:8000](http://localhost:8000) click allow to see your camera and the connection will be made between your to open windows. -##For instructions on how to start with webRTC.io +##For instructions on how to start developing with webRTC.io -go to [https://github.com/cavedweller/webRTC.io](https://github.com/cavedweller/webRTC.io) and read the instructions. +go to [https://github.com/webRTC/webRTC.io](https://github.com/webRTC/webRTC.io) and read the instructions. Developed by: [@dennismatensson](https://github.com/dennismartensson) From c1e2d60d2af6189a14292dee02c37c3988c231fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20M=C3=A5rtensson?= Date: Fri, 10 Aug 2012 17:57:03 -0400 Subject: [PATCH 03/36] removed nodejitsu thinks --- example/index.html | 3 - example/server.js | 3 - example/webrtc.io.js | 298 ++++++++++++++++++++++++++++++++++++++++++- package.json | 2 +- 4 files changed, 298 insertions(+), 8 deletions(-) mode change 120000 => 100644 example/webrtc.io.js diff --git a/example/index.html b/example/index.html index e5ed441..a1b3963 100644 --- a/example/index.html +++ b/example/index.html @@ -165,9 +165,6 @@ var room = window.location.hash.slice(1); - //When connectiong to nodejitsu - //rtc.connect("http://multiwebrtc.nodejitsu.com/", room); - //When using localhost rtc.connect("ws://localhost:8001/", room); diff --git a/example/server.js b/example/server.js index 3bbdc02..0309404 100644 --- a/example/server.js +++ b/example/server.js @@ -1,9 +1,6 @@ var app = require('express').createServer(); var webRTC = require('webrtc.io').listen(8001); -//When connectiong to nodejitsu -//app.listen(80); -//When using localhost app.listen(8000); app.get('/', function(req, res) { diff --git a/example/webrtc.io.js b/example/webrtc.io.js deleted file mode 120000 index 5b50d99..0000000 --- a/example/webrtc.io.js +++ /dev/null @@ -1 +0,0 @@ -../node_modules/webrtc.io/node_modules/webrtc.io-client/lib/webrtc.io.js \ No newline at end of file diff --git a/example/webrtc.io.js b/example/webrtc.io.js new file mode 100644 index 0000000..f751a77 --- /dev/null +++ b/example/webrtc.io.js @@ -0,0 +1,297 @@ +//CLIENT + + // Fallbacks for vendor-specific variables until the spec is finalized. +var PeerConnection = window.PeerConnection || window.webkitPeerConnection00; +var URL = window.URL || window.webkitURL || window.msURL || window.oURL; +var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; + +(function() { + + var rtc; + if ('undefined' === typeof module) { + rtc = this.rtc = {}; + } else { + rtc = module.exports = {}; + } + + + // Holds a connection to the server. + rtc._socket = null; + + // Holds callbacks for certain events. + rtc._events = {}; + + rtc.on = function(eventName, callback) { + rtc._events[eventName] = rtc._events[eventName] || []; + rtc._events[eventName].push(callback); + }; + + rtc.fire = function(eventName, _) { + var events = rtc._events[eventName]; + var args = Array.prototype.slice.call(arguments, 1); + + if (!events) { + return; + } + + for (var i = 0, len = events.length; i < len; i++) { + events[i].apply(null, args); + } + }; + + // Holds the STUN server to use for PeerConnections. + rtc.SERVER = "STUN stun.l.google.com:19302"; + + // Referenc e to the lone PeerConnection instance. + rtc.peerConnections = {}; + + // Array of known peer socket ids + rtc.connections = []; + // Stream-related variables. + rtc.streams = []; + rtc.numStreams = 0; + rtc.initializedStreams = 0; + + /** + * Connects to the websocket server. + */ + rtc.connect = function(server, room) { + room = room || ""; // by default, join a room called the blank string + rtc._socket = new WebSocket(server); + + rtc._socket.onopen = function() { + + rtc._socket.send(JSON.stringify({ + "eventName": "join_room", + "room": room + }), function(error){ + if(error){console.log(error);} + }); + + rtc._socket.onmessage = function(data) { + var json = JSON.parse(data.data); + rtc.fire(json.eventName, json); + }; + + rtc._socket.onerror = function(err) { + console.log('onerror'); + console.log(err); + }; + + rtc._socket.onclose = function(data) { + rtc.fire('disconnect stream', rtc._socket.id); + delete rtc.peerConnections[rtc._socket.id]; + }; + + rtc.on('get_peers', function(data) { + rtc.connections = data.connections; + // fire connections event and pass peers + rtc.fire('connections', rtc.connections); + }); + + rtc.on('receive_ice_candidate', function(data) { + var candidate = new IceCandidate(data.label, data.candidate); + rtc.peerConnections[data.socketId].processIceMessage(candidate); + + rtc.fire('receive ice candidate', candidate); + }); + + rtc.on('new_peer_connected', function(data) { + rtc.connections.push(data.socketId); + + var pc = rtc.createPeerConnection(data.socketId); + for (var i = 0; i < rtc.streams.length; i++) { + var stream = rtc.streams[i]; + pc.addStream(stream); + } + }); + + rtc.on('remove_peer_connected', function(data) { + rtc.fire('disconnect stream', data.socketId); + delete rtc.peerConnections[data.socketId]; + }); + + rtc.on('receive_offer', function(data) { + rtc.receiveOffer(data.socketId, data.sdp); + rtc.fire('receive offer', data); + }); + + rtc.on('receive_answer', function(data) { + rtc.receiveAnswer(data.socketId, data.sdp); + rtc.fire('receive answer', data); + }); + + rtc.fire('connect'); + }; + }; + + + rtc.sendOffers = function() { + for (var i = 0, len = rtc.connections.length; i < len; i++) { + var socketId = rtc.connections[i]; + rtc.sendOffer(socketId); + } + } + + rtc.onClose = function(data) { + rtc.on('close_stream', function() { + rtc.fire('close_stream', data); + }); + } + + rtc.createPeerConnections = function() { + for (var i = 0; i < rtc.connections.length; i++) { + rtc.createPeerConnection(rtc.connections[i]); + } + }; + + rtc.createPeerConnection = function(id) { + console.log('createPeerConnection'); + var pc = rtc.peerConnections[id] = new PeerConnection(rtc.SERVER, function(candidate, moreToFollow) { + if (candidate) { + rtc._socket.send(JSON.stringify({ + "eventName": "send_ice_candidate", + "label": candidate.label, + "candidate": candidate.toSdp(), + "socketId": id + }), function(error){ + if(error){console.log(error);} + }); + } + rtc.fire('ice candidate', candidate, moreToFollow); + }); + + pc.onopen = function() { + // TODO: Finalize this API + rtc.fire('peer connection opened'); + }; + + pc.onaddstream = function(event) { + // TODO: Finalize this API + rtc.fire('add remote stream', event.stream, id); + }; + return pc; + }; + + rtc.sendOffer = function(socketId) { + var pc = rtc.peerConnections[socketId]; + // TODO: Abstract away video: true, audio: true for offers + var offer = pc.createOffer({ + video: true, + audio: true + }); + pc.setLocalDescription(pc.SDP_OFFER, offer); + rtc._socket.send(JSON.stringify({ + "eventName": "send_offer", + "socketId": socketId, + "sdp": offer.toSdp() + }), function(error){ + if(error){console.log(error);} + }); + pc.startIce(); + }; + + + rtc.receiveOffer = function(socketId, sdp) { + var pc = rtc.peerConnections[socketId]; + pc.setRemoteDescription(pc.SDP_OFFER, new SessionDescription(sdp)); + rtc.sendAnswer(socketId); + }; + + + rtc.sendAnswer = function(socketId) { + var pc = rtc.peerConnections[socketId]; + var offer = pc.remoteDescription; + // TODO: Abstract away video: true, audio: true for answers + var answer = pc.createAnswer(offer.toSdp(), { + video: true, + audio: true + }); + pc.setLocalDescription(pc.SDP_ANSWER, answer); + rtc._socket.send(JSON.stringify({ + "eventName": "send_answer", + "socketId": socketId, + "sdp": answer.toSdp() + }), function(error){ + if(error){console.log(error);} + }); + pc.startIce(); + }; + + + rtc.receiveAnswer = function(socketId, sdp) { + var pc = rtc.peerConnections[socketId]; + pc.setRemoteDescription(pc.SDP_ANSWER, new SessionDescription(sdp)); + }; + + + rtc.createStream = function(opt, onSuccess, onFail) { + var options; + onSuccess = onSuccess || + function() {}; + onFail = onFail || + function() {}; + + if(opt.audio && opt.video){ + options = { + video: true, + audio: true + }; + }else if(opt.video){ + options = { + video: true, + audio: false + }; + }else if(opt.audio){ + options = { + video: false, + audio: true + }; + }else { + options = { + video: false, + audio: false + }; + } + + if (getUserMedia) { + rtc.numStreams++; + getUserMedia.call(navigator, options, function(stream) { + + rtc.streams.push(stream); + rtc.initializedStreams++; + onSuccess(stream); + if (rtc.initializedStreams === rtc.numStreams) { + rtc.fire('ready'); + } + }, function() { + alert("Could not connect stream."); + onFail(); + }); + } else { + alert('webRTC is not yet supported in this browser.'); + } + } + + + rtc.addStreams = function() { + for (var i = 0; i < rtc.streams.length; i++) { + var stream = rtc.streams[i]; + for (var connection in rtc.peerConnections) { + rtc.peerConnections[connection].addStream(stream); + } + } + }; + + + rtc.attachStream = function(stream, domId) { + document.getElementById(domId).src = URL.createObjectURL(stream); + }; + + rtc.on('ready', function() { + rtc.createPeerConnections(); + rtc.addStreams(); + rtc.sendOffers(); + }); + +}).call(this); \ No newline at end of file diff --git a/package.json b/package.json index 1144e6b..2d5d321 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "MultiWebRTC", "description": "Example of multi user webrtc", - "version": "0.0.1-31", + "version": "0.0.1-43", "engines": { "node": ">= 0.6.0" }, From effe58348b0ce40c19f17e111b27ecfbeb6c9913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20M=C3=A5rtensson?= Date: Sat, 11 Aug 2012 12:46:58 -0400 Subject: [PATCH 04/36] fix websocket problems with lisen to server --- example/index.html | 2 +- example/server.js | 5 +++-- package.json | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/example/index.html b/example/index.html index a1b3963..9d184de 100644 --- a/example/index.html +++ b/example/index.html @@ -166,7 +166,7 @@ var room = window.location.hash.slice(1); //When using localhost - rtc.connect("ws://localhost:8001/", room); + rtc.connect("ws://localhost:8000/", room); rtc.on('add remote stream', function(stream, socketId) { console.log("ADDING REMOTE STREAM..."); diff --git a/example/server.js b/example/server.js index 0309404..b5d8775 100644 --- a/example/server.js +++ b/example/server.js @@ -1,7 +1,8 @@ var app = require('express').createServer(); -var webRTC = require('webrtc.io').listen(8001); - app.listen(8000); +var webRTC = require('webrtc.io').listen(app); + + app.get('/', function(req, res) { res.sendfile(__dirname + '/index.html'); diff --git a/package.json b/package.json index 2d5d321..c478bb1 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "MultiWebRTC", "description": "Example of multi user webrtc", - "version": "0.0.1-43", + "version": "0.0.1-47", "engines": { "node": ">= 0.6.0" }, "dependencies": { - "webrtc.io": "latest", + "webrtc.io": "0.0.0", "express": "2.5.1", "ws": "latest" }, From a404d7a6c09da7a10787ba1a8bf31fc9085c0069 Mon Sep 17 00:00:00 2001 From: Ben Brittain Date: Sat, 11 Aug 2012 15:50:44 +0000 Subject: [PATCH 05/36] bump version num and clean up NPM --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index c478bb1..253c39a 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "MultiWebRTC", "description": "Example of multi user webrtc", - "version": "0.0.1-47", + "version": "0.0.2-1", "engines": { "node": ">= 0.6.0" }, "dependencies": { - "webrtc.io": "0.0.0", + "webrtc.io": "latest", "express": "2.5.1", "ws": "latest" }, @@ -29,4 +29,4 @@ "email": "david.a.peter@gmail.com" } ] -} \ No newline at end of file +} From 04fd8124438cd6f3a421f224cb5db4f39a359345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20M=C3=A5rtensson?= Date: Sat, 11 Aug 2012 17:19:40 -0400 Subject: [PATCH 06/36] chance of api fic --- example/index.html | 2 + example/server.js | 8 +- example/webrtc.io.js | 298 +------------------------------------------ 3 files changed, 8 insertions(+), 300 deletions(-) mode change 100644 => 120000 example/webrtc.io.js diff --git a/example/index.html b/example/index.html index 9d184de..59c46cf 100644 --- a/example/index.html +++ b/example/index.html @@ -131,9 +131,11 @@ if (key === 13) { rtc._socket.send(JSON.stringify({ "eventName": "chat_msg", + "data": { "messages": input.value, "room": room, "color": color + } }), function(error) { if (error) { console.log(error); diff --git a/example/server.js b/example/server.js index b5d8775..f0f0c17 100644 --- a/example/server.js +++ b/example/server.js @@ -36,13 +36,15 @@ webRTC.rtc.on('chat_msg', function(data, socket) { var socketId = roomList[i]; if (socketId !== socket.id) { - var soc = webRTC.rtc.getSocket(data.room, socketId); + var soc = webRTC.rtc.getSocket(socketId); if (soc) { soc.send(JSON.stringify({ "eventName": "receive_chat_msg", - "messages": data.messages, - "color": data.color + "data": { + "messages": data.messages, + "color": data.color + } }), function(error) { if (error) { console.log(error); diff --git a/example/webrtc.io.js b/example/webrtc.io.js deleted file mode 100644 index f751a77..0000000 --- a/example/webrtc.io.js +++ /dev/null @@ -1,297 +0,0 @@ -//CLIENT - - // Fallbacks for vendor-specific variables until the spec is finalized. -var PeerConnection = window.PeerConnection || window.webkitPeerConnection00; -var URL = window.URL || window.webkitURL || window.msURL || window.oURL; -var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; - -(function() { - - var rtc; - if ('undefined' === typeof module) { - rtc = this.rtc = {}; - } else { - rtc = module.exports = {}; - } - - - // Holds a connection to the server. - rtc._socket = null; - - // Holds callbacks for certain events. - rtc._events = {}; - - rtc.on = function(eventName, callback) { - rtc._events[eventName] = rtc._events[eventName] || []; - rtc._events[eventName].push(callback); - }; - - rtc.fire = function(eventName, _) { - var events = rtc._events[eventName]; - var args = Array.prototype.slice.call(arguments, 1); - - if (!events) { - return; - } - - for (var i = 0, len = events.length; i < len; i++) { - events[i].apply(null, args); - } - }; - - // Holds the STUN server to use for PeerConnections. - rtc.SERVER = "STUN stun.l.google.com:19302"; - - // Referenc e to the lone PeerConnection instance. - rtc.peerConnections = {}; - - // Array of known peer socket ids - rtc.connections = []; - // Stream-related variables. - rtc.streams = []; - rtc.numStreams = 0; - rtc.initializedStreams = 0; - - /** - * Connects to the websocket server. - */ - rtc.connect = function(server, room) { - room = room || ""; // by default, join a room called the blank string - rtc._socket = new WebSocket(server); - - rtc._socket.onopen = function() { - - rtc._socket.send(JSON.stringify({ - "eventName": "join_room", - "room": room - }), function(error){ - if(error){console.log(error);} - }); - - rtc._socket.onmessage = function(data) { - var json = JSON.parse(data.data); - rtc.fire(json.eventName, json); - }; - - rtc._socket.onerror = function(err) { - console.log('onerror'); - console.log(err); - }; - - rtc._socket.onclose = function(data) { - rtc.fire('disconnect stream', rtc._socket.id); - delete rtc.peerConnections[rtc._socket.id]; - }; - - rtc.on('get_peers', function(data) { - rtc.connections = data.connections; - // fire connections event and pass peers - rtc.fire('connections', rtc.connections); - }); - - rtc.on('receive_ice_candidate', function(data) { - var candidate = new IceCandidate(data.label, data.candidate); - rtc.peerConnections[data.socketId].processIceMessage(candidate); - - rtc.fire('receive ice candidate', candidate); - }); - - rtc.on('new_peer_connected', function(data) { - rtc.connections.push(data.socketId); - - var pc = rtc.createPeerConnection(data.socketId); - for (var i = 0; i < rtc.streams.length; i++) { - var stream = rtc.streams[i]; - pc.addStream(stream); - } - }); - - rtc.on('remove_peer_connected', function(data) { - rtc.fire('disconnect stream', data.socketId); - delete rtc.peerConnections[data.socketId]; - }); - - rtc.on('receive_offer', function(data) { - rtc.receiveOffer(data.socketId, data.sdp); - rtc.fire('receive offer', data); - }); - - rtc.on('receive_answer', function(data) { - rtc.receiveAnswer(data.socketId, data.sdp); - rtc.fire('receive answer', data); - }); - - rtc.fire('connect'); - }; - }; - - - rtc.sendOffers = function() { - for (var i = 0, len = rtc.connections.length; i < len; i++) { - var socketId = rtc.connections[i]; - rtc.sendOffer(socketId); - } - } - - rtc.onClose = function(data) { - rtc.on('close_stream', function() { - rtc.fire('close_stream', data); - }); - } - - rtc.createPeerConnections = function() { - for (var i = 0; i < rtc.connections.length; i++) { - rtc.createPeerConnection(rtc.connections[i]); - } - }; - - rtc.createPeerConnection = function(id) { - console.log('createPeerConnection'); - var pc = rtc.peerConnections[id] = new PeerConnection(rtc.SERVER, function(candidate, moreToFollow) { - if (candidate) { - rtc._socket.send(JSON.stringify({ - "eventName": "send_ice_candidate", - "label": candidate.label, - "candidate": candidate.toSdp(), - "socketId": id - }), function(error){ - if(error){console.log(error);} - }); - } - rtc.fire('ice candidate', candidate, moreToFollow); - }); - - pc.onopen = function() { - // TODO: Finalize this API - rtc.fire('peer connection opened'); - }; - - pc.onaddstream = function(event) { - // TODO: Finalize this API - rtc.fire('add remote stream', event.stream, id); - }; - return pc; - }; - - rtc.sendOffer = function(socketId) { - var pc = rtc.peerConnections[socketId]; - // TODO: Abstract away video: true, audio: true for offers - var offer = pc.createOffer({ - video: true, - audio: true - }); - pc.setLocalDescription(pc.SDP_OFFER, offer); - rtc._socket.send(JSON.stringify({ - "eventName": "send_offer", - "socketId": socketId, - "sdp": offer.toSdp() - }), function(error){ - if(error){console.log(error);} - }); - pc.startIce(); - }; - - - rtc.receiveOffer = function(socketId, sdp) { - var pc = rtc.peerConnections[socketId]; - pc.setRemoteDescription(pc.SDP_OFFER, new SessionDescription(sdp)); - rtc.sendAnswer(socketId); - }; - - - rtc.sendAnswer = function(socketId) { - var pc = rtc.peerConnections[socketId]; - var offer = pc.remoteDescription; - // TODO: Abstract away video: true, audio: true for answers - var answer = pc.createAnswer(offer.toSdp(), { - video: true, - audio: true - }); - pc.setLocalDescription(pc.SDP_ANSWER, answer); - rtc._socket.send(JSON.stringify({ - "eventName": "send_answer", - "socketId": socketId, - "sdp": answer.toSdp() - }), function(error){ - if(error){console.log(error);} - }); - pc.startIce(); - }; - - - rtc.receiveAnswer = function(socketId, sdp) { - var pc = rtc.peerConnections[socketId]; - pc.setRemoteDescription(pc.SDP_ANSWER, new SessionDescription(sdp)); - }; - - - rtc.createStream = function(opt, onSuccess, onFail) { - var options; - onSuccess = onSuccess || - function() {}; - onFail = onFail || - function() {}; - - if(opt.audio && opt.video){ - options = { - video: true, - audio: true - }; - }else if(opt.video){ - options = { - video: true, - audio: false - }; - }else if(opt.audio){ - options = { - video: false, - audio: true - }; - }else { - options = { - video: false, - audio: false - }; - } - - if (getUserMedia) { - rtc.numStreams++; - getUserMedia.call(navigator, options, function(stream) { - - rtc.streams.push(stream); - rtc.initializedStreams++; - onSuccess(stream); - if (rtc.initializedStreams === rtc.numStreams) { - rtc.fire('ready'); - } - }, function() { - alert("Could not connect stream."); - onFail(); - }); - } else { - alert('webRTC is not yet supported in this browser.'); - } - } - - - rtc.addStreams = function() { - for (var i = 0; i < rtc.streams.length; i++) { - var stream = rtc.streams[i]; - for (var connection in rtc.peerConnections) { - rtc.peerConnections[connection].addStream(stream); - } - } - }; - - - rtc.attachStream = function(stream, domId) { - document.getElementById(domId).src = URL.createObjectURL(stream); - }; - - rtc.on('ready', function() { - rtc.createPeerConnections(); - rtc.addStreams(); - rtc.sendOffers(); - }); - -}).call(this); \ No newline at end of file diff --git a/example/webrtc.io.js b/example/webrtc.io.js new file mode 120000 index 0000000..e0feac7 --- /dev/null +++ b/example/webrtc.io.js @@ -0,0 +1 @@ +../node_modules/webrtc.io-client/lib/webrtc.io.js \ No newline at end of file From d1ea3395d2adec3d4fb20e3689085ae8c6565345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20M=C3=A5rtensson?= Date: Mon, 13 Aug 2012 23:15:58 -0400 Subject: [PATCH 07/36] fix for ln -s --- example/webrtc.io.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/webrtc.io.js b/example/webrtc.io.js index e0feac7..c2fcf8b 120000 --- a/example/webrtc.io.js +++ b/example/webrtc.io.js @@ -1 +1 @@ -../node_modules/webrtc.io-client/lib/webrtc.io.js \ No newline at end of file +../node_modules/webRTC.io/node_modules/webrtc.io-client/lib/webrtc.io.js \ No newline at end of file From 64b00fee32255c7d07313cdc12a27442389517ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20M=C3=A5rtensson?= Date: Tue, 14 Aug 2012 10:18:53 -0400 Subject: [PATCH 08/36] fix symlink --- example/webrtc.io.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/webrtc.io.js b/example/webrtc.io.js index c2fcf8b..5b50d99 120000 --- a/example/webrtc.io.js +++ b/example/webrtc.io.js @@ -1 +1 @@ -../node_modules/webRTC.io/node_modules/webrtc.io-client/lib/webrtc.io.js \ No newline at end of file +../node_modules/webrtc.io/node_modules/webrtc.io-client/lib/webrtc.io.js \ No newline at end of file From 30c1ede3798e31afbaffea53fccce097a96d8a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20M=C3=A5rtensson?= Date: Sat, 18 Aug 2012 11:47:18 -0400 Subject: [PATCH 09/36] add .swp to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7dccd97..50077fb 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ lib-cov *.out *.pid *.gz +*.swp pids logs From e6bfa100daf642f811c1aefa025030bb5c18c2c8 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 12 Nov 2012 09:55:15 +0200 Subject: [PATCH 10/36] added suport of Chrome Version 25.0.1323.0 canary --- example/index.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/example/index.html b/example/index.html index 59c46cf..5100646 100644 --- a/example/index.html +++ b/example/index.html @@ -1,4 +1,3 @@ - Example webrtc.io @@ -22,7 +21,7 @@ + + +
+ Fork me on GitHub + +
+
+
+
+ +
+ +
+
Enter Full Screen
+
Create A New Room
+
+ + + + + diff --git a/site/script.js b/site/script.js new file mode 100644 index 0000000..b5a9420 --- /dev/null +++ b/site/script.js @@ -0,0 +1,203 @@ +var videos = []; +var rooms = [1, 2, 3, 4, 5]; +var PeerConnection = window.PeerConnection || window.webkitPeerConnection00 || window.webkitRTCPeerConnection; + +function getNumPerRow() { + var len = videos.length; + var biggest; + + // Ensure length is even for better division. + if(len % 2 === 1) { + len++; + } + + biggest = Math.ceil(Math.sqrt(len)); + while(len % biggest !== 0) { + biggest++; + } + return biggest; +} + +function subdivideVideos() { + var perRow = getNumPerRow(); + var numInRow = 0; + for(var i = 0, len = videos.length; i < len; i++) { + var video = videos[i]; + setWH(video, i); + numInRow = (numInRow + 1) % perRow; + } +} + +function setWH(video, i) { + var perRow = getNumPerRow(); + var perColumn = Math.ceil(videos.length / perRow); + var width = Math.floor((window.innerWidth) / perRow); + var height = Math.floor((window.innerHeight - 190) / perColumn); + video.width = width; + video.height = height; + video.style.position = "absolute"; + video.style.left = (i % perRow) * width + "px"; + video.style.top = Math.floor(i / perRow) * height + "px"; +} + +function cloneVideo(domId, socketId) { + var video = document.getElementById(domId); + var clone = video.cloneNode(false); + clone.id = "remote" + socketId; + document.getElementById('videos').appendChild(clone); + videos.push(clone); + return clone; +} + +function removeVideo(socketId) { + var video = document.getElementById('remote' + socketId); + if(video) { + videos.splice(videos.indexOf(video), 1); + video.parentNode.removeChild(video); + } +} + +function addToChat(msg, color) { + var messages = document.getElementById('messages'); + msg = sanitize(msg); + if(color) { + msg = '' + msg + ''; + } else { + msg = '' + msg + ''; + } + messages.innerHTML = messages.innerHTML + msg + '
'; + messages.scrollTop = 10000; +} + +function sanitize(msg) { + return msg.replace(/ Date: Thu, 21 Feb 2013 19:14:58 +0100 Subject: [PATCH 24/36] remove old version --- example/index.html | 225 ------------------------------------------- example/server.js | 58 ----------- example/style.css | 52 ---------- example/webrtc.io.js | 1 - 4 files changed, 336 deletions(-) delete mode 100644 example/index.html delete mode 100644 example/server.js delete mode 100644 example/style.css delete mode 120000 example/webrtc.io.js diff --git a/example/index.html b/example/index.html deleted file mode 100644 index 7e7fa05..0000000 --- a/example/index.html +++ /dev/null @@ -1,225 +0,0 @@ - - - Example webrtc.io - - - - - -
- Fork me on GitHub - -
-
- - -
-
-
- -
- - - diff --git a/example/server.js b/example/server.js deleted file mode 100644 index e69c8a1..0000000 --- a/example/server.js +++ /dev/null @@ -1,58 +0,0 @@ -var app = require('express')(); -var server = require('http').createServer(app); -var webRTC = require('webrtc.io').listen(server); - -server.listen(8000); - - - -app.get('/', function(req, res) { - res.sendfile(__dirname + '/index.html'); -}); - -app.get('/style.css', function(req, res) { - res.sendfile(__dirname + '/style.css'); -}); - -app.get('/webrtc.io.js', function(req, res) { - res.sendfile(__dirname + '/webrtc.io.js'); -}); - - -webRTC.rtc.on('connect', function(rtc) { - //Client connected -}); - -webRTC.rtc.on('send answer', function(rtc) { - //answer sent -}); - -webRTC.rtc.on('disconnect', function(rtc) { - //Client disconnect -}); - -webRTC.rtc.on('chat_msg', function(data, socket) { - var roomList = webRTC.rtc.rooms[data.room] || []; - - for (var i = 0; i < roomList.length; i++) { - var socketId = roomList[i]; - - if (socketId !== socket.id) { - var soc = webRTC.rtc.getSocket(socketId); - - if (soc) { - soc.send(JSON.stringify({ - "eventName": "receive_chat_msg", - "data": { - "messages": data.messages, - "color": data.color - } - }), function(error) { - if (error) { - console.log(error); - } - }); - } - } - } -}); diff --git a/example/style.css b/example/style.css deleted file mode 100644 index 14e6e61..0000000 --- a/example/style.css +++ /dev/null @@ -1,52 +0,0 @@ -html, body { - height: 100%; -} - -html { - overflow-y: scroll; -} - -body { - padding: 0; - margin: 0; -} - -#videos { - position: absolute; - top: 0px; - left: 0px; - right: 0px; - bottom: 0px; - background-color: #F0F6FB; -} - -#chatbox { - position: absolute; - height: 180px; - right: 20px; - left: 20px; - bottom: 0px; -} - -#chatinput { - width: 100%; - padding-top: 7px; - padding-bottom: 7px; - border-radius: 8px; - border-style:solid; - border-width:1px; -} - -#messages { - overflow: scroll; - height: 100px; - width: 100%; - background-color: white; - border-radius: 8px; - border-style:solid; - border-width:1px; -} - -.flip { --webkit-transform: rotateY(180deg); -} diff --git a/example/webrtc.io.js b/example/webrtc.io.js deleted file mode 120000 index e0feac7..0000000 --- a/example/webrtc.io.js +++ /dev/null @@ -1 +0,0 @@ -../node_modules/webrtc.io-client/lib/webrtc.io.js \ No newline at end of file From f195d17e09ffe539c1e738f28aac5b595bfae578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20M=C3=A5rtensson?= Date: Thu, 21 Feb 2013 19:18:37 +0100 Subject: [PATCH 25/36] fix in the readme setup instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5938120..e48e7b9 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ npm install ``` ```bash -cd example +cd site ``` ```bash From 1967058f85d38d9025e31e1bf5abc54a86dc3627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20M=C3=A5rtensson?= Date: Fri, 22 Feb 2013 08:23:25 +0100 Subject: [PATCH 26/36] remove google analytics --- site/index.html | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/site/index.html b/site/index.html index 41f481b..a90801b 100644 --- a/site/index.html +++ b/site/index.html @@ -22,19 +22,5 @@ - From 80bc181d63dba6374e11c120d56fb3b0b9e4af6f Mon Sep 17 00:00:00 2001 From: Daniel Kutik Date: Sat, 2 Mar 2013 23:27:12 -0500 Subject: [PATCH 27/36] declared --- site/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/script.js b/site/script.js index b5a9420..5361b8b 100644 --- a/site/script.js +++ b/site/script.js @@ -155,7 +155,7 @@ function initChat() { } }, false); rtc.on(chat.event, function() { - data = chat.recv.apply(this, arguments); + var data = chat.recv.apply(this, arguments); console.log(data.color); addToChat(data.messages, data.color.toString(16)); }); From fef618567c013dacd747d2a87a6e6b20429a5bca Mon Sep 17 00:00:00 2001 From: Daniel Kutik Date: Sat, 2 Mar 2013 23:31:55 -0500 Subject: [PATCH 28/36] Removed unused variable --- site/script.js | 1 - 1 file changed, 1 deletion(-) diff --git a/site/script.js b/site/script.js index 5361b8b..a039380 100644 --- a/site/script.js +++ b/site/script.js @@ -1,5 +1,4 @@ var videos = []; -var rooms = [1, 2, 3, 4, 5]; var PeerConnection = window.PeerConnection || window.webkitPeerConnection00 || window.webkitRTCPeerConnection; function getNumPerRow() { From 8502bf832c57a2af6ee3b3d6c04222c4f873d511 Mon Sep 17 00:00:00 2001 From: Daniel Kutik Date: Sat, 2 Mar 2013 23:46:17 -0500 Subject: [PATCH 29/36] Server listen port can now be defined in environment variables (useful for Heroku, CloudBees, cloud9), fallback to 8080 --- site/server.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/site/server.js b/site/server.js index a9d00e8..a45ebe1 100644 --- a/site/server.js +++ b/site/server.js @@ -2,7 +2,8 @@ var app = require('express')(); var server = require('http').createServer(app); var webRTC = require('webrtc.io').listen(server); -server.listen(8000); +var port = process.env.PORT || 8080; +server.listen(port); From cf3214c1a29d0a35cf1bfd34909cc431a6207e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20M=C3=A5rtensson?= Date: Mon, 4 Mar 2013 19:55:56 +0100 Subject: [PATCH 30/36] default port now 8080 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e48e7b9..2fdc7b8 100644 --- a/README.md +++ b/README.md @@ -29,11 +29,11 @@ node server.js In a version of Chrome that have webRTC support. -go to [localhost:8000](http://localhost:8000) +go to [localhost:8000](http://localhost:8080) click allow to see your camera -go to [localhost:8000](http://localhost:8000) +go to [localhost:8000](http://localhost:8080) click allow to see your camera and the connection will be made between your to open windows. From 2e596b28a8e0f7aaefd5b619372becd406648fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20M=C3=A5rtensson?= Date: Mon, 4 Mar 2013 19:56:55 +0100 Subject: [PATCH 31/36] fix the link text to --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2fdc7b8..bb56ce3 100644 --- a/README.md +++ b/README.md @@ -29,11 +29,11 @@ node server.js In a version of Chrome that have webRTC support. -go to [localhost:8000](http://localhost:8080) +go to [localhost:8080](http://localhost:8080) click allow to see your camera -go to [localhost:8000](http://localhost:8080) +go to [localhost:8080](http://localhost:8080) click allow to see your camera and the connection will be made between your to open windows. From 001fe6b7ae5f238312dce834eb01939ae17ba9dd Mon Sep 17 00:00:00 2001 From: Daniel Kutik Date: Wed, 6 Mar 2013 04:52:30 -0500 Subject: [PATCH 32/36] Updated webrtc.io.js --- site/webrtc.io.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/site/webrtc.io.js b/site/webrtc.io.js index 5b7e3f9..e2f5f90 100644 --- a/site/webrtc.io.js +++ b/site/webrtc.io.js @@ -69,7 +69,7 @@ var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || nav try { // raises exception if createDataChannel is not supported var pc = new PeerConnection(rtc.SERVER, rtc.dataChannelConfig); - channel = pc.createDataChannel('supportCheck', {reliable: false}); + var channel = pc.createDataChannel('supportCheck', {reliable: false}); channel.close(); return true; } catch(e) { @@ -245,7 +245,9 @@ var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || nav "socketId": socketId, "sdp": session_description } - })); + } + )); + //TODO Unused variable!? var offer = pc.remoteDescription; }); }; @@ -304,11 +306,13 @@ var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || nav rtc.createDataChannel = function(pcOrId, label) { if (!rtc.dataChannelSupport) { + //TODO this should be an exception alert('webRTC data channel is not yet supported in this browser,' + ' or you must turn on experimental flags'); return; } + var id, pc; if (typeof(pcOrId) === 'string') { id = pcOrId; pc = rtc.peerConnections[pcOrId]; @@ -331,8 +335,9 @@ var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || nav label = label || 'fileTransfer' || String(id); // chrome only supports reliable false atm. - options = {reliable: false}; + var options = {reliable: false}; + var channel; try { console.log('createDataChannel ' + id); channel = pc.createDataChannel(label, options); From e9b831374d87c7beb5e28d6e4746fc3f3367a21a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20M=C3=A5rtensson?= Date: Sun, 17 Mar 2013 19:01:41 +0100 Subject: [PATCH 33/36] now firefox to firefox works. It looks like there is a conection between firefox and chrome to but I have not gotten the media to play back. I dont know why the video is not playing back in the video tag... any one please have a look --- site/script.js | 5 +- site/server.js | 13 --- site/webrtc.io.js | 292 +++++++++++++++++++++++++++++++++++----------- 3 files changed, 224 insertions(+), 86 deletions(-) diff --git a/site/script.js b/site/script.js index a039380..1d8c16b 100644 --- a/site/script.js +++ b/site/script.js @@ -1,5 +1,5 @@ var videos = []; -var PeerConnection = window.PeerConnection || window.webkitPeerConnection00 || window.webkitRTCPeerConnection; +var PeerConnection = window.PeerConnection || window.webkitPeerConnection00 || window.webkitRTCPeerConnection || window.mozRTCPeerConnection || window.RTCPeerConnection; function getNumPerRow() { var len = videos.length; @@ -164,10 +164,11 @@ function initChat() { function init() { if(PeerConnection) { rtc.createStream({ - "video": true, + "video": {"mandatory": {}, "optional": []}, "audio": true }, function(stream) { document.getElementById('you').src = URL.createObjectURL(stream); + document.getElementById('you').play(); videos.push(document.getElementById('you')); //rtc.attachStream(stream, 'you'); subdivideVideos(); diff --git a/site/server.js b/site/server.js index a45ebe1..88953a6 100644 --- a/site/server.js +++ b/site/server.js @@ -27,19 +27,6 @@ app.get('/webrtc.io.js', function(req, res) { res.sendfile(__dirname + '/webrtc.io.js'); }); - -webRTC.rtc.on('connect', function(rtc) { - //Client connected -}); - -webRTC.rtc.on('send answer', function(rtc) { - //answer sent -}); - -webRTC.rtc.on('disconnect', function(rtc) { - //Client disconnect -}); - webRTC.rtc.on('chat_msg', function(data, socket) { var roomList = webRTC.rtc.rooms[data.room] || []; diff --git a/site/webrtc.io.js b/site/webrtc.io.js index e2f5f90..e9dd499 100644 --- a/site/webrtc.io.js +++ b/site/webrtc.io.js @@ -1,10 +1,40 @@ //CLIENT - // Fallbacks for vendor-specific variables until the spec is finalized. +// Fallbacks for vendor-specific variables until the spec is finalized. + +var PeerConnection = (window.PeerConnection || window.webkitPeerConnection00 || window.webkitRTCPeerConnection || window.mozRTCPeerConnection); +var URL = (window.URL || window.webkitURL || window.msURL || window.oURL); +var getUserMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia); +var nativeRTCIceCandidate = (window.mozRTCIceCandidate || window.RTCIceCandidate); +var nativeRTCSessionDescription = (window.mozRTCSessionDescription || window.RTCSessionDescription); // order is very important: "RTCSessionDescription" defined in Nighly but useless + +var sdpConstraints = { + 'mandatory': { + 'OfferToReceiveAudio': true, + 'OfferToReceiveVideo': true + } +}; -var PeerConnection = window.PeerConnection || window.webkitPeerConnection00 || window.webkitRTCPeerConnection; -var URL = window.URL || window.webkitURL || window.msURL || window.oURL; -var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; +if (navigator.webkitGetUserMedia) { + if (!webkitMediaStream.prototype.getVideoTracks) { + webkitMediaStream.prototype.getVideoTracks = function() { + return this.videoTracks; + }; + webkitMediaStream.prototype.getAudioTracks = function() { + return this.audioTracks; + }; + } + + // New syntax of getXXXStreams method in M26. + if (!webkitRTCPeerConnection.prototype.getLocalStreams) { + webkitRTCPeerConnection.prototype.getLocalStreams = function() { + return this.localStreams; + }; + webkitRTCPeerConnection.prototype.getRemoteStreams = function() { + return this.remoteStreams; + }; + } +} (function() { @@ -44,7 +74,21 @@ var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || nav }; // Holds the STUN/ICE server to use for PeerConnections. - rtc.SERVER = {iceServers:[{url:"stun:stun.l.google.com:19302"}]}; + rtc.SERVER = function() { + if (navigator.mozGetUserMedia) { + return { + "iceServers": [{ + "url": "stun:23.21.150.121" + }] + }; + } + return { + "iceServers": [{ + "url": "stun:stun.l.google.com:19302" + }] + }; + } + // Reference to the lone PeerConnection instance. rtc.peerConnections = {}; @@ -61,18 +105,32 @@ var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || nav rtc.dataChannels = {}; // PeerConnection datachannel configuration - rtc.dataChannelConfig = {optional: [ {RtpDataChannels: true} ] }; + rtc.dataChannelConfig = { + "optional": [{ + "RtpDataChannels": true + }, { + "DtlsSrtpKeyAgreement": true + }] + }; + + rtc.pc_constraints = { + "optional": [{ + "DtlsSrtpKeyAgreement": true + }] + } // check whether data channel is supported. rtc.checkDataChannelSupport = function() { try { // raises exception if createDataChannel is not supported - var pc = new PeerConnection(rtc.SERVER, rtc.dataChannelConfig); - var channel = pc.createDataChannel('supportCheck', {reliable: false}); + var pc = new PeerConnection(rtc.SERVER(), rtc.dataChannelConfig); + var channel = pc.createDataChannel('supportCheck', { + reliable: false + }); channel.close(); return true; - } catch(e) { + } catch (e) { return false; } }; @@ -91,7 +149,7 @@ var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || nav rtc._socket.send(JSON.stringify({ "eventName": "join_room", - "data":{ + "data": { "room": room } })); @@ -119,7 +177,7 @@ var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || nav }); rtc.on('receive_ice_candidate', function(data) { - var candidate = new RTCIceCandidate(data); + var candidate = new nativeRTCIceCandidate(data); rtc.peerConnections[data.socketId].addIceCandidate(candidate); rtc.fire('receive ice candidate', candidate); }); @@ -174,24 +232,24 @@ var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || nav }; rtc.createPeerConnection = function(id) { - var config; - if (rtc.dataChannelSupport) - config = rtc.dataChannelConfig; - var pc = rtc.peerConnections[id] = new PeerConnection(rtc.SERVER, config); + var config = rtc.pc_constraints; + if (rtc.dataChannelSupport) config = rtc.dataChannelConfig; + + var pc = rtc.peerConnections[id] = new PeerConnection(rtc.SERVER(), config); pc.onicecandidate = function(event) { if (event.candidate) { - rtc._socket.send(JSON.stringify({ - "eventName": "send_ice_candidate", - "data": { - "label": event.candidate.label, - "candidate": event.candidate.candidate, - "socketId": id - } - })); - } - rtc.fire('ice candidate', event.candidate); - }; + rtc._socket.send(JSON.stringify({ + "eventName": "send_ice_candidate", + "data": { + "label": event.candidate.sdpMLineIndex, + "candidate": event.candidate.candidate, + "socketId": id + } + })); + } + rtc.fire('ice candidate', event.candidate); + }; pc.onopen = function() { // TODO: Finalize this API @@ -204,7 +262,7 @@ var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || nav }; if (rtc.dataChannelSupport) { - pc.ondatachannel = function (evt) { + pc.ondatachannel = function(evt) { console.log('data channel connecting ' + id); rtc.addDataChannel(id, evt.channel); }; @@ -215,60 +273,73 @@ var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || nav rtc.sendOffer = function(socketId) { var pc = rtc.peerConnections[socketId]; - pc.createOffer( function(session_description) { - pc.setLocalDescription(session_description); - rtc._socket.send(JSON.stringify({ + + var constraints = { + "optional": [], + "mandatory": { + "MozDontOfferDataChannel": true + } + }; + // temporary measure to remove Moz* constraints in Chrome + if (navigator.webkitGetUserMedia) { + for (prop in constraints.mandatory) { + if (prop.indexOf("Moz") != -1) { + delete constraints.mandatory[prop]; + } + } + } + constraints = mergeConstraints(constraints, sdpConstraints); + + pc.createOffer(function(session_description) { + session_description.sdp = preferOpus(session_description.sdp); + pc.setLocalDescription(session_description); + rtc._socket.send(JSON.stringify({ "eventName": "send_offer", - "data":{ - "socketId": socketId, - "sdp": session_description - } - })); - }); + "data": { + "socketId": socketId, + "sdp": session_description + } + })); + }, null, sdpConstraints); }; - rtc.receiveOffer = function(socketId, sdp) { var pc = rtc.peerConnections[socketId]; - pc.setRemoteDescription(new RTCSessionDescription(sdp)); - rtc.sendAnswer(socketId); + rtc.sendAnswer(socketId, sdp); }; - - rtc.sendAnswer = function(socketId) { + rtc.sendAnswer = function(socketId, sdp) { var pc = rtc.peerConnections[socketId]; - pc.createAnswer( function(session_description) { - pc.setLocalDescription(session_description); - rtc._socket.send(JSON.stringify({ + pc.setRemoteDescription(new nativeRTCSessionDescription(sdp)); + pc.createAnswer(function(session_description) { + pc.setLocalDescription(session_description); + rtc._socket.send(JSON.stringify({ "eventName": "send_answer", - "data":{ - "socketId": socketId, - "sdp": session_description - } + "data": { + "socketId": socketId, + "sdp": session_description } - )); - //TODO Unused variable!? - var offer = pc.remoteDescription; - }); + })); + //TODO Unused variable!? + var offer = pc.remoteDescription; + }, null, sdpConstraints); }; rtc.receiveAnswer = function(socketId, sdp) { var pc = rtc.peerConnections[socketId]; - pc.setRemoteDescription(new RTCSessionDescription(sdp)); + pc.setRemoteDescription(new nativeRTCSessionDescription(sdp)); }; rtc.createStream = function(opt, onSuccess, onFail) { var options; - onSuccess = onSuccess || - function() {}; - onFail = onFail || - function() {}; + onSuccess = onSuccess || function() {}; + onFail = onFail || function() {}; options = { - video: !!opt.video, - audio: !!opt.audio + video: !! opt.video, + audio: !! opt.audio }; if (getUserMedia) { @@ -300,7 +371,14 @@ var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || nav }; rtc.attachStream = function(stream, domId) { - document.getElementById(domId).src = URL.createObjectURL(stream); + var element = document.getElementById(domId); + if (navigator.mozGetUserMedia) { + console.log("Attaching media stream"); + element.mozSrcObject = stream; + element.play(); + } else { + element.src = webkitURL.createObjectURL(stream); + } }; @@ -308,7 +386,7 @@ var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || nav if (!rtc.dataChannelSupport) { //TODO this should be an exception alert('webRTC data channel is not yet supported in this browser,' + - ' or you must turn on experimental flags'); + ' or you must turn on experimental flags'); return; } @@ -320,22 +398,21 @@ var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || nav pc = pcOrId; id = undefined; for (var key in rtc.peerConnections) { - if (rtc.peerConnections[key] === pc) - id = key; + if (rtc.peerConnections[key] === pc) id = key; } } - if (!id) - throw new Error ('attempt to createDataChannel with unknown id'); + if (!id) throw new Error('attempt to createDataChannel with unknown id'); - if (!pc || !(pc instanceof PeerConnection)) - throw new Error ('attempt to createDataChannel without peerConnection'); + if (!pc || !(pc instanceof PeerConnection)) throw new Error('attempt to createDataChannel without peerConnection'); // need a label label = label || 'fileTransfer' || String(id); // chrome only supports reliable false atm. - var options = {reliable: false}; + var options = { + reliable: false + }; var channel; try { @@ -379,11 +456,10 @@ var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || nav }; rtc.addDataChannels = function() { - if (!rtc.dataChannelSupport) - return; + if (!rtc.dataChannelSupport) return; for (var connection in rtc.peerConnections) - rtc.createDataChannel(connection); + rtc.createDataChannel(connection); }; @@ -395,3 +471,77 @@ var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || nav }); }).call(this); + +function preferOpus(sdp) { + var sdpLines = sdp.split('\r\n'); + + // Search for m line. + for (var i = 0; i < sdpLines.length; i++) { + if (sdpLines[i].search('m=audio') !== -1) { + var mLineIndex = i; + break; + } + } + if (mLineIndex === null) return sdp; + + // If Opus is available, set it as the default in m line. + for (var i = 0; i < sdpLines.length; i++) { + if (sdpLines[i].search('opus/48000') !== -1) { + var opusPayload = extractSdp(sdpLines[i], /:(\d+) opus\/48000/i); + if (opusPayload) sdpLines[mLineIndex] = setDefaultCodec(sdpLines[mLineIndex], opusPayload); + break; + } + } + + // Remove CN in m line and sdp. + sdpLines = removeCN(sdpLines, mLineIndex); + + sdp = sdpLines.join('\r\n'); + return sdp; +} + +function extractSdp(sdpLine, pattern) { + var result = sdpLine.match(pattern); + return (result && result.length == 2) ? result[1] : null; +} + +function setDefaultCodec(mLine, payload) { + var elements = mLine.split(' '); + var newLine = new Array(); + var index = 0; + for (var i = 0; i < elements.length; i++) { + if (index === 3) // Format of media starts from the fourth. + newLine[index++] = payload; // Put target payload to the first. + if (elements[i] !== payload) newLine[index++] = elements[i]; + } + return newLine.join(' '); +} + +function removeCN(sdpLines, mLineIndex) { + var mLineElements = sdpLines[mLineIndex].split(' '); + // Scan from end for the convenience of removing an item. + for (var i = sdpLines.length - 1; i >= 0; i--) { + var payload = extractSdp(sdpLines[i], /a=rtpmap:(\d+) CN\/\d+/i); + if (payload) { + var cnPos = mLineElements.indexOf(payload); + if (cnPos !== -1) { + // Remove CN payload from m line. + mLineElements.splice(cnPos, 1); + } + // Remove CN line in sdp + sdpLines.splice(i, 1); + } + } + + sdpLines[mLineIndex] = mLineElements.join(' '); + return sdpLines; +} + +function mergeConstraints(cons1, cons2) { + var merged = cons1; + for (var name in cons2.mandatory) { + merged.mandatory[name] = cons2.mandatory[name]; + } + merged.optional.concat(cons2.optional); + return merged; +} \ No newline at end of file From 6b0023f5e45af7567d607b148219f820430d3540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20M=C3=A5rtensson?= Date: Sun, 17 Mar 2013 19:14:18 +0100 Subject: [PATCH 34/36] fix the problems in the last build --- site/webrtc.io.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/site/webrtc.io.js b/site/webrtc.io.js index e9dd499..ec5cf93 100644 --- a/site/webrtc.io.js +++ b/site/webrtc.io.js @@ -87,7 +87,7 @@ if (navigator.webkitGetUserMedia) { "url": "stun:stun.l.google.com:19302" }] }; - } + }; // Reference to the lone PeerConnection instance. @@ -117,7 +117,7 @@ if (navigator.webkitGetUserMedia) { "optional": [{ "DtlsSrtpKeyAgreement": true }] - } + }; // check whether data channel is supported. @@ -282,7 +282,7 @@ if (navigator.webkitGetUserMedia) { }; // temporary measure to remove Moz* constraints in Chrome if (navigator.webkitGetUserMedia) { - for (prop in constraints.mandatory) { + for (var prop in constraints.mandatory) { if (prop.indexOf("Moz") != -1) { delete constraints.mandatory[prop]; } @@ -477,17 +477,18 @@ function preferOpus(sdp) { // Search for m line. for (var i = 0; i < sdpLines.length; i++) { + var mLineIndex = null; if (sdpLines[i].search('m=audio') !== -1) { - var mLineIndex = i; + mLineIndex = i; break; } } if (mLineIndex === null) return sdp; // If Opus is available, set it as the default in m line. - for (var i = 0; i < sdpLines.length; i++) { - if (sdpLines[i].search('opus/48000') !== -1) { - var opusPayload = extractSdp(sdpLines[i], /:(\d+) opus\/48000/i); + for (var j = 0; j < sdpLines.length; j++) { + if (sdpLines[j].search('opus/48000') !== -1) { + var opusPayload = extractSdp(sdpLines[j], /:(\d+) opus\/48000/i); if (opusPayload) sdpLines[mLineIndex] = setDefaultCodec(sdpLines[mLineIndex], opusPayload); break; } From e40f50efc6b786f1416fb70fb90ee5ab4b148d1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20M=C3=A5rtensson?= Date: Sun, 17 Mar 2013 19:20:22 +0100 Subject: [PATCH 35/36] sorry did miss some of them --- site/webrtc.io.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/site/webrtc.io.js b/site/webrtc.io.js index ec5cf93..1393f41 100644 --- a/site/webrtc.io.js +++ b/site/webrtc.io.js @@ -474,10 +474,9 @@ if (navigator.webkitGetUserMedia) { function preferOpus(sdp) { var sdpLines = sdp.split('\r\n'); - + var mLineIndex = null; // Search for m line. for (var i = 0; i < sdpLines.length; i++) { - var mLineIndex = null; if (sdpLines[i].search('m=audio') !== -1) { mLineIndex = i; break; @@ -508,7 +507,7 @@ function extractSdp(sdpLine, pattern) { function setDefaultCodec(mLine, payload) { var elements = mLine.split(' '); - var newLine = new Array(); + var newLine = []; var index = 0; for (var i = 0; i < elements.length; i++) { if (index === 3) // Format of media starts from the fourth. From 79b1a1576aa8ab65d04c9fb80416772f3f3fb299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20M=C3=A5rtensson?= Date: Fri, 22 Mar 2013 22:40:03 +0100 Subject: [PATCH 36/36] add toogle to message and made the video of you smaller --- site/index.html | 5 +++-- site/script.js | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/site/index.html b/site/index.html index a90801b..eb38f1f 100644 --- a/site/index.html +++ b/site/index.html @@ -8,9 +8,10 @@
Fork me on GitHub - +
+
toggle chat
@@ -23,4 +24,4 @@ - + \ No newline at end of file diff --git a/site/script.js b/site/script.js index 1d8c16b..145205a 100644 --- a/site/script.js +++ b/site/script.js @@ -135,9 +135,22 @@ function initChat() { } var input = document.getElementById("chatinput"); + var toggleHideShow = document.getElementById("hideShowMessages"); var room = window.location.hash.slice(1); var color = "#" + ((1 << 24) * Math.random() | 0).toString(16); + toggleHideShow.addEventListener('click', function() { + var element = document.getElementById("messages"); + + if(element.style.display === "block") { + element.style.display = "none"; + } + else { + element.style.display = "block"; + } + + }); + input.addEventListener('keydown', function(event) { var key = event.which || event.keyCode; if(key === 13) { @@ -169,9 +182,9 @@ function init() { }, function(stream) { document.getElementById('you').src = URL.createObjectURL(stream); document.getElementById('you').play(); - videos.push(document.getElementById('you')); + //videos.push(document.getElementById('you')); //rtc.attachStream(stream, 'you'); - subdivideVideos(); + //subdivideVideos(); }); } else { alert('Your browser is not supported or you have to turn on flags. In chrome you go to chrome://flags and turn on Enable PeerConnection remember to restart chrome');