-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Add readableObjectMode as an option for createWebSocketStream #185
Labels
Comments
How can we reproduce the issue? |
I'll try to create a minimal reproduction |
It seems that it's enough to set the socket's binary type to "arraybuffer" on the server, and then to send data as a buffer from the client. const WebSocket = require("ws");
const fastify = require("fastify")();
fastify.register(require("fastify-websocket"));
fastify.get("/", { websocket: true }, async (connection) => {
connection.socket.binaryType = "arraybuffer";
});
fastify.listen(3000, (err) => {
const ws = new WebSocket("ws://localhost:" + fastify.server.address().port);
ws.onopen = () => {
ws.send(Buffer.from("Hello!"));
};
}); |
This is actually an interesting problem! Would you like to send a PR to add this feature? |
Definitely! I'll create a PR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisites
🚀 Feature Proposal
Adding
readableObjectMode
as an option for fastify-websocket.I noticed that currently in the documentation, it says that fastify-websocket supports
objectMode
as an option for[ws](https://github.com/websockets/ws/)
, but objectMode is not listed in the ws options documentation.It seems reasonable to add readableObjectMode as an option to fastify-websocket as it is an option for
createWebSocketStream
and achieves a similar goal. It may also make sense to allow users to change other connection (duplex) options likereadableHighWaterMark
andwritableHighWaterMark
, but I haven't needed those options yet.Motivation
There is currently no way to set
readableObjectMode
and this can lead to a TypeError for certain WebSocket applications, specifically:That being said, this issue which led to the inclusion of
readableObjectMode
as an option forcreateWebSocketStream
suggests there are issues with objectMode and backpressure handling, and the option could be a footgun.This error also didn't occur when using
express-ws
so I wonder if it's related to how Fastify works as the issue also highlights a bug in Node.js core. I noticed thatexpress-ws
doesn't seem to call createWebSocketStream at all and so I'm curious why there is a difference in implementation and that might reflect if this feature is needed.Example
Then these options can be passed to
WebSocket.createWebSocketStream
The text was updated successfully, but these errors were encountered: