mesh-socket-io-bus
v1.1.4
Published
[![Build Status](https://travis-ci.org/mojo-js/mesh-socket.io.svg)](https://travis-ci.org/mojo-js/mesh-socket.io) [![Coverage Status](https://coveralls.io/repos/mojo-js/mesh-socket.io/badge.svg?branch=master)](https://coveralls.io/r/mojo-js/mesh-socket.io
Downloads
35
Readme
Streams for socket.io. Also works with mesh.
Basic example
var mesh = require("mesh");
var loki = require("mesh-loki");
var io = require("mesh-socket.io");
var bus = mesh.tailable(loki());
// setup socket io - take all remote ops and pass
// to the bus
var iobus = mesh.reject("load", io({
host: "http://localhost"
}, bus));
// pipe all actions on bus to socket.io
bus(mesh.op("tail")).pipe(mesh.open(iobus));
// insert data into the DB. Should get broadcasted
// to socket.io
bus(mesh.op("insert", {
collection: "people"
data: {
name: "Shrek"
}
}));
server configuration
Server configuration is pretty easy to setup. Just re-broadcast incomming actions.
var io = require("socket.io");
var server = io(80);
server.on("connection", function(connection) {
// note that "action" is the channel that the client is
// publishing / subscribing to
connection.on("action", function(action) {
// re-broadcast to other clients
connection.broadcast.emit("action", action);
});
});
db(options, bus)
creates a new socket.io streamer.
options
host
- socket.io server hostchannel
- channel to subscribe to. Default isaction
.
bus
- bus to pass remote calls to
var iodb = io({
host: "http://localhost",
channel: "myactionsChannel"
})
stream.Readable db(actionName, options)
Broadcasts a new action. This can be anything.
stream.Readable db(tail, filter)
Tails a remote action.
// tail all actions
db(mesh.op("tail")).on("data", function() {
});
// tail only insert actions
db(mesh.op("tail", { name: "insert" })).on("data", function() {
});
// tail only actions on people collection
db(mesh.op("tail", { collection: "people" })).on("data", function() {
});