most.js W3C Messaging adapters
Create a most.js stream from a WebSocket (or SockJS, etc.), EventSource, MessagePort (or anything with the postMessage()
API), or Worker and get all the filtering, transforming, reducing, etc goodness:
var fromWebSocket = fromWebSocket; var socket1 = 'ws://localhost:8001';var socket2 = 'ws://localhost:8002'; // Merge 2 websockets into a single stream// When the merged stream ends, both socket1.close and socket2.close// will be called.var stream =
API
fromWebSocket
fromWebSocket(webSocket [, dispose]) -> Stream
Create a stream from a WebSocket. The stream will contain all messages received by the WebSocket from the time a consumer begins observing the stream (using observe
, .forEach
or .reduce
). The stream will end when the WebSocket closes, or will error if the WebSocket errors.
fromWebSocket
does not close the WebSocket automatically. You can pass-in a dispose
function if you want to close the socket when the stream ends or once all consumers of the stream have lost interest:
var stream = ;
toWebSocket
toWebSocket(stream, webSocket) -> Promise
Send all events from a stream to a WebSocket, and return a promise for the end of the stream.
If the WebSocket closes before the stream ends, the returned promise will fulfill if the WebSocket closes cleanly, or will reject if the WebSocket errors. If the stream ends before the WebSocket closes, the returned promise will fulfill if the stream ends cleanly, or will reject if the stream errors.
toWebSocket
does not close the WebSocket automatically. The creator of the WebSocket should close it.