mirror of https://github.com/kern/filepizza
Use the Twilio STUN/TURN service.
parent
5b2e85809f
commit
594fd54823
@ -0,0 +1,34 @@
|
|||||||
|
var twilio = require('twilio')
|
||||||
|
var winston = require('winston')
|
||||||
|
|
||||||
|
if (process.env.TWILIO_SID && process.env.TWILIO_TOKEN) {
|
||||||
|
var client = twilio(process.env.TWILIO_SID, process.env.TWILIO_TOKEN)
|
||||||
|
} else {
|
||||||
|
var client = null
|
||||||
|
}
|
||||||
|
|
||||||
|
var CACHE_LIFETIME = 5 * 60 * 1000 // 5 minutes
|
||||||
|
var cachedPromise = null
|
||||||
|
|
||||||
|
function clearCache() {
|
||||||
|
cachedPromise = null
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.getICEServers = function () {
|
||||||
|
if (client == null) return Promise.resolve({})
|
||||||
|
if (cachedPromise) return cachedPromise
|
||||||
|
|
||||||
|
cachedPromise = new Promise(function (resolve, reject) {
|
||||||
|
client.tokens.create({}, function(err, token) {
|
||||||
|
if (err) {
|
||||||
|
winston.error(err.message)
|
||||||
|
return resolve({})
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(clearCache, CACHE_LIFETIME)
|
||||||
|
resolve(token.ice_servers)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return cachedPromise
|
||||||
|
}
|
||||||
@ -1,3 +0,0 @@
|
|||||||
import WebTorrent from 'webtorrent'
|
|
||||||
|
|
||||||
export default new WebTorrent({})
|
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
import WebTorrent from 'webtorrent'
|
||||||
|
import socket from 'filepizza-socket'
|
||||||
|
|
||||||
|
export function getClient() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
socket.emit('rtcConfig', {}, (rtcConfig) => {
|
||||||
|
const client = new WebTorrent({ rtcConfig: rtcConfig })
|
||||||
|
resolve(client)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue