X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fkiak.git;a=blobdiff_plain;f=main.js;h=321af8873c2ab3d5a2a683bac4ad8085be83b525;hp=9ef0b496a763f4765fa89ee4bd7d8487bdd158df;hb=5da8f7e044a781c15567b43ee9acc07444605015;hpb=44c1e3ad8fd1e594cceebb36a97e3b126b7d6188 diff --git a/main.js b/main.js index 9ef0b49..321af88 100644 --- 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 + } } })