X-Git-Url: https://git.kengrimes.com/?p=henge%2Fkiak.git;a=blobdiff_plain;f=host.js;h=3af3426d8040767e7e806a6cb3d4bc543c8196e7;hp=9b84f5c4d335ec63d9eb2e1e8f0e9bfdd7df012a;hb=01bded344986da59b5b34091b85979e116a85693;hpb=a64cde9da6eac0b1d9dae8828ae89d5845fd5908 diff --git a/host.js b/host.js index 9b84f5c..3af3426 100644 --- a/host.js +++ b/host.js @@ -52,8 +52,9 @@ function handleNewClientConnection(offer) { getPublicKey().then((hpk) => { hpc.onicecandidate = (event) => { if (event.candidate) { + console.log('Host: Allocating ice candidate for client') iceCandidates.push(JSON.stringify({ - cmd: '< ice pubKey', + cmd: "< ice pubKey", ice: event.candidate, hostPubKey: hpk.n, /* TODO: do we need to send this? */ clientPubKey: offer.pubKey, @@ -77,7 +78,9 @@ function handleNewClientConnection(offer) { dataChannel.onmessage = (msg) => { console.log(msg.data) } - dataChannel.send('Hi from the host') + dataChannel.onopen = () => { + dataChannel.send(`Hi ${offer.pubKey} -host`) + } } hpc.oniceconnectionstatechange = () => { console.log('iceConnectionState = ' + hpc.iceConnectionState) @@ -100,13 +103,14 @@ function handleNewIceSubmission(msg) { } function handleIceRequest(msg) { - console.log('Host: Sending ice candidate to client') + console.log('Host: Handling ice candidate request') + console.log(iceCandidates) const hpc = clients.get(msg) - const iceCandidates = iceCandidates.pop() + const iceCandidate = iceCandidates.pop() if (iceCandidate !== undefined) { wsock.send(iceCandidate) } else { - wsock.send('no ice candidates') + wsock.send(`{"cmd" : "< ice pubKey", "clientPubKey":"${msg.pubKey}", "iceCandidateAvailable": false}`) } } @@ -120,10 +124,10 @@ if ("WebSocket" in window) { wsock.onmessage = (serverMsg) => { /* msg is either offer or ice candidate or ice candidate request*/ - + /* What if data null? */ let msg = JSON.parse(serverMsg.data) - const clientID = msg.pubKey || msg + const clientID = msg.pubKey /* TODO: redo this trash */ if (clients.has(clientID)) {