X-Git-Url: https://git.kengrimes.com/?p=henge%2Fkiak.git;a=blobdiff_plain;f=main.js;h=9ef0b496a763f4765fa89ee4bd7d8487bdd158df;hp=a5b105b183ce9c5ce32c9e4899382655c21ddf55;hb=01bded344986da59b5b34091b85979e116a85693;hpb=a64cde9da6eac0b1d9dae8828ae89d5845fd5908 diff --git a/main.js b/main.js index a5b105b..9ef0b49 100644 --- a/main.js +++ b/main.js @@ -45,7 +45,7 @@ const router = { 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])) { @@ -68,6 +68,7 @@ const router = { + /* Client is INIT GET */ if (headerData === undefined) { console.log('client init GET') @@ -77,17 +78,12 @@ const router = { //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') @@ -95,7 +91,7 @@ const router = { 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) @@ -119,9 +115,9 @@ const router = { 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) => {