SuperIO
Super Socket.io Client. A drop-in replacement for Automattic/socket.io-client.
Advantages
- RegExp Events.
- Backbone.js Style Event System.
- Additional Request-Response Flow.
- Configurable Agnostic (Non-Event) Messages.
Installation
SuperIO is released on npm
and can be installed using:
npm install superio --save
How to use
SuperIO can be used with Browserify and stand-alone and has the same interface as socket.io-client.
Browserify (or Node.js)
var socket = 'http://localhost';socket;
Stand-Alone Global
Build The Stand-Alone Yourself
npm install
- Install the build prerequisites.gulp build
- Build using Gulp. Result is indist
folder.npm test
- Run tests.
API
SuperIO(uri:String, options:Object): SuperIOSocket
Exposed as the superio
namespace in the standalone build, or the result
of calling require('superio')
.
The following options can be provided:
Name | Description | Default |
---|---|---|
header | Header applied to each message | null |
messageEvent | Agnostic message event name | message |
errorEvent | Req-Res Error event name (prefix) | error: |
io | Socket.IO options. See Socket.IO | null |
RegExp Events
Built-in support for Regular Expressions. Simply listen in on the expression.
Some Examples:
//Listen On All Transactionssocket; //Listen On All Transactions Except From Brokeragesocket; //Listen On Everything (Wildcard)socket;
Backbone.js Style Event System.
Featuring a "sane" on/off event interface with optional (but super-awesome) context support.
socket
The extra context support allows you to unbind based context. Its really handy when you want to destroy all listeners from an object during its destruction
// Removes just the `onTransaction` callback.socket; // Removes all 'transaction' callbacks.socket; // Removes the `onTransaction` callback for all events.socket; // Removes all callbacks for `myObject` for all events.socket; // Removes all callbacks on socket.socket;
Keeps the zombie objects at bay!
Request-Response
A simple req-res interface. Emit an event, catch it back and then stop listening.
- Same event used to listen for a response.
errorEvent
prefix used to listen for an error. Default is 'error:'.- Automatically unbinds and stops listening.
var joinMsg = roomId: 'westminster' ;socket;
The error prefix can be set as an option:
var superio = ; var socket = ; //Will Pass Error Events As: 'my_super_error:room:join'socket;
Agnostic (Non-Event) Messages.
When you just want to send a message through a single entry point.
var message = type: 'transaction' payload: ... ;socket;
This will emit a 'message' event to the server. Same as what Socket.io provides...
However, if you want to emit a different message or attach a header, you can easily pass those in as options.
var superio = ; var socket = ; //Will Add The Authentication Header Before Sendingsocket;
License
MIT