@gertt/ws-transform-stream

0.0.0 • Public • Published

ws-transform-stream

A transformer for websocket streams.

Usage

npm install --save @gertsallaerts/ws-transform-stream

In your code:

const WsTransformStream = require('@gertt/ws-transform-stream');

/**
 * Make all WS messages uppercase
 */
function transform(message) {
    return message.toUpperCase();
}

const transformer = new WsTransformStream({ transform });

// You'd typically get these when receiving a request on a webserver and needing
// to forward/proxy the WS elsewhere;
const clientWsSocket = ...;
const upstreamWsSocket = ...;

// pipe the sockets through the transformer to transform any messages going from
// client to upstream server
clientWsSocket.pipe(transformer).pipe(upstreamWsSocket);

Package Sidebar

Install

npm i @gertt/ws-transform-stream

Weekly Downloads

48

Version

0.0.0

License

MIT

Unpacked Size

11.6 kB

Total Files

8

Last publish

Collaborators

  • gertt