Skip to content

Commit

Permalink
Fixing #34, adding new TURN format for M28
Browse files Browse the repository at this point in the history
https://webrtc-experiment.appspot.com/chat-hangout/
https://webrtc-experiment.appspot.com/file-hangout/

Both experiments are now firing "channel.onclose" event.

New TURN format is added for RTCMultiConnection v1.1, v1.2 and v1.3 —
DataChannel.js —  RTCall.js — and RTCPeerConnection v1.5 and v1.6
  • Loading branch information
muaz-khan committed May 30, 2013
1 parent 6df6a55 commit c0688f9
Show file tree
Hide file tree
Showing 18 changed files with 780 additions and 609 deletions.
14 changes: 13 additions & 1 deletion DataChannel/DataChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@
window.onunload = function () {
leaveChannels();
};

window.onkeyup = function(e) {
if(e.keyCode == 116) leaveChannels();
};

(function () {
var anchors = document.querySelectorAll('a'), length = anchors.length;
Expand Down Expand Up @@ -826,7 +830,15 @@
iceServers: options.iceServers || [STUN]
};

if (!moz && !options.iceServers) iceServers.iceServers = [TURN, STUN];
if (!moz && !options.iceServers) {
if (parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2]) >= 28)
TURN = {
url: 'turn:numb.viagenie.ca',
credential: 'muazkh',
username: '[email protected]'
};
iceServers.iceServers = [TURN, STUN];
}

var optional = {
optional: []
Expand Down
2 changes: 1 addition & 1 deletion Pluginfree-Screen-Sharing/conference-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function captureUserMedia(callback) {
if (location.protocol === 'http:') {
alert('Please test this WebRTC experiment on HTTPS.');
} else {
alert('Screen capturing is either denied or not supported.');
alert('Screen capturing is either denied or not supported. Are you enabled flag: "Enable screen capture support in getUserMedia"?');
}
}
});
Expand Down
30 changes: 20 additions & 10 deletions Pluginfree-Screen-Sharing/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,29 @@ <h2>
<script src="https://webrtc-experiment.appspot.com/Pluginfree-Screen-Sharing/conference.js"></script>
<script src="https://webrtc-experiment.appspot.com/Pluginfree-Screen-Sharing/conference-ui.js"></script>

<br />
<br />
<h2>You must make sure that:</h2>

<br />
<br />

<blockquote>
<ol>
<li>You're using <span style="color: red;">chrome canary</span> (If you want to share your own screen).</li>
<li>You enabled flag "<code>Enable screen capture support in getUserMedia()</code>" – via – "<code>chrome://flags</code>"</li>
</ol>
<h2>Enable screen capture support in getUserMedia()</h2>

<br /><br />

Allow web pages to request access to the screen contents via the getUserMedia() API. #enable-usermedia-screen-capture

<br /><br />

You must enable this flag via "chrome://flags/"

</blockquote>

<h2>To use code in your own site, you must understand following limitations:</h2>

<br />
<br />

<blockquote>
<h2>To use code in your own site, you must understand following limitations:</h2>
<br />
<br />
Chrome Canary <span style="color: red;">denies</span> "screen capturing" request automatically if:
<ol>
<li>You've not used '<code>chromeMediaSource</code>' constraint:
Expand All @@ -253,6 +262,7 @@ <h2>To use code in your own site, you must understand following limitations:</h2
</li>
<li>You requested audio-stream alongwith '<code>chromeMediaSource</code>' – it is not permitted.</li>
<li>You're not testing it on SSL origin (HTTPS domain).</li>
<li>"screen capturing" is requested multiple times per tab. Maximum one request is permitted per page!</li>
</ol>
<br />
Remember, recursive cascade images or blurred screen is chrome's implementation issues. It will be solved soon.
Expand Down
2 changes: 1 addition & 1 deletion RTCMultiConnection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ connection.onmessage = function (e) {
}
```

### Direct Messages
#### Direct Messages

You can share data directly between two unique users using their user-ids:

Expand Down
13 changes: 11 additions & 2 deletions RTCMultiConnection/RTCMultiConnection-v1.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function RTCMultiConnection(channel) {
if (location.protocol === 'http:') {
throw 'Please test this WebRTC experiment on HTTPS.';
} else {
throw 'Screen capturing is either denied or not supported.';
throw 'Screen capturing is either denied or not supported. Are you enabled flag: "Enable screen capture support in getUserMedia"?';
}
} else {
throw 'Unable to get access to your webcam';
Expand Down Expand Up @@ -282,7 +282,16 @@ var RTCPeerConnection = function (options) {
var iceServers = {
iceServers: options.iceServers || [STUN]
};
if (!moz && !options.iceServers) iceServers.iceServers[1] = TURN;

if (!moz && !options.iceServers) {
if (parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2]) >= 28)
TURN = {
url: 'turn:numb.viagenie.ca',
credential: 'muazkh',
username: '[email protected]'
};
iceServers.iceServers = [TURN, STUN];
}

var optional = {
optional: []
Expand Down
12 changes: 10 additions & 2 deletions RTCMultiConnection/RTCMultiConnection-v1.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
if (location.protocol === 'http:') {
throw 'Please test this WebRTC experiment on HTTPS.';
} else {
throw 'Screen capturing is either denied or not supported.';
throw 'Screen capturing is either denied or not supported. Are you enabled flag: "Enable screen capture support in getUserMedia"?';
}
} else {
throw 'Unable to get access to your webcam';
Expand Down Expand Up @@ -378,7 +378,15 @@
iceServers: options.iceServers || [STUN]
};

if (!moz && !options.iceServers) iceServers.iceServers = [TURN, STUN];
if (!moz && !options.iceServers) {
if (parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2]) >= 28)
TURN = {
url: 'turn:numb.viagenie.ca',
credential: 'muazkh',
username: '[email protected]'
};
iceServers.iceServers = [TURN, STUN];
}

var optional = {
optional: []
Expand Down
16 changes: 14 additions & 2 deletions RTCMultiConnection/RTCMultiConnection-v1.3.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
if (session.audio && !session.video) throw 'Microphone access is denied.';
else if (session.screen) {
if (location.protocol === 'http:') throw '<https> is mandatory to capture screen.';
else throw 'Multi-capturing of screen is not allowed. Capturing process is denied.';
else throw 'Multi-capturing of screen is not allowed. Capturing process is denied. Are you enabled flag: "Enable screen capture support in getUserMedia"?';
} else throw 'Webcam access is denied.';
}
};
Expand Down Expand Up @@ -600,6 +600,10 @@
window.onunload = function () {
leaveARoom();
};

window.onkeyup = function(e) {
if(e.keyCode == 116) leaveARoom();
};

(function () {
var anchors = document.querySelectorAll('a'), length = anchors.length;
Expand Down Expand Up @@ -948,7 +952,15 @@
iceServers: options.iceServers || [STUN]
};

if (!moz && !options.iceServers) iceServers.iceServers = [TURN, STUN];
if (!moz && !options.iceServers) {
if (parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2]) >= 28)
TURN = {
url: 'turn:numb.viagenie.ca',
credential: 'muazkh',
username: '[email protected]'
};
iceServers.iceServers = [TURN, STUN];
}

optional = {
optional: []
Expand Down
89 changes: 50 additions & 39 deletions RTCPeerConnection/RTCPeerConnection-v1.5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
2013, Muaz Khan<muazkh>--[github.com/muaz-khan]
Demo & Documentation: http://bit.ly/RTCPeerConnection-Documentation */

window.moz = !!navigator.mozGetUserMedia;
window.moz = !! navigator.mozGetUserMedia;
var RTCPeerConnection = function (options) {
var w = window,
PeerConnection = w.mozRTCPeerConnection || w.webkitRTCPeerConnection,
Expand All @@ -23,21 +22,31 @@ var RTCPeerConnection = function (options) {
iceServers: options.iceServers || [STUN]
};

if (!moz && !options.iceServers) iceServers.iceServers = [TURN, STUN];
if (!moz && !options.iceServers) {
if (parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2]) >= 28)
TURN = {
url: 'turn:numb.viagenie.ca',
credential: 'muazkh',
username: '[email protected]'
};
iceServers.iceServers = [TURN, STUN];
}

var optional = {
optional: []
};

if (!moz) {
optional.optional = [{
DtlsSrtpKeyAgreement: true
}];
DtlsSrtpKeyAgreement: true
}
];

if (options.onChannelMessage)
optional.optional = [{
RtpDataChannels: true
}];
RtpDataChannels: true
}
];
}

var peerConnection = new PeerConnection(iceServers, optional);
Expand Down Expand Up @@ -89,7 +98,7 @@ var RTCPeerConnection = function (options) {
var inline = getChars() + '\r\n' + (extractedChars = '');
sdp = sdp.indexOf('a=crypto') == -1 ? sdp.replace(/c=IN/g,
'a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:' + inline +
'c=IN') : sdp;
'c=IN') : sdp;

if (options.offerSDP) {
info('\n--------offer sdp provided by offerer\n');
Expand All @@ -108,10 +117,10 @@ var RTCPeerConnection = function (options) {
if (!options.onOfferSDP) return;

peerConnection.createOffer(function (sessionDescription) {
sessionDescription.sdp = getInteropSDP(sessionDescription.sdp);
peerConnection.setLocalDescription(sessionDescription);
options.onOfferSDP(sessionDescription);
}, null, constraints);
sessionDescription.sdp = getInteropSDP(sessionDescription.sdp);
peerConnection.setLocalDescription(sessionDescription);
options.onOfferSDP(sessionDescription);
}, null, constraints);
}

function createAnswer() {
Expand All @@ -121,10 +130,10 @@ var RTCPeerConnection = function (options) {
peerConnection.setRemoteDescription(options.offerSDP);

peerConnection.createAnswer(function (sessionDescription) {
sessionDescription.sdp = getInteropSDP(sessionDescription.sdp);
peerConnection.setLocalDescription(sessionDescription);
options.onAnswerSDP(sessionDescription);
}, null, constraints);
sessionDescription.sdp = getInteropSDP(sessionDescription.sdp);
peerConnection.setLocalDescription(sessionDescription);
options.onAnswerSDP(sessionDescription);
}, null, constraints);
}

if ((options.onChannelMessage && !moz) || !options.onChannelMessage) {
Expand All @@ -141,12 +150,12 @@ var RTCPeerConnection = function (options) {

if (moz && !options.attachStream) {
navigator.mozGetUserMedia({
audio: true,
fake: true
}, function (stream) {
peerConnection.addStream(stream);
createOffer();
}, useless);
audio: true,
fake: true
}, function (stream) {
peerConnection.addStream(stream);
createOffer();
}, useless);
}
}

Expand All @@ -171,6 +180,8 @@ var RTCPeerConnection = function (options) {
};
channel.onclose = function (event) {
if (options.onChannelClosed) options.onChannelClosed(event);

console.warn('WebRTC DataChannel closed', event);
};
channel.onerror = function (event) {
console.error(event);
Expand All @@ -189,17 +200,16 @@ var RTCPeerConnection = function (options) {

if (moz && !options.attachStream) {
navigator.mozGetUserMedia({
audio: true,
fake: true
}, function (stream) {
peerConnection.addStream(stream);
createAnswer();
}, useless);
audio: true,
fake: true
}, function (stream) {
peerConnection.addStream(stream);
createAnswer();
}, useless);
}
}

function useless() {
}
function useless() {}

function info(information) {
console.log(information);
Expand All @@ -216,9 +226,9 @@ var RTCPeerConnection = function (options) {
addICE: function (candidate) {
info(candidate.candidate);
peerConnection.addIceCandidate(new IceCandidate({
sdpMLineIndex: candidate.sdpMLineIndex,
candidate: candidate.candidate
}));
sdpMLineIndex: candidate.sdpMLineIndex,
candidate: candidate.candidate
}));
},

peer: peerConnection,
Expand All @@ -235,14 +245,15 @@ var video_constraints = {
};

function getUserMedia(options) {
var n = navigator, media;
var n = navigator,
media;
n.getMedia = n.webkitGetUserMedia || n.mozGetUserMedia;
n.getMedia(options.constraints || {
audio: true,
video: video_constraints
}, streaming, options.onerror || function (e) {
console.error(e);
});
audio: true,
video: video_constraints
}, streaming, options.onerror || function (e) {
console.error(e);
});

function streaming(stream) {
var video = options.video;
Expand Down
Loading

0 comments on commit c0688f9

Please sign in to comment.