-
Notifications
You must be signed in to change notification settings - Fork 93
A few BUGFIXES and new tests to cover those scenarios #54
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome PR @michaelfakhri, thank you for adding tests in. Made a couple of comments, would be great to have those addressed for the merge
listener.close = (callback) => { | ||
if (!callback) { | ||
callback = function noop () {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's replace this by a more simpler: callback = callback || () => {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
}, 100) | ||
} | ||
listener.getAddrs = (callback) => { | ||
process.nextTick(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not available in the browser, should use setImmediate instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -71,3 +71,74 @@ describe('dial', () => { | |||
// TODO IPv6 not supported yet | |||
}) | |||
}) | |||
describe('complex dial scenarios', () => { | |||
let ws1, ws2, listenerToClose |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you using standard
for linting? This fails linting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, everything was good using gulp lint on my machine and on travis. I used npm run lint the second time round and it was still fine, should I have used something else?
@@ -58,7 +57,7 @@ function WebRTCStar () { | |||
channel.on('signal', function (signal) { | |||
sioClient.emit('ss-handshake', { | |||
intentId: intentId, | |||
srcMultiaddr: maSelf.toString(), | |||
srcMultiaddr: listeners[Object.keys(listeners)[0]].ma.toString(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will make it fail if more than one listener is added. Can you add a test for multiple listeners?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also added two tests earlier that test multiple listeners connected to the same signalling server but are listening on different addresses. The code here simply follows the same criteria for picking the sioClient. Nothing weird going on but the code previously attached a random address to the signalling which is weird. In a multiple signalling server scenario, that maSelf code could fail on server and client side.
@@ -116,11 +115,11 @@ function WebRTCStar () { | |||
if (!callback) { | |||
callback = function noop () {} | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's replace this by a more simpler: callback = callback || () => {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if (!callback) { | ||
callback = function noop () {} | ||
} | ||
callback = callback || function () {} | ||
|
||
const intentId = (~~(Math.random() * 1e9)).toString(36) + Date.now() | ||
const sioClient = listeners[Object.keys(listeners)[0]].io |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@diasdavid I think the criteria for picking the sioClient here is not quite right, since it should be picking the signalling that we know the other peer is connected to (from the ma). This method just picks the first signalling server available and sends the offer without taking into account that peer might not be connected to that specific server. (Keeping in mind this only a problem in multiple signalling server scenario)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right @michaelfakhri, the picking of the 'right signalling server' wasn't added because we always had only one, but we should support multiple nevertheless.
Would you like to add that + a test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah sure, perhaps I might also attempt to decouple the listeners from the signalling servers in the process.
note to self 1: simple-peer 6.1.3 breaks libp2p webrtc transport (something to do with onSuccess callback), 6.1.0 work just fine so I used npm shrinkwrap to get tests passing by forcing simple peer to 6.1.0 |
Interesting note, thanks for catching that @michaelfakhri, will check how to update properly :) |
@michaelfakhri found the issue, the 'Fallback' option in simple-peer is expecting an interface that |
@michaelfakhri could you rebase master onto your PR? I've fixed the |
@diasdavid Thanks for looking into it and fixing it! This is now ready for review / merge. I attempted a rebase but did something wrong and ended up bringing in all the commits into the branch instead of rebasing but thats easily fixable using a squash merge at the end. I have seen two issues (not related to this PR though) that might need attention / investigation:
|
Continued here: #89 |
Here is a summary of all the changes:
Part of this PR addresses Websocket stays connected even after webrtc-star listener is closed #51
EDIT: This PR also adds support for handling multiple signalling servers
Let me know if you need me to make any changes.