Created
January 30, 2023 21:29
-
-
Save ggarber/274825b38a18b4d08dc406d4ad0056bd to your computer and use it in GitHub Desktop.
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
(function() { | |
var origPeerConnection = window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection; | |
if (origPeerConnection) { | |
var newPeerConnection = function(config, constraints) { | |
console.log('PeerConnection created with config', config); | |
config.iceServers[1].urls = [ 'turns:turn.streamyard.com:443?transport=tcp']; | |
config.iceTransportPolicy = 'relay'; | |
// Add here the specific logic you need | |
// You can see some examples for specific use cases in the next sections of this document | |
const pc = new origPeerConnection(config, constraints); | |
return pc; | |
}; | |
['RTCPeerConnection', 'webkitRTCPeerConnection', 'mozRTCPeerConnection'].forEach(function(obj) { | |
// Override objects if they exist in the window object | |
if (window.hasOwnProperty(obj)) { | |
window[obj] = newPeerConnection; | |
// Copy the static methods (generateCertificate in this case) | |
Object.keys(origPeerConnection).forEach((x) => { | |
window[obj][x] = origPeerConnection[x]; | |
}); | |
window[obj].prototype = origPeerConnection.prototype; | |
} | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment