node icon indicating copy to clipboard operation
node copied to clipboard

could you expose internal APIs of WebSocket such as WebsocketFrameSend to user?

Open navegador5 opened this issue 1 year ago • 4 comments

What is the problem this feature will solve?

expose more APIs of websocket module:

const value = Buffer.from(data);
const frame = new WebsocketFrameSend(value);
const buffer = frame.createFrame(opcodes.BINARY);

What is the feature you are proposing to solve the problem?

expose more APIs of websocket module:

const value = Buffer.from(data);
const frame = new WebsocketFrameSend(value);
const buffer = frame.createFrame(opcodes.BINARY);

What alternatives have you considered?

No response

navegador5 avatar May 08 '24 05:05 navegador5

Can you explain your use case in more detail?

fahrradflucht avatar May 08 '24 20:05 fahrradflucht

As @fahrradflucht said, for a feature to be added to Node.js, there needs to be a use case, do you have one?

Thank you!

avivkeller avatar May 08 '24 23:05 avivkeller

in one of my project: the equipment(work as websocket client, most of them using nodejs) need to send msg(short but frequentlty) to some upstream-servers . unfortunately, the upstream-servers NOT under our control. and some of them NOT obey the standard-websocket-protocol(they do a private implement), so need the client to send some specical low-level ws-frame to them.

navegador5 avatar May 09 '24 09:05 navegador5

@navegador5 see https://github.com/websockets/ws/blob/ddfe4a804d79e7788ab136290e609f91cf68423f/lib/sender.js#L49-L70. It is not documented due to permessage-deflate constraints.

You can use it like this

const { Sender } = require('ws'); // or import { Sender } from 'ws';

const data = Buffer.alloc(256);

const buffers = Sender.frame(data, { opcode: 2 });
const frame = Buffer.concat(buffers);

lpinca avatar May 23 '24 17:05 lpinca