-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deferred emission of stream events received before emitting connect event #26
base: master
Are you sure you want to change the base?
Conversation
Another solution would be to delay these events until emitting the |
3dfff81
to
a67550c
Compare
a67550c
to
14b8213
Compare
I've implemented delaying the events until after the |
index.js
Outdated
debug('peer', id, 'is', (peer.connected ? '' : 'not ') + 'connected') | ||
if (peer.connected) { | ||
peer.removeListener('stream', onStreamWhileNotConnected) | ||
} else { |
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.
Rather return early than use else
.
index.js
Outdated
delayedStreams.forEach(function (stream) { | ||
peer.emit('stream', stream) | ||
}) | ||
delayedStreams = []; |
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 would rather clean up in line 75 together with the removal of the listener.
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.
If I move this to line 75, the array will be only freed in case of receiving a stream after connecting. Actually, this cleaning is incomplete, I should remove also the event listener to avoid memory leaks and nullify the array. I'll do in the following commit.
@perguth I changed the way of clean-up. Let me know your thoughts and thanks for the feedback. |
Fix #25
This is an initial draft of the solution. Since
simple-peer
has no support for lazy-adding streams, let's store the stream sent by the peer inside the peer.