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

Remove stream method and ability to send a stream #875

Merged
merged 1 commit into from Dec 7, 2016

Conversation

lpinca
Copy link
Member

@lpinca lpinca commented Oct 28, 2016

I would like to discuss a little about this change to see if it makes sense or it is better to keep things as they are.

In my opinion the functionality offered by WebSocket.prototype.stream() does not belong to ws as it is something that should be done in the application and not in the library. The same applies for the ability to use a stream in WebSocket.prototype.send().

For example instead of

ws.send(stream, cb);

the developer could use something like this

(function read(readable) {
  const chunk = readable.read();

  if (chunk === null) {
    ws.send(chunk, { fin: true });
    return
  }

  ws.send(chunk, { fin: false }, (err) => {
    if (err) return handleError(err);

    read(readable);
  });
})(readable);

and queue/handle additional sends that can happen while reading from the stream.

@JoshuaWise
Copy link
Member

I completely agree.

How do you feel about implementing a proper DuplexStream interface to WebSocket? I know there's been a lot of talk about that.

@lpinca
Copy link
Member Author

lpinca commented Oct 28, 2016

Yeah making WebSocket a duplex stream would be the ideal solution.

WRT this particular change I wonder how many users depend on the removed features. I think not many but I may be wrong.

@lpinca
Copy link
Member Author

lpinca commented Nov 30, 2016

@websockets/admin any more opinions on this?

@lpinca
Copy link
Member Author

lpinca commented Dec 5, 2016

Another point in favor of this is the existence of modules like https://github.com/maxogden/websocket-stream which has 100k monthly downloads.

@3rd-Eden
Copy link
Member

3rd-Eden commented Dec 7, 2016

+1

@3rd-Eden 3rd-Eden merged commit b409ec9 into master Dec 7, 2016
@3rd-Eden 3rd-Eden deleted the remove/stream-method branch December 7, 2016 12:24
@lpinca lpinca mentioned this pull request Dec 12, 2016
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.

None yet

3 participants