ice candidate addition for host + client now works
[henge/kiak.git] / host.js
diff --git a/host.js b/host.js
index 3af3426..01c56a2 100644 (file)
--- a/host.js
+++ b/host.js
@@ -58,11 +58,12 @@ function handleNewClientConnection(offer) {
               ice: event.candidate,
               hostPubKey: hpk.n, /* TODO: do we need to send this? */
               clientPubKey: offer.pubKey,
-              iceCandidateAvailable: true
+              iceState: "a"
             }))
           }
           else {
             console.log('Host: Finished sending ICE candidates')
+            console.log(hpc)
           }
         }
         console.log('Host: Sending answer to Client')
@@ -91,8 +92,6 @@ function handleNewClientConnection(offer) {
     })
   })
 
-
-
 }
 
 function handleNewIceSubmission(msg) {
@@ -105,12 +104,18 @@ function handleNewIceSubmission(msg) {
 function handleIceRequest(msg) {
   console.log('Host: Handling ice candidate request')
   console.log(iceCandidates)
-  const hpc = clients.get(msg)
+  const hpc = clients.get(msg.pubKey)
   const iceCandidate = iceCandidates.pop()
   if (iceCandidate !== undefined) {
     wsock.send(iceCandidate)
   } else {
-    wsock.send(`{"cmd" : "< ice pubKey", "clientPubKey":"${msg.pubKey}", "iceCandidateAvailable": false}`)
+    if (hpc.iceGatheringState.localeCompare('gathering') === 0) {
+      wsock.send(`{"cmd" : "< ice pubKey", "clientPubKey":"${msg.pubKey}", "iceState": "g"}`)
+    }
+    else if (hpc.iceGatheringState.localeCompare('complete') === 0) {
+      wsock.send(`{"cmd" : "< ice pubKey", "clientPubKey":"${msg.pubKey}", "iceState": "c"}`)
+    }
+
   }
 
 }