diff --git a/src/remote/peer-fetch.js b/src/remote/peer-fetch.js index 5c4b4f63..8ade9415 100644 --- a/src/remote/peer-fetch.js +++ b/src/remote/peer-fetch.js @@ -46,15 +46,27 @@ export class PeerFetch { // Handle incoming data (messages only since this is the signal sender) const peerFetch = this this._dataConnection.on('data', function (data) { - console.debug('Remote Peer Data message received (type %s): %s', + console.debug('Remote 11111 Peer Data message received (type %s): %s', typeof (data), data) // we expect data to be a response to a previously sent request message const response = data const ticket = peerFetch._nextTicketInLine console.debug(peerFetch, peerFetch._requestMap, ticket, response) + // const blah = { + // url: 'http://localhost:8778/?from=_dataConnection.on_data' + // } + // const msg = JSON.stringify(blah) + // const dc = peerFetch._dataConnection + // console.error('>>>>>>>>>>>>>>>>>> Sending msg', { dc, msg }) + // peerFetch._dataConnection.send(msg) // update request map entry with this response const pair = peerFetch._requestMap.get(ticket) - pair.response = response + if (pair) { + pair.response = response + } else { + console.error('No entry found in pending requestMap for ticket', + { ticket }) + } }) } @@ -110,7 +122,11 @@ export class PeerFetch { const requestMap = this._requestMap console.debug('Sending request to remote peer', { requestMap, ticket, request }) - this._dataConnection.send(jsonRequest) + try { + this._dataConnection.send(jsonRequest) + } catch (error) { + console.error('Error sending message via Peer DataConnection', { error }) + } } _processNextTicketInLine () { @@ -160,6 +176,7 @@ export class PeerFetch { return response } else { console.debug('Waiting for response', { ticket, request }) + // this._processNextTicketInLine() } timeElapsed = Date.now() - timerStart await sleep(1000) diff --git a/src/store/pnp.js b/src/store/pnp.js index 2ea1cf8c..fab508f0 100644 --- a/src/store/pnp.js +++ b/src/store/pnp.js @@ -225,7 +225,12 @@ function setPeerConnectionHandlers ({ state, commit, dispatch }, peerConnection) const peerFetch = new PeerFetch(peerConnection) console.debug('Peer DataConnection is now open. Creating PeerFetch wrapper.') commit(PEER_FETCH, peerFetch) - dispatch(PEER_AUTHENTICATE, peerConnection) + setTimeout(() => dispatch(PEER_AUTHENTICATE, peerConnection), 1000) + try { + peerConnection.send('HELLO from peerConnection.on_open') + } catch (error) { + console.error('Error sending message via webrtc datachannel', { error }) + } }) peerConnection.on('close', function () { @@ -342,7 +347,7 @@ const actions = { console.log('Connecting to remote peer', remotePeerId) commit(PEER_CONNECTING) const peerConnection = peer.connect(remotePeerId, { - reliable: true, serialization: 'raw' + label: 'http-proxy', reliable: true, serialization: 'raw' }) setPeerConnectionHandlers({ state, commit, dispatch }, peerConnection) },