Avoid assigning objects to window.
This commit is contained in:
parent
62f08b5fac
commit
b90175760e
2 changed files with 17 additions and 20 deletions
16
README.md
16
README.md
|
@ -21,6 +21,7 @@ function getIPs(callback){
|
||||||
var RTCPeerConnection = window.RTCPeerConnection
|
var RTCPeerConnection = window.RTCPeerConnection
|
||||||
|| window.mozRTCPeerConnection
|
|| window.mozRTCPeerConnection
|
||||||
|| window.webkitRTCPeerConnection;
|
|| window.webkitRTCPeerConnection;
|
||||||
|
var useWebKit = !!window.webkitRTCPeerConnection;
|
||||||
|
|
||||||
//bypass naive webrtc blocking
|
//bypass naive webrtc blocking
|
||||||
if(!RTCPeerConnection){
|
if(!RTCPeerConnection){
|
||||||
|
@ -30,12 +31,10 @@ function getIPs(callback){
|
||||||
iframe.style.display = 'none';
|
iframe.style.display = 'none';
|
||||||
document.body.appendChild(iframe);
|
document.body.appendChild(iframe);
|
||||||
var win = iframe.contentWindow;
|
var win = iframe.contentWindow;
|
||||||
window.RTCPeerConnection = win.RTCPeerConnection;
|
RTCPeerConnection = win.RTCPeerConnection
|
||||||
window.mozRTCPeerConnection = win.mozRTCPeerConnection;
|
|| win.mozRTCPeerConnection
|
||||||
window.webkitRTCPeerConnection = win.webkitRTCPeerConnection;
|
|| win.webkitRTCPeerConnection;
|
||||||
RTCPeerConnection = window.RTCPeerConnection
|
useWebKit = !!win.webkitRTCPeerConnection;
|
||||||
|| window.mozRTCPeerConnection
|
|
||||||
|| window.webkitRTCPeerConnection;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//minimal requirements for data connection
|
//minimal requirements for data connection
|
||||||
|
@ -49,7 +48,7 @@ function getIPs(callback){
|
||||||
var servers = undefined;
|
var servers = undefined;
|
||||||
|
|
||||||
//add same stun server for chrome
|
//add same stun server for chrome
|
||||||
if(window.webkitRTCPeerConnection)
|
if(useWebKit)
|
||||||
servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
|
servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
|
||||||
|
|
||||||
//construct a new RTCPeerConnection
|
//construct a new RTCPeerConnection
|
||||||
|
@ -92,9 +91,8 @@ function getIPs(callback){
|
||||||
var lines = pc.localDescription.sdp.split('\n');
|
var lines = pc.localDescription.sdp.split('\n');
|
||||||
|
|
||||||
lines.forEach(function(line){
|
lines.forEach(function(line){
|
||||||
if (line.startsWith('a=candidate:')) {
|
if(line.startsWith('a=candidate:'))
|
||||||
handleCandidate(line);
|
handleCandidate(line);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
13
index.html
13
index.html
|
@ -28,6 +28,7 @@
|
||||||
var RTCPeerConnection = window.RTCPeerConnection
|
var RTCPeerConnection = window.RTCPeerConnection
|
||||||
|| window.mozRTCPeerConnection
|
|| window.mozRTCPeerConnection
|
||||||
|| window.webkitRTCPeerConnection;
|
|| window.webkitRTCPeerConnection;
|
||||||
|
var useWebKit = !!window.webkitRTCPeerConnection;
|
||||||
|
|
||||||
//bypass naive webrtc blocking
|
//bypass naive webrtc blocking
|
||||||
if(!RTCPeerConnection){
|
if(!RTCPeerConnection){
|
||||||
|
@ -37,12 +38,10 @@
|
||||||
iframe.style.display = 'none';
|
iframe.style.display = 'none';
|
||||||
document.body.appendChild(iframe);
|
document.body.appendChild(iframe);
|
||||||
var win = iframe.contentWindow;
|
var win = iframe.contentWindow;
|
||||||
window.RTCPeerConnection = win.RTCPeerConnection;
|
RTCPeerConnection = win.RTCPeerConnection
|
||||||
window.mozRTCPeerConnection = win.mozRTCPeerConnection;
|
|| win.mozRTCPeerConnection
|
||||||
window.webkitRTCPeerConnection = win.webkitRTCPeerConnection;
|
|| win.webkitRTCPeerConnection;
|
||||||
RTCPeerConnection = window.RTCPeerConnection
|
useWebKit = !!win.webkitRTCPeerConnection;
|
||||||
|| window.mozRTCPeerConnection
|
|
||||||
|| window.webkitRTCPeerConnection;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//minimal requirements for data connection
|
//minimal requirements for data connection
|
||||||
|
@ -56,7 +55,7 @@
|
||||||
var servers = undefined;
|
var servers = undefined;
|
||||||
|
|
||||||
//add same stun server for chrome
|
//add same stun server for chrome
|
||||||
if(window.webkitRTCPeerConnection)
|
if(useWebKit)
|
||||||
servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
|
servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
|
||||||
|
|
||||||
//construct a new RTCPeerConnection
|
//construct a new RTCPeerConnection
|
||||||
|
|
Loading…
Reference in a new issue