[](https://travis-ci.org/mojo-js/mesh-socket.io) [](https://coveralls.io/r/mojo-js/mesh-socket.io
npm install mesh-socket-io-bus
  
Streams for socket.io. Also works with mesh.
#### Basic example
``javascript
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.
`javascript
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.
- optionshost
- - socket.io server hostchannel
- - channel to subscribe to. Default is action.bus
- - bus to pass remote calls to
`javascript`
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.
`javascript
// 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() {
});
``