fixed null body for get headers
[henge/kiak.git] / client.js
index 8989989..8813f55 100644 (file)
--- a/client.js
+++ b/client.js
@@ -7,11 +7,12 @@ document.body = body
 /* Poll the server. Send get request, wait for timeout, send another request.
    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)
+  console.log(`Polling server ${url} with`)
+  console.log(data)
   const request = new XMLHttpRequest()
-  request.open('GET', url)
+  request.open('GET', url, true)
   request.setRequestHeader('Content-Type', 'application/json' )
-  request.setRequestHeader('X-Strapp-Type', 'o' )
+  request.setRequestHeader('X-Strapp-Type', JSON.stringify(data))
   request.onreadystatechange = () => {
     if (request.status === 200) {
       console.log(request.response)
@@ -26,7 +27,7 @@ function pollServerTimeout(url, data, resolve, reject) {
     }
   }
   console.log(data)
-  request.send('data in stufff and stuff in data')
+  request.send()
 }
 
 /* TODO: All this does is wrap a function in a promise */
@@ -76,7 +77,8 @@ const cpc = new RTCPeerConnection()
 console.log('creating offer')
 cpc.createOffer().then((offer) => {
   return cpc.setLocalDescription(offer)
-}).then(() => {
+})
+  .then(() => {
   console.log('sessionDescriptionInit = ' + cpc.localDescription)
   getPublicKey().then((cpk) => {
     console.log('cpk is' + cpk)
@@ -95,3 +97,6 @@ cpc.createOffer().then((offer) => {
     console.log('error in sdp handshake: ' + err)
   })
 })
+  .catch((err) => {
+    console.log(err)
+  })