3.0.7 • Published 10 years ago

mesh-socket.io v3.0.7

Weekly downloads
4
License
ISC
Repository
github
Last release
10 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 operations 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 operations.

var io = require("socket.io");
var server = io(80);
server.on("connection", function(connection) {

  // note that "operation" is the channel that the client is
  // publishing / subscribing to
  connection.on("operation", function(operation) {

    // re-broadcast to other clients
    connection.broadcast.emit("operation", operation);
  });
});

db(options, bus)

creates a new socket.io streamer.

  • options
    • host - socket.io server host
    • channel - channel to subscribe to. Default is operation.
  • bus - bus to pass remote calls to
var iodb = io({
  host: "http://localhost",
  channel: "myOperationsChannel"
})

stream.Readable db(operationName, options)

Broadcasts a new operation. This can be anything.

stream.Readable db(tail, filter)

Tails a remote operation.

// tail all operations
db(mesh.op("tail")).on("data", function() {

});

// tail only insert operations
db(mesh.op("tail", { name: "insert" })).on("data", function() {

});

// tail only operations on people collection
db(mesh.op("tail", { collection: "people" })).on("data", function() {

});
3.0.7

10 years ago

3.0.5

10 years ago

3.0.4

10 years ago

3.0.3

10 years ago

3.0.2

10 years ago

3.0.1

10 years ago

3.0.0

10 years ago

2.0.3

10 years ago

2.0.2

10 years ago

1.0.2

10 years ago