WebSockets Radio
Universal publish/subscribe WebSockets API for JavaScript: a single tiny module both for server (NodeJS) and client.
Radio provides a tiny wrapper around client and server WebSocket objects, which has the same API for communication with another peer.
Usage
Both on client and server you have to work with Radio
instance, using the same API.
But first, you need to initialize Radio instance and pass a WebSocket to it.
Connect client to server:
; const ws = `http://localhost:12345`;const radio = ws;
Server usage (within ws
package):
;; const wss = port: 8080 ; wss;
Server/client API:
// Send any data to another peerradio; // Send and wait for response to this requestradio; // Listen for particular event data coming from another peerradio; // Listen and reply to a particular messageradio; // Re-initialize Radio with another WebSocket (for example, after WebSocket disconnects):radio;