childprocess-websocket

1.0.0 • Public • Published

childprocess-websocket

npm version Build Status

Turns ChildProcess IPC into Web Socket.

Background

Instead of learning/using different API for different communication channels, we should unite them into a single interface pattern, either MessagePort or WebSocket.

How to use

const childProcess = ChildProcess.fork('echo.js');
const webSocket = new ChildProcessWebSocket(childProcess);

webSocket.onmessage = event => {
  // Could be either a string or Buffer
  console.log(event.data);
};

webSocket.send('Hello, World!');

Instead of subscribing to onmessage, you can also subscribe using on('message', handler).

Note that when ChildProcessWebSocket is constructed, the IPC channel is already established. So we assume Web Socket is already opened, thus, no open event will be emitted.

Contributions

Like us? Star us.

Want to make it better? File us an issue.

Don't like something you see? Submit a pull request.

Readme

Keywords

none

Package Sidebar

Install

npm i childprocess-websocket

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

15.2 kB

Total Files

12

Last publish

Collaborators

  • compulim