ice candidate addition for host + client now works
[henge/kiak.git] / main.js
diff --git a/main.js b/main.js
index 9ef0b49..321af88 100644 (file)
--- a/main.js
+++ b/main.js
@@ -138,22 +138,31 @@ const router = {
             }
             else if (hostMessage['cmd'].localeCompare('< ice pubKey') === 0){
               /* if the host response is an ice candidate */
-              console.log('Server: Sending host ice candidate')
-              let iceCandidateAvailable = hostMessage['iceCandidateAvailable']
+              console.log('Server: Handling host ICE message')
+              let iceState = hostMessage['iceState']              
               /* If there are any ice candidates, send them back */
-              if (iceCandidateAvailable) {
-                response.writeHead('200', {'x-strapp-type': 'ice-candidate-available'})
-                response.write(JSON.stringify(hostMessage))
-                response.end()
-              }
-              else { /* If not, srequest processed successfully, but there isnt anything yet*/
-                console.log('Server: No ice candidate available for response')
-                response.writeHead('204', {'x-strapp-type': 'ice-candidate-unavailable'})
-                response.end()
-              }
-            }
-            else {
-              console.log('unhandled message cmd from host')
+              switch(iceState) {
+                case "a":
+                  response.writeHead('200', {'x-strapp-type': 'ice-candidate-available'})
+                  response.write(JSON.stringify(hostMessage))
+                  response.end()
+                  break
+                case "g":
+                  console.log('Server: Host is still gathering candidates, keep trying')
+                  response.writeHead('200', {'x-strapp-type': 'ice-state-gathering'})
+                  response.write(JSON.stringify(hostMessage))
+                  response.end()
+                break
+                case "c":
+                  console.log('Server: Host has completed gathering candidates')
+                  response.writeHead('200', {'x-strapp-type': 'ice-state-complete'})
+                  response.write(JSON.stringify(hostMessage))
+                  response.end()
+                  break
+                default:
+                  console.log('unhandled iceState from host')
+                  break
+                }
             }
 
           })