Created
June 18, 2019 05:08
-
-
Save leopay/2fa9e0efc6f750db6c439018e01c621a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var express = require('express') | |
| var crypto = require('crypto') | |
| var app = express() | |
| var hmac = function (key, content) { | |
| var method = crypto.createHmac('sha1', key) | |
| method.setEncoding('base64') | |
| method.write(content) | |
| method.end() | |
| return method.read() | |
| } | |
| function handleIceRequest(req, resp) { | |
| var query = req.query | |
| var key = '4080218913' | |
| var time_to_live = 600 | |
| var timestamp = Math.floor(Date.now() / 1000) + time_to_live | |
| var turn_username = timestamp + ':ninefingers' | |
| var password = hmac(key, turn_username) | |
| resp.header("Access-Control-Allow-Origin", "*"); | |
| return resp.send({ | |
| iceServers: [ | |
| { | |
| urls: [ | |
| 'stun:10.78.115.215:3478', | |
| 'turn:10.78.115.215:3478' | |
| ], | |
| username: turn_username, | |
| credential: password | |
| } | |
| ] | |
| }) | |
| } | |
| app.get('/iceconfig', handleIceRequest) | |
| app.post('/iceconfig', handleIceRequest) | |
| app.listen('3033', function () { | |
| console.log('server started') | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment