Last active
September 27, 2021 19:04
-
-
Save phsultan/1e81d757c0f4f9078a7dce6381f0948f to your computer and use it in GitHub Desktop.
How to use Susbspace's TURN servers with Tokbox (TADHack 2021)
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
<html> | |
<head> | |
<title>Publish to Vonage, via Subspace TURN network</title> | |
<link href="css/app.css" rel="stylesheet" type="text/css"> | |
<script> | |
class turnSubspaceRTCPeerConnection extends RTCPeerConnection { | |
constructor(configuration) { | |
configuration.iceTransportPolicy = 'relay' | |
configuration.iceServers = [ | |
{ | |
"username":"*******:***************", | |
"credential":"*******************", | |
"url":"turn:globalturn.subspace.com:3478?transport=udp", | |
"urls":"turn:globalturn.subspace.com:3478?transport=udp" | |
}, | |
{ | |
"username":"*******:***************", | |
"credential":"*******************", | |
"url":"turn:globalturn.subspace.com:3478?transport=tcp", | |
"urls":"turn:globalturn.subspace.com:3478?transport=tcp" | |
} | |
] | |
super(configuration) | |
} | |
} | |
window.RTCPeerConnection = turnSubspaceRTCPeerConnection | |
</script> | |
<script src="https://static.opentok.com/v2/js/opentok.min.js"></script> | |
<script> | |
// replace these values with those generated in your TokBox Account | |
var apiKey = "*******"; | |
var sessionId = "*******" | |
var token = "*******"; | |
function handleError(error) { | |
if (error) { | |
alert(error.message); | |
} | |
} | |
initializeSession(); | |
function initializeSession() { | |
var publisher = OT.initPublisher('publisher', {}, | |
(error) => { | |
if (error) { | |
console.log('OT.initPublisher failed :', error) | |
return | |
} | |
}); | |
var session = OT.initSession(apiKey, sessionId); | |
session.connect(token, function (error) { | |
if (error) { | |
handleError(error); | |
} else { | |
console.log('Session connected :', session); | |
session.publish(publisher, function(error) { | |
if (error) { | |
alert(error.message); | |
} else { | |
console.log('Publish success'); | |
} | |
}); | |
} | |
}); | |
} | |
</script> | |
</head> | |
<body> | |
<h2>Publish to Vonage, via Subspace TURN network</h1> | |
<div id="publisher"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment