agora
dead simple websocket communication module.
Stream JSON data easily with events between clients and server. You can broadcast to all clients, or just one.
runs in node and in the browser with browserify!
It's basically a simple wrapper built around the awesome module emit.io
install
npm install agora
server example
var Server = require('agora').Server;
var server = new Server({
port: 8000
});
server.on('connection', function (conn) {
var id = conn.id;
var inStream = conn.inStream;
var outStream = conn.outStream;
inStream.on('addOne', function (data) {
server.emitTo(outStream, 'addResult', data += 1);
});
server.emitTo(outStream, 'ready', id);
});
setInterval(function () {
server.emit('serverTime', new Date());
}, 1000);
client example
var Client = require('agora').Client;
var client = new Client();
client.on('ready', function (id) {
client.id = id;
client.emit('addOne', 1);
});
client.on('addResult', function (data) {
var div = document.getElementById('#someDiv');
div.innerHTML = data;
setTimeout(function () {
client.emit('addOne', data);
}, 5000);
});
client.on('serverTime', function (date) {
console.log(date);
});
client.connect('ws://localhost:8000');
methods
var Signals = require('agora');
var server = new Signals.Server(opts)
Creates a new instance of a websocket server.
opts.port
| specify the port number int
var client = new Signals.Client()
Creates a new instance of a websocket client.
client.connect(address)
Connects to the websocket server at the provided address
| String.
license
MIT