Skip to content

Commit

Permalink
rtcConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
feross committed Mar 24, 2021
1 parent 0bb1612 commit d0a4620
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
8 changes: 3 additions & 5 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,13 @@ function getRtcConfig (cb) {
if (err || res.statusCode !== 200) {
cb(new Error('Could not get WebRTC config from server. Using default (without TURN).'))
} else {
let rtcConfig
try {
rtcConfig = JSON.parse(data)
data = JSON.parse(data)
} catch (err) {
return cb(new Error('Got invalid WebRTC config from server: ' + data))
}
delete rtcConfig.comment
debug('got rtc config: %o', rtcConfig)
cb(null, rtcConfig)
debug('got rtc config: %o', data.rtcConfig)
cb(null, data.rtcConfig)
}
})
}
Expand Down
39 changes: 22 additions & 17 deletions secret/index-sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@ exports.rollbar = {
accessToken: 'TODO'
}

exports.iceServers = [
{
urls: [
'stun:stun.l.google.com:19302',
'stun:global.stun.twilio.com:3478'
]
},
{
urls: [
'turn:TODO:443?transport=udp',
'turn:TODO:443?transport=tcp',
'turns:TODO:443?transport=tcp'
],
username: 'TODO',
credential: 'TODO'
}
]
exports.rtcConfig = {
iceServers: [
{
urls: [
'stun:stun.l.google.com:19302',
'stun:global.stun.twilio.com:3478'
]
},
{
urls: [
'turn:TODO:443?transport=udp',
'turn:TODO:443?transport=tcp',
'turns:TODO:443?transport=tcp'
],
username: 'TODO',
credential: 'TODO'
}
],
sdpSemantics: 'unified-plan',
bundlePolicy: 'max-bundle',
iceCandidatePoolsize: 1
}
6 changes: 3 additions & 3 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ app.get('/__rtcConfig__', cors({
}
}), function (req, res) {
// console.log('referer:', req.headers.referer, 'user-agent:', req.headers['user-agent'])
const iceServers = secret.iceServers
const rtcConfig = secret.rtcConfig

if (!iceServers) return res.status(404).send({ iceServers: [] })
if (!rtcConfig) return res.status(404).send({ rtcConfig: {} })
res.send({
comment: 'WARNING: This is *NOT* a public endpoint. Do not depend on it in your app',
iceServers: iceServers
rtcConfig: rtcConfig
})
})

Expand Down

0 comments on commit d0a4620

Please sign in to comment.