Merge 300e94be5b
into 4b92b8a538
This commit is contained in:
commit
0d4349b1eb
|
@ -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,4 +1,5 @@
|
|||
node_modules/
|
||||
.DS_Store
|
||||
/.idea
|
||||
/.vscode
|
||||
.env
|
20
server.js
20
server.js
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue