test-ready
authorken <ken@kengrimes.com>
Mon, 10 Jul 2017 00:46:30 +0000 (00:46 +0000)
committerken <ken@kengrimes.com>
Mon, 10 Jul 2017 00:46:30 +0000 (00:46 +0000)
router.js

index 9d283f6..d8e9a8b 100644 (file)
--- a/router.js
+++ b/router.js
@@ -28,8 +28,6 @@ exports = {
   httpdRoot: undefined,
   bindJail: undefined,
 
-
-
   /** @func    
    * @summary Start main HTTP server
    * @desc    starts up an HTTP or HTTPS server used for routing
@@ -302,12 +300,19 @@ exports = {
    *          and responds to either the host or the client, or both.  Commands
    *          are whitespace separated strings.
    *            Commands:
+   *              Forward Payload to Client)
    *              < clientKey payload [header]
    *                Route 'payload' to the client identified by 'clientKey'.
    *                The optional 'header' argument is a stringified JSON object,
    *                which will be written to the HTTP response header
    *                  In case of multiple requests from a single client, the
    *                  oldest request will be serviced on arrival of message
+   *              Translate SDP and Forward to Client)
+   *              ^ clientKey sdp [header]
+   *                Route the JSON object 'sdp' to the client, after translating
+   *                for interop between browsers using planB or Unified.  Other
+   *                than the interop step, this is identical to the '<' command
+   *              Error)
    *              ! errorMessage errorCode [offendingMessage]
    *                Notify host that an error has occured, providing a message
    *                and error code.  'offendingMessage', if present, is the
@@ -321,6 +326,17 @@ exports = {
     argv = argv.slice(1)
     dlog(`Received host message from ${route.name}: ${command}`)
     switch (command) {
+    case '^':
+      if (argv.length < 2) {
+        dlog(`Malformed '${command}' command from ${route.host}`)
+        route.socket.send(`! "Insufficient arguments" 0 ${message}`)
+        break
+      }
+      argv[1] = JSON.parse(argv[1])
+      //TODO: interop step
+      argv[1] = JSON.stringify(argv[1])
+      //TODO: argv[1] = encryptForClient(argv[0], argv[1])
+      /* Fallthrough to '<' behavior after translating argv[1] */
     case '<':
       const response = route.pendingResponses.get(argv[0]).shift()
       if (!response)
@@ -342,6 +358,10 @@ exports = {
         argv[0] += `\nIn message: ${argv[2]}`
       console.log(`Error[${route.host}|${argv[1]}]:${argv[0]}`)
       break
+    default:
+      route.socket.send(`! "Unknown command '${command}'" 0 ${message}`)
+      dlog(`Host ${route.host} send unknown command: ${message}`)
+      break
     }
   },