getUserMedia problem in firefox
[henge/kiak.git] / host.js
diff --git a/host.js b/host.js
index 3af3426..81aabc6 100644 (file)
--- a/host.js
+++ b/host.js
@@ -1,4 +1,6 @@
 document.title = "Strapp.io Host"
+
+
 const conf = {"iceServers": [{ "urls": "stun:stun.1.google.com:19302" }] }
 const clients = new Map([])
 const iceCandidates = []
@@ -58,11 +60,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 +94,6 @@ function handleNewClientConnection(offer) {
     })
   })
 
-
-
 }
 
 function handleNewIceSubmission(msg) {
@@ -105,12 +106,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"}`)
+    }
+
   }
 
 }
@@ -149,6 +156,22 @@ if ("WebSocket" in window) {
         }
       }
     }
+    document.body.innerHTML = '<div>Choose options for client</div> <video autoplay></video>'
+
+    navigator.mediaDevices.getUserMedia({ video : { mediaSource: "screen", // whole screen sharing
+        // mediaSource: "window", // choose a window to share
+        // mediaSource: "application", // choose a window to share
+        width: {max: '1920'},
+        height: {max: '1080'},
+        frameRate: {max: '10'}} })
+    .then(function(mediaStream) {
+      let video = document.querySelector('video')
+      video.srcObject = mediaStream
+      video.onloadedmetadata = function(e) {
+        video.play()
+      }
+    })
+    .catch(function(err) { console.log(err); }); // always check for errors at the end.
   })
 }
 else {