if (routeName === '' || routeName === 'index.html')
- serveFile(opts['index'])
+ serveFile(opts['index'])
else if (routeName in opts['bindings']) {
let localPath = path.normalize(opts['bindings'][routeName].concat(path.sep + routePath.slice(1).join(path.sep)))
if (localPath.includes(opts['bindings'][routeName])) {
+
/* Client is INIT GET */
if (headerData === undefined) {
console.log('client init GET')
//TODO: if route.socket == undefined: have server delay this send until host connects
// (this happens when a client connects to an active route with no currently-online host)
}
- else if (headerData.localeCompare('ice-candidate-request') === 0){
+ else if (headerData.localeCompare('ice-candidate-request') === 0) {
console.log('Server: received ice-candidate-request from Client')
- let data = []
- request.on('data', (chunk) => {
- data.push(chunk)
- }).on('end', () => {
- data = Buffer.concat(data).toString();
- console.log('Sending ice-candidate-request to Host' + data)
- clients.set(data, response)
- route.socket.send(data)
- })
+ let pubKey = request.headers['x-client-pubkey']
+ clients.set(pubKey, response)
+ pubKey = '{ "pubKey": "' + pubKey + '" }'
+ route.socket.send(pubKey)
}
else if (headerData.localeCompare('ice-candidate-submission') === 0) {
console.log('Server: recieved ice-candidate-submission from Client')
request.on('data', (chunk) => {
data.push(chunk)
}).on('end', () => {
- console.log('Sending ice-candidate-submission to Host' + data)
+ console.log('Sending ice-candidate-submission to Host')
data = Buffer.concat(data).toString();
clients.set(JSON.parse(data)['pubKey'], response)
route.socket.send(data)
getport().then( (port) => {
newRoute.port = port
if (opts['no-tls'])
- newRoute.httpd = http.createServer()
+ newRoute.httpd = http.createServer()
else
- newRoute.httpd = https.createServer(router.httpsOpts)
+ newRoute.httpd = https.createServer(router.httpsOpts)
newRoute.httpd.listen(newRoute.port)
newRoute.wsd = new ws.Server( { server: newRoute.httpd } )
newRoute.wsd.on('connection', (sock) => {