/* 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)
}
}
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 */
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)
console.log('error in sdp handshake: ' + err)
})
})
+ .catch((err) => {
+ console.log(err)
+ })
const route = router.routes[routeName]
/* Client is INIT GET */
- if (request.headers['x-strapp-type'] !== 'o') {
+ if (request.headers['x-strapp-type'] == undefined) {
console.log('client init GET')
response.writeHead(200, { 'Content-Type': 'text/html' })
response.write(`${router.skelPage[0]}${router.clientJS}${router.skelPage[1]}`)
// (this happens when a client connects to an active route with no currently-online host)
}
else { /* Client sent offer, waiting for answer */
- console.log('client offer/answer GET')
- //route.socket.send(JSON.parse(body.join('')))
+ console.log(JSON.parse(request.headers['x-strapp-type']))
route.socket.on('message', (hostResponse) => {
console.log(hostResponse)
})