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

[ws] add options to transform client and server streams #1301

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
4 participants
@GertSallaerts
Copy link

commented Oct 23, 2018

A "light" alternative to #991. This simply allows us to pass in two options: createWsClientTransformStream and/or createWsServerTransformStream. Implementation of parsing and/or transforming the messages is left up to the user.

It's also a solution to #1203

@GertSallaerts GertSallaerts force-pushed the ambassify:feature/ws-transform-streams branch 2 times, most recently from fc73b3b to 6330fad Oct 23, 2018

@fanfare

This comment has been minimized.

Copy link

commented Feb 18, 2019

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.

@brickbite

This comment has been minimized.

Copy link

commented Feb 27, 2019

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.

@GertSallaerts

This comment has been minimized.

Copy link
Author

commented Feb 27, 2019

@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 node-http-proxy

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);
@brickbite

This comment has been minimized.

Copy link

commented Feb 28, 2019

@GertSallaerts thank you very much for the reference, I'll see if I can make anything of it

@fanfare

This comment has been minimized.

Copy link

commented Feb 28, 2019

Yes! can confirm it works. thanks so much @GertSallaerts

@GertSallaerts

This comment has been minimized.

Copy link
Author

commented Feb 28, 2019

@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.

@kindritskyiMax

This comment has been minimized.

Copy link

commented Apr 4, 2019

Hi, do you have any plans to merge this PR? This is quite a useful feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.