This commit is contained in:
Zubin Gao 2020-06-16 21:15:09 +02:00 committed by GitHub
commit 0d4349b1eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

9
.env.template vendored
View File

@ -4,3 +4,12 @@
TWILIO_ACCOUNT_SID=YourAccountSIDHere
LOCAL_AUTH_TOKEN=YourAuthTokenHere
# Or use your own STUN/TURN server
# It's a comma-separated list
# Example for Google's no credential ICE server:
# ICE_SERVER_URLS=stun.l.google.com:19302,stun1.l.google.com:19302,stun2.l.google.com:19302,stun3.l.google.com:19302,stun4.l.google.com:19302
ICE_SERVER_URLS=
ICE_SERVER_USERNAME=
ICE_SERVER_CREDENTIAL=
ICE_SERVER_CREDENTIALTYPE=

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
node_modules/
.DS_Store
/.idea
/.vscode
.env

View File

@ -5,7 +5,21 @@ var twillioAuthToken =
process.env.HEROKU_AUTH_TOKEN || process.env.LOCAL_AUTH_TOKEN;
var twillioAccountSID =
process.env.HEROKU_TWILLIO_SID || process.env.LOCAL_TWILLIO_SID;
var twilio = require("twilio")(twillioAccountSID, twillioAuthToken);
var iceServer =
process.env.ICE_SERVER_URLS && process.env.ICE_SERVER_URLS.length > 0
? {
urls: process.env.ICE_SERVER_URLS.split(",").map((s) => s.trim()),
username: process.env.ICE_SERVER_USERNAME,
credential: process.env.ICE_SERVER_CREDENTIAL,
credentialType: process.env.ICE_SERVER_CREDENTIALTYPE,
}
: undefined;
var twilio = iceServer
? undefined
: require("twilio")(twillioAccountSID, twillioAuthToken);
var express = require("express");
var app = express();
var http = require("http").createServer(app);
@ -96,6 +110,10 @@ io.on("connection", function (socket) {
// token to get ephemeral credentials to use the TURN server.
socket.on("token", function (room) {
logIt("Received token request", room);
if (iceServer) {
socket.emit("token", { iceServers: [iceServer] });
return;
}
twilio.tokens.create(function (err, response) {
if (err) {
logIt(err, room);