Skip to content

GertSallaerts/ws-transform-stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ws-transform-stream

A transformer for websocket streams.

Usage

yarn add @gertt/ws-transform-stream

or

npm install @gertt/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);

About

Node.JS websocket Transform stream implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published