let dataChannel\r
let screenStream /* TODO: Remove if can access localStreams */\r
let tracks = []\r
-\r
+let hpk\r
\r
/* TODO: duplicate in both client.js and host.jhs */\r
function getPublicKey() {\r
})\r
}\r
\r
+function sendClientICE(clientPubKey, hostPubKey, iceCandidate) {\r
+ console.log('Host: Allocating ice candidate for client')\r
+ console.log(iceCandidate)\r
+ iceCandidates.push(JSON.stringify({\r
+ cmd: "< ice pubKey",\r
+ ice: iceCandidate,\r
+ hostPubKey: hostPubKey, /* TODO: do we need to send this? */\r
+ clientPubKey: clientPubKey,\r
+ iceState: "a"\r
+ }))\r
+}\r
+\r
function handleNewClientConnection(offer) {\r
/* New Client Connection*/\r
hpc = new RTCPeerConnection(conf)\r
return hpc.setLocalDescription(answer)\r
})\r
.then(() => {\r
- getPublicKey().then((hpk) => {\r
- hpc['hpk'] = hpk\r
- hpc.onicecandidate = (event) => {\r
- if (event.candidate) {\r
- console.log('Host: Allocating ice candidate for client')\r
- iceCandidates.push(JSON.stringify({\r
- cmd: "< ice pubKey",\r
- ice: event.candidate,\r
- hostPubKey: hpk.n, /* TODO: do we need to send this? */\r
- clientPubKey: offer.pubKey,\r
- iceState: "a"\r
- }))\r
- }\r
- else {\r
- console.log('Host: Finished sending ICE candidates')\r
- }\r
- }\r
- console.log('Host: Sending answer to Client ')\r
- wsock.send(JSON.stringify({\r
- cmd: '< sdp pubKey',\r
- sdp: hpc.localDescription,\r
- hostPubKey: hpk.n,\r
- clientPubKey: offer.pubKey\r
- }))\r
\r
+ hpc.onicecandidate = (event) => {\r
+ if (event.candidate) {\r
+ sendClientICE(offer.pubKey, hpk.n, event.candidate)\r
+ }\r
+ else {\r
+ console.log('Host: Finished allocating ICE candidates')\r
+ }\r
+ }\r
+ console.log('Host: Sending answer to Client ')\r
+ wsock.send(JSON.stringify({\r
+ cmd: '< sdp pubKey',\r
+ sdp: hpc.localDescription,\r
+ hostPubKey: hpk.n,\r
+ clientPubKey: offer.pubKey\r
+ }))\r
\r
- })\r
}).catch((err) => {\r
console.log(`error in host answer ${err}`)\r
})\r
dataChannel = evt.channel\r
dataChannel.onmessage = (msg) => {\r
let clientMessage = JSON.parse(msg.data)\r
- console.log(clientMessage)\r
+ console.log(`client message is ${clientMessage}`)\r
hpc.setRemoteDescription(clientMessage.sdp).then(() => {\r
console.log('should be streaming now')\r
})\r
}\r
dataChannel.onopen = () => {\r
+ /* If !screenStream, gUM */\r
screenStream.getTracks().forEach( (track) => {\r
hpc.addTrack(track, screenStream)\r
})\r
console.log(err);\r
}); // always check for errors at the end.\r
\r
+ getPublicKey()\r
+ .then((hpkVal) => {\r
+ hpk = hpkVal\r
+ })\r
wsock = new WebSocket(`${_strapp_protocol}://${window.location.hostname}:${_strapp_port}`)\r
wsock.onopen = () => {\r
console.log(`Strapped to ${_strapp_protocol}://${window.location.hostname}:${_strapp_port}`)\r
/* msg is either offer or ice candidate or ice candidate request*/\r
\r
/* What if data null? */\r
+ console.log(`serverMsg = ${serverMsg.data}`)\r
let msg = JSON.parse(serverMsg.data)\r
\r
const clientID = msg.pubKey\r