[ws] add options to transform client and server streams#1301
[ws] add options to transform client and server streams#1301GertSallaerts wants to merge 1 commit intohttp-party:masterfrom
Conversation
fc73b3b to
6330fad
Compare
6330fad to
0b04f18
Compare
|
Is there any progress with this? I'd really like to implement this in something I'm working on, but can't really figure out how to manipulate the frames after a connection has been established. |
|
hi @GertSallaerts, wondering if you have an example of the function that returns a duplex stream (and an example of the duplex stream implementation). I'm testing this locally and trying to get it to work, but figuring out streams at the moment. |
|
@brickbite the logic to set this up is not that straightforward so I created a separate repo for it. You can find it here: https://github.com/GertSallaerts/ws-transform-stream I've not had time to complete the documentation or test the code yet, but I hope it can help you in the right direction. It will probably be something along these lines for use with const http = require('http');
const { createProxyServer } = require('http-proxy');
const WsTransformStream = require('@gertt/ws-transform-stream');
const server = http.createServer();
const proxy = createProxyServer({});
function transform(message) {
return message.toUpperCase();
}
function createWsClientTransformStream(req) {
return WsTransformStream.fromUpgradeRequest(req, { transform });
};
server.on('upgrade', (req, socket, head) => {
proxy.ws(req, socket, head, {
/* ...yourOptions, */
createWsClientTransformStream,
});
});
server.listen(3000); |
|
@GertSallaerts thank you very much for the reference, I'll see if I can make anything of it |
|
Yes! can confirm it works. thanks so much @GertSallaerts |
|
@fanfare @brickbite I published it on NPM as well in case you guys are interested in using it as a library. You're welcome to report any issues or suggestions on the GitHub repo. |
|
Hi, do you have any plans to merge this PR? This is quite a useful feature. |
|
merge please |
A "light" alternative to #991. This simply allows us to pass in two options:
createWsClientTransformStreamand/orcreateWsServerTransformStream. Implementation of parsing and/or transforming the messages is left up to the user.It's also a solution to #1203