Socketio-transport
socketio-transport will allow you to define request handlers (file, DB, ...) on the server side and to access them from the client side.
Installation
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.
Wrap the server side and define handlers
Require the server part of socketio-transport:
var 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 */ { ; }
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 = ; // The observable-store to wrap the handlersvar Store = ; // register socket.io and the handlers:;
Wrap the client side and query the handlers
Require the client part of socketio-transport
var SocketioTransport = Client;
Initialize it with the socket.io that you want to use:
var transport = io;
And you're now free to query your request handlers:
transport;
LICENSE
MIT