lrio
v1.2.1
Published
Minimalist websocket broadcast server and client
Downloads
79
Maintainers
Readme
lrio
Minimalist websocket broadcast server and browser client
Feature
- Broadcast messages using a dedicated channel
- Attach as many websocket server you want without collision
- Client for browserify
- Based on WebSocket-Node
Usage
npm install --save lrio
Server side
var http = require('http');
var lrio = require('lrio');
var server = http.createServer();
var A = lrio(server, 'myChannelA');
var B = lrio(server, 'myChannelB');
server.listen(8080);
// Broadcast message on myChannelA
A.broadcast({my:42})
// Broadcast message on myChannelB
B.broadcast({foo:'bar'})
// Other events :
A.on('join', function(client) {})
A.on('leave', function(client) {})
Notice that client
are WebSocketConnection instances
Client side (using browserify)
var lrio = require('lrio');
var A = lrio('myChannelA');
var B = lrio('myChannelB');
A.on('message', function(message) { console.log(message) })
B.on('message', function(message) { console.log(message) })
// Other events:
A.on('open', function() {})
A.on('close', function() {})
A.on('error', function() {})
A.close(); // Close websocket
A.connect(); // Re-connect (only if closed)
License
The MIT license • Novadiscovery