messageevent-stream
v0.0.0
Published
Wrap a MessageEvent emiter object as a Node.js stream
Downloads
7
Maintainers
Readme
MessageEvent-stream
Wrap a MessageEvent emiter object as a Node.js stream
Wrap a MessageEvent
emiter object as a Node.js Duplex
stream.
This includes Server-sent events, Web sockets, Cross-document messaging
(postMessage()
), Channel messaging, Cross-worker/document messaging (including
Service Workers), Broadcast channels and WebRTC data channels. In case the
MessageEvent
emitter object is not writeable (like Server-sent events), it
will create a Readable
stream instead.
This module was inspired by https://github.com/maxogden/websocket-stream and https://github.com/DmitryMyadzelets/slip-stream/blob/master/tests/ws-stream.js, and based on https://github.com/piranna/ws-backpressure.
Install
npm install messageevent-stream
API
- ws: MessageEvent object to be wrapped
- options: options passed to the parent
Duplex
orReadable
stream class constructor- closeOnFinish: flag to emit
close
event after the writable stream emits thefinish
event
- closeOnFinish: flag to emit
By default, the returned stream will inherit from Readable
class. If the
wrapped MessageEvent emitter object is writable (has a send()
or
postMessage()
method), then a Duplex
stream object will be returned instead.