-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing #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
- Loading branch information
Showing
18 changed files
with
780 additions
and
609 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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: [] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -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: [] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -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: [] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.'; | ||
} | ||
}; | ||
|
@@ -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; | ||
|
@@ -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: [] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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); | ||
|
@@ -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'); | ||
|
@@ -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() { | ||
|
@@ -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) { | ||
|
@@ -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); | ||
} | ||
} | ||
|
||
|
@@ -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); | ||
|
@@ -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); | ||
|
@@ -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, | ||
|
@@ -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; | ||
|
Oops, something went wrong.