Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

delapuente
Copy link

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.

@delapuente
Copy link
Author

delapuente commented Sep 12, 2017

Another solution would be to delay these events until emitting the peer event. What do you think @mafintosh ?

@delapuente
Copy link
Author

delapuente commented Sep 26, 2017

I've implemented delaying the events until after the peer event. What do you think, @mafintosh ?

index.js Outdated
debug('peer', id, 'is', (peer.connected ? '' : 'not ') + 'connected')
if (peer.connected) {
peer.removeListener('stream', onStreamWhileNotConnected)
} else {
Copy link
Collaborator

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 = [];
Copy link
Collaborator

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.

Copy link
Author

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.

@delapuente
Copy link
Author

delapuente commented Oct 26, 2017

@perguth I changed the way of clean-up. Let me know your thoughts and thanks for the feedback.

@delapuente delapuente changed the title Initial draft for supporting streams Deferred emission of stream events received before emitting connect event Oct 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants