Skip to content

Commit

Permalink
fix: issues with Safari and iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
ivelin committed Jan 25, 2020
1 parent 05932f3 commit 47f098c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
23 changes: 20 additions & 3 deletions src/remote/peer-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
})
}

Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions src/store/pnp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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)
},
Expand Down

0 comments on commit 47f098c

Please sign in to comment.