Skip to content

Commit c0688f9

Browse files
committed
Fixing muaz-khan#34, adding new TURN format for M28
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
1 parent 6df6a55 commit c0688f9

File tree

18 files changed

+780
-609
lines changed

18 files changed

+780
-609
lines changed

DataChannel/DataChannel.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,10 @@
488488
window.onunload = function () {
489489
leaveChannels();
490490
};
491+
492+
window.onkeyup = function(e) {
493+
if(e.keyCode == 116) leaveChannels();
494+
};
491495

492496
(function () {
493497
var anchors = document.querySelectorAll('a'), length = anchors.length;
@@ -826,7 +830,15 @@
826830
iceServers: options.iceServers || [STUN]
827831
};
828832

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

831843
var optional = {
832844
optional: []

Pluginfree-Screen-Sharing/conference-ui.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function captureUserMedia(callback) {
8787
if (location.protocol === 'http:') {
8888
alert('Please test this WebRTC experiment on HTTPS.');
8989
} else {
90-
alert('Screen capturing is either denied or not supported.');
90+
alert('Screen capturing is either denied or not supported. Are you enabled flag: "Enable screen capture support in getUserMedia"?');
9191
}
9292
}
9393
});

Pluginfree-Screen-Sharing/index.html

+20-10
Original file line numberDiff line numberDiff line change
@@ -228,20 +228,29 @@ <h2>
228228
<script src="https://webrtc-experiment.appspot.com/Pluginfree-Screen-Sharing/conference.js"></script>
229229
<script src="https://webrtc-experiment.appspot.com/Pluginfree-Screen-Sharing/conference-ui.js"></script>
230230

231-
<br />
232-
<br />
233-
<h2>You must make sure that:</h2>
234-
231+
<br />
232+
<br />
233+
235234
<blockquote>
236-
<ol>
237-
<li>You're using <span style="color: red;">chrome canary</span> (If you want to share your own screen).</li>
238-
<li>You enabled flag "<code>Enable screen capture support in getUserMedia()</code>" – via – "<code>chrome://flags</code>"</li>
239-
</ol>
235+
<h2>Enable screen capture support in getUserMedia()</h2>
236+
237+
<br /><br />
238+
239+
Allow web pages to request access to the screen contents via the getUserMedia() API. #enable-usermedia-screen-capture
240+
241+
<br /><br />
242+
243+
You must enable this flag via "chrome://flags/"
244+
240245
</blockquote>
241-
242-
<h2>To use code in your own site, you must understand following limitations:</h2>
246+
247+
<br />
248+
<br />
243249

244250
<blockquote>
251+
<h2>To use code in your own site, you must understand following limitations:</h2>
252+
<br />
253+
<br />
245254
Chrome Canary <span style="color: red;">denies</span> "screen capturing" request automatically if:
246255
<ol>
247256
<li>You've not used '<code>chromeMediaSource</code>' constraint:
@@ -253,6 +262,7 @@ <h2>To use code in your own site, you must understand following limitations:</h2
253262
</li>
254263
<li>You requested audio-stream alongwith '<code>chromeMediaSource</code>' – it is not permitted.</li>
255264
<li>You're not testing it on SSL origin (HTTPS domain).</li>
265+
<li>"screen capturing" is requested multiple times per tab. Maximum one request is permitted per page!</li>
256266
</ol>
257267
<br />
258268
Remember, recursive cascade images or blurred screen is chrome's implementation issues. It will be solved soon.

RTCMultiConnection/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ connection.onmessage = function (e) {
217217
}
218218
```
219219

220-
### Direct Messages
220+
#### Direct Messages
221221

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

RTCMultiConnection/RTCMultiConnection-v1.1.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function RTCMultiConnection(channel) {
215215
if (location.protocol === 'http:') {
216216
throw 'Please test this WebRTC experiment on HTTPS.';
217217
} else {
218-
throw 'Screen capturing is either denied or not supported.';
218+
throw 'Screen capturing is either denied or not supported. Are you enabled flag: "Enable screen capture support in getUserMedia"?';
219219
}
220220
} else {
221221
throw 'Unable to get access to your webcam';
@@ -282,7 +282,16 @@ var RTCPeerConnection = function (options) {
282282
var iceServers = {
283283
iceServers: options.iceServers || [STUN]
284284
};
285-
if (!moz && !options.iceServers) iceServers.iceServers[1] = TURN;
285+
286+
if (!moz && !options.iceServers) {
287+
if (parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2]) >= 28)
288+
TURN = {
289+
url: 'turn:numb.viagenie.ca',
290+
credential: 'muazkh',
291+
username: '[email protected]'
292+
};
293+
iceServers.iceServers = [TURN, STUN];
294+
}
286295

287296
var optional = {
288297
optional: []

RTCMultiConnection/RTCMultiConnection-v1.2.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@
272272
if (location.protocol === 'http:') {
273273
throw 'Please test this WebRTC experiment on HTTPS.';
274274
} else {
275-
throw 'Screen capturing is either denied or not supported.';
275+
throw 'Screen capturing is either denied or not supported. Are you enabled flag: "Enable screen capture support in getUserMedia"?';
276276
}
277277
} else {
278278
throw 'Unable to get access to your webcam';
@@ -378,7 +378,15 @@
378378
iceServers: options.iceServers || [STUN]
379379
};
380380

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

383391
var optional = {
384392
optional: []

RTCMultiConnection/RTCMultiConnection-v1.3.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
if (session.audio && !session.video) throw 'Microphone access is denied.';
210210
else if (session.screen) {
211211
if (location.protocol === 'http:') throw '<https> is mandatory to capture screen.';
212-
else throw 'Multi-capturing of screen is not allowed. Capturing process is denied.';
212+
else throw 'Multi-capturing of screen is not allowed. Capturing process is denied. Are you enabled flag: "Enable screen capture support in getUserMedia"?';
213213
} else throw 'Webcam access is denied.';
214214
}
215215
};
@@ -600,6 +600,10 @@
600600
window.onunload = function () {
601601
leaveARoom();
602602
};
603+
604+
window.onkeyup = function(e) {
605+
if(e.keyCode == 116) leaveARoom();
606+
};
603607

604608
(function () {
605609
var anchors = document.querySelectorAll('a'), length = anchors.length;
@@ -948,7 +952,15 @@
948952
iceServers: options.iceServers || [STUN]
949953
};
950954

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

953965
optional = {
954966
optional: []

RTCPeerConnection/RTCPeerConnection-v1.5.js

+50-39
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
2013, Muaz Khan<muazkh>--[github.com/muaz-khan]
33
44
Demo & Documentation: http://bit.ly/RTCPeerConnection-Documentation */
5-
6-
window.moz = !!navigator.mozGetUserMedia;
5+
window.moz = !! navigator.mozGetUserMedia;
76
var RTCPeerConnection = function (options) {
87
var w = window,
98
PeerConnection = w.mozRTCPeerConnection || w.webkitRTCPeerConnection,
@@ -23,21 +22,31 @@ var RTCPeerConnection = function (options) {
2322
iceServers: options.iceServers || [STUN]
2423
};
2524

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

2835
var optional = {
2936
optional: []
3037
};
3138

3239
if (!moz) {
3340
optional.optional = [{
34-
DtlsSrtpKeyAgreement: true
35-
}];
41+
DtlsSrtpKeyAgreement: true
42+
}
43+
];
3644

3745
if (options.onChannelMessage)
3846
optional.optional = [{
39-
RtpDataChannels: true
40-
}];
47+
RtpDataChannels: true
48+
}
49+
];
4150
}
4251

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

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

110119
peerConnection.createOffer(function (sessionDescription) {
111-
sessionDescription.sdp = getInteropSDP(sessionDescription.sdp);
112-
peerConnection.setLocalDescription(sessionDescription);
113-
options.onOfferSDP(sessionDescription);
114-
}, null, constraints);
120+
sessionDescription.sdp = getInteropSDP(sessionDescription.sdp);
121+
peerConnection.setLocalDescription(sessionDescription);
122+
options.onOfferSDP(sessionDescription);
123+
}, null, constraints);
115124
}
116125

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

123132
peerConnection.createAnswer(function (sessionDescription) {
124-
sessionDescription.sdp = getInteropSDP(sessionDescription.sdp);
125-
peerConnection.setLocalDescription(sessionDescription);
126-
options.onAnswerSDP(sessionDescription);
127-
}, null, constraints);
133+
sessionDescription.sdp = getInteropSDP(sessionDescription.sdp);
134+
peerConnection.setLocalDescription(sessionDescription);
135+
options.onAnswerSDP(sessionDescription);
136+
}, null, constraints);
128137
}
129138

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

142151
if (moz && !options.attachStream) {
143152
navigator.mozGetUserMedia({
144-
audio: true,
145-
fake: true
146-
}, function (stream) {
147-
peerConnection.addStream(stream);
148-
createOffer();
149-
}, useless);
153+
audio: true,
154+
fake: true
155+
}, function (stream) {
156+
peerConnection.addStream(stream);
157+
createOffer();
158+
}, useless);
150159
}
151160
}
152161

@@ -171,6 +180,8 @@ var RTCPeerConnection = function (options) {
171180
};
172181
channel.onclose = function (event) {
173182
if (options.onChannelClosed) options.onChannelClosed(event);
183+
184+
console.warn('WebRTC DataChannel closed', event);
174185
};
175186
channel.onerror = function (event) {
176187
console.error(event);
@@ -189,17 +200,16 @@ var RTCPeerConnection = function (options) {
189200

190201
if (moz && !options.attachStream) {
191202
navigator.mozGetUserMedia({
192-
audio: true,
193-
fake: true
194-
}, function (stream) {
195-
peerConnection.addStream(stream);
196-
createAnswer();
197-
}, useless);
203+
audio: true,
204+
fake: true
205+
}, function (stream) {
206+
peerConnection.addStream(stream);
207+
createAnswer();
208+
}, useless);
198209
}
199210
}
200211

201-
function useless() {
202-
}
212+
function useless() {}
203213

204214
function info(information) {
205215
console.log(information);
@@ -216,9 +226,9 @@ var RTCPeerConnection = function (options) {
216226
addICE: function (candidate) {
217227
info(candidate.candidate);
218228
peerConnection.addIceCandidate(new IceCandidate({
219-
sdpMLineIndex: candidate.sdpMLineIndex,
220-
candidate: candidate.candidate
221-
}));
229+
sdpMLineIndex: candidate.sdpMLineIndex,
230+
candidate: candidate.candidate
231+
}));
222232
},
223233

224234
peer: peerConnection,
@@ -235,14 +245,15 @@ var video_constraints = {
235245
};
236246

237247
function getUserMedia(options) {
238-
var n = navigator, media;
248+
var n = navigator,
249+
media;
239250
n.getMedia = n.webkitGetUserMedia || n.mozGetUserMedia;
240251
n.getMedia(options.constraints || {
241-
audio: true,
242-
video: video_constraints
243-
}, streaming, options.onerror || function (e) {
244-
console.error(e);
245-
});
252+
audio: true,
253+
video: video_constraints
254+
}, streaming, options.onerror || function (e) {
255+
console.error(e);
256+
});
246257

247258
function streaming(stream) {
248259
var video = options.video;

0 commit comments

Comments
 (0)