client + server + host fixes
[henge/kiak.git] / client.js
index 85c139f..69ac81e 100644 (file)
--- a/client.js
+++ b/client.js
@@ -5,7 +5,7 @@ body.appendChild(root)
 document.body = body
 
 /* Poll the server. Send get request, wait for timeout, send another request.
-   Do this until...? */
+   Do this until...? Can be used for either reconnecting or waiting for answer*/
 function pollServerTimeout(url, data, resolve, reject) {
   console.log('Polling server with offer ' + data)
   const request = XMLHttpRequest()
@@ -17,7 +17,7 @@ function pollServerTimeout(url, data, resolve, reject) {
       resolve(request.response)
     }
     else if (request.status === 504) {
-      pollServerTimeout(url, resolve, reject)
+      pollServerTimeout(url, data, resolve, reject)
     }
     else {
       reject('server errored out with ' + request.status)
@@ -32,7 +32,8 @@ function pollServer(url, clientPubKey, func) {
     func(url, clientPubKey, resolve, reject )
   })
 }
-/* If https connection, should be already defined. If not https,*/
+
+/* TODO: duplicate in both client.js and host.js */
 function getPublicKey() {
   /* Check local storage for public key */
   if (window.localStorage.getItem('public-key') === undefined) {
@@ -65,8 +66,7 @@ cpc.createOffer().then((offer) => {
   /* Poll for answer */
   return pollServer(window.location, offer, pollServerTimeout)
 }).then((answer) => {
-  /* TODO: Extract sdp from answer ?*/
   console.log(answer)
-  /* State machine to parse answer */
+  /* TODO: State machine to parse answer */
   cpc.setRemoteDescription(answer.sdp)
 })