fixed null body for get headers
[henge/kiak.git] / host.js
diff --git a/host.js b/host.js
index e6600de..dd48d10 100644 (file)
--- a/host.js
+++ b/host.js
@@ -9,9 +9,10 @@ if ("WebSocket" in window) {
     }
     wsock.onmessage = (msg) => {
       /* Message is offer from client */
+      /* TODO: Determine which client ?? */
       console.log("Incoming connection " + msg)
 
-      /* State machine to parse offer */
+      /* TODO: State machine to parse offer */
 
       /* New Client Connection*/
       hpc = new RTCPeerConnection()
@@ -23,14 +24,16 @@ if ("WebSocket" in window) {
       }).then(() => {
         const hpk = getPublicKey()
         wsock.send({
-          cmd: '< sdp pubKey'
-          sdp: hpc.localDescription
+          cmd: '< sdp pubKey',
+          sdp: hpc.localDescription,
           pubKey: hpk
         })
         clients.push({
-          sdp: hpc.localDescription
+          hostsdp: hpc.localDescription,
+          clientsdp: hpc.remoteDescription,
           clientPubKey: msg.pubKey
         })
+
       })
     }
   })
@@ -40,3 +43,18 @@ else {
     document.body.innerHTML = 'Websockets not supported in your browser'
   })
 }
+/* TODO: duplicate in both client.js and host.jhs */
+function getPublicKey() {
+  /* Check local storage for public key */
+  if (window.localStorage.getItem('public-key') === undefined) {
+    /* If doesn't exist, generate public and private key pair, store in
+    local storage */
+    crypto.subtle.generateKey({name:'RSA-OAEP', length: 192}, true, ['encrypt', 'decrypt'])
+      .then((keyPair) => {
+        /* TODO: Do we need to store the private key as well? */
+        window.localStorage.setItem('public-key', keyPair.type.public.toString())
+      })
+  }
+    console.log(window.localStorage.getItem('public-key'))
+    return window.localStorage.getItem('public-key')
+}