socketio-transport will allow you to define request handlers on the server side and to access them from the client side.
socketio-transport will allow you to define request handlers (file, DB, ...) on the server side and to access them from the client side.
npm install socketio-transport
#How to use
socketio-transport has a client-side and a server-side part, just like socket.io which it's based upon. It'll just wrap socket.io to provide a nice abstraction to make requests and open channels from the client side.
Require the server part of socketio-transport:
var transport = require"socketio-transport"Server;
And define you request handlers:
var handlers =/*** payload is a JSON sent by the client* onData is the callback that will receive each update* onEnd will be called with the last update*/setIntervalonData;200;
Then register the socket.io that you want to use and add the handlers too. The handlers need to be wrapped in an observable-store, because they can be shared between several
transports and they will know when handlers are added/removed/updated if needed.
// the socket.iovar io = require"socket.io"listen8000;// The observable-store to wrap the handlersvar Store = require"observable-store";// register socket.io and the handlers:socketioTransportio handlers;
Require the client part of socketio-transport
var SocketioTransport = require"socketio-transport"Client;
Initialize it with the socket.io that you want to use:
var transport = ioconnect"";
And you're now free to query your request handlers:
transportlisten"test"// do something with dataconsole.logdata; // Date, triggered every 200ms;