rapport
A simple websocket wrapper that adds request/response functionality.
Features
- Callback and Promise support for requests
- Wraps node WS objects as well as the browser Websocket object
- Small footprint (7.4kb minified)
- Configurable promise implementation
- Configurable serialization functions
- Zero dependencies
Browser Usage
Simply add rapport.min.js
to your HTML page and start using it:
const Rapport = ;const ws = Rapport; ws; // Replying to a requestws; // Closes are resolved when onClose is called, with an optional timeoutws ; // Other functions are also wrapped:ws;ws;ws;
Node.js Usage
Install with npm install --save rapport
.
Requesting from clients with an existing socket
const Rapport = ;const wrappedSocket = Rapport; wrappedSocket ; wrappedSocket;
Responding to clients with an existing socket
const Rapport = ;const wrappedSocket = Rapport; wrappedSocket;
Creating a new client
const Rapport = ;const ws = Rapport; ws; // Replying to a requestws; // Closes are resolved when onClose is called, with an optional timeoutws ; // Other functions are also wrapped:ws;ws;ws;
Configuration Options
There are 6 configurable options for the Rapport library, with the following defaults:
;