1.1.4 • Published 9 years ago

mesh-socket-io-bus v1.1.4

Weekly downloads
1
License
ISC
Repository
-
Last release
9 years ago

Build Status Coverage Status Dependency Status

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 host
    • channel - channel to subscribe to. Default is action.
  • 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() {

});
1.1.4

9 years ago

1.1.3

9 years ago

1.1.2

9 years ago

1.1.0

9 years ago

1.0.18

9 years ago

1.0.17

9 years ago

1.0.15

9 years ago

1.0.14

9 years ago

1.0.13

9 years ago

1.0.11

9 years ago

1.0.10

9 years ago

1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.0

10 years ago