X-Git-Url: https://git.kengrimes.com/?p=henge%2Fkiak.git;a=blobdiff_plain;f=router.js;h=0e8edf8bd725b68222553e127d84b1c52dc7f100;hp=8fe523585553cdd48516529dc99a5906a8c2382d;hb=25a33ef76e7fbb1647fcbac0bd2c3b2cb84ca2d2;hpb=68d808b03537c8cbe71d895f2ebc0bd9ab232bea diff --git a/router.js b/router.js index 8fe5235..0e8edf8 100644 --- a/router.js +++ b/router.js @@ -33,7 +33,7 @@ exports = { httpdRoot: undefined, bindJail: undefined, - /** @func + /** @func * @summary Start main HTTP server * @desc starts up an HTTP or HTTPS server used for routing * @arg {Object} conf - object containing configuration properties @@ -116,7 +116,7 @@ exports = { throw new Error(`${path} not found, ${routeName} not bound`) }, - /** @func + /** @func * @summary Router * @desc listens for http client requests and services routes/files * @arg {http.ClientRequest} request @@ -140,8 +140,8 @@ exports = { // that isn't just "give you a route if it's available" on visit /* else if (route.origin == (request.headers['x-forwarded-for'] || request.connection.remoteAddress)) - this.serveHost(response, route, htArgv) - else */ + this.serveHost(response, route, htArgv) */ + else this.serveClient(request, response, route) } /* If it's a valid routename that doesn't exist, make this client a host */ @@ -211,7 +211,7 @@ exports = { this.serveFile(response, bind.path) }, - /** @func + /** @func * @summary Serve a route to an http client * @desc routes may be bound to the filesystem, or to an outgoing host * @arg {http.ClientRequest} request - request from the client @@ -234,9 +234,9 @@ exports = { case 'client-sdp-offer': let data = '' if (pubKey) { + let data = request.headers['x-strapp-offer'] route.pendingResponses.addResponse(pubKey, response) - request.on('data', (chunk) => data += chunk) - request.on('end', () => route.socket.send(`${pubKey} ${type} ${data}`)) + route.socket.send(`${pubKey} ${type} ${data}`) } else { response.writeHead(401) @@ -249,7 +249,7 @@ exports = { } }, - /** @func + /** @func * @summary Create a new route for a host * @desc makes a new route for the given route name * @arg {string} routeName - name of the new route @@ -284,13 +284,14 @@ exports = { }) route.pendingResponses.addResponse = function (key, response_p) { let responses = this.get(key) || [] - this.set(key, responses.push(response_p)) + responses.push(response_p) + this.set(key, responses) } this.routes[routeName] = route this.serveHost(response, route, argv) }, - /** @func + /** @Func * @summary Serve a route to an authorized http host * @desc services host application to the client, establishing a socket * @arg {http.ServerResponse} response - response object to use @@ -379,7 +380,7 @@ exports = { } }, - /** @func + /** @func * @summary Serve a file to an http client after a request * @desc reads files from the system to be distributed to clients, and * buffers recently accessed files @@ -401,8 +402,8 @@ exports = { response.end() }) }, - - /** @func + + /** @func * @summary Synchronize Reading Multiple Files * @desc reads an array of files into an object, whose keys are the * input filenames, and values are the data read