+
+ /* Handle all messages from host */
+ sock.on('message', (hostMessage) => {
+ hostMessage = JSON.parse(hostMessage)
+ response = newRoute.clients.get(hostMessage['clientPubKey'])
+
+ /* If the host response is a answer */
+ if (hostMessage['cmd'].localeCompare('< sdp pubKey') === 0) {
+ console.log('Server: Sending host answer to client')
+ response.writeHead(200, { 'Content-Type': 'application/json' })
+ response.write(JSON.stringify(hostMessage))
+ response.end()
+ }
+ 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']
+ /* 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')
+ }
+
+ })