A client library for SHET. It can be used in Node.js, or in web browsers using Socket.IO.
npm install shet-client
var shet = require("shet-client").connect();
This uses Socket.IO, so it's probably easiest to get that working first (see http://socket.io/#how-to-use).
Install as above, then use Browserify to generate a single library file:
browserify -r shet-client -o public/shet.js
Include this in your page, then add the something like this to the server:
# after "io = require('socket.io').listen(app)"
require("shet-client").listen_socket(io);
...and something like this to the client:
# after "var socket = io.connect(...);"
var shet = require("shet-client").connect(socket);
This creates a SHET client, that can be used exactly as in Node.
Rather than using callbacks for everything, this library uses Q to provide 'deferred values' or 'promises', as in the Twisted version.
Create a new client.
options
is an optional object that may contain the following keys:
host
: The host to connect to. Defaults to $SHET_HOST or localhost.port
: The port to connect to. Defaults to $SHET_PORT or 11235.ping_interval
: The interval in milliseconds for sending pings to the server. Defaults to 30,000. If 0, no pings are sent.
Create a new client connected to the given Socket.IO channel.
Accept connections on the given Socket.IO channel, and pass traffic to the SHET server (which is resolved as above).
Add an action. When the action is called, callback
will be called with the
appropriate arguments, and it's return value will be returned to the caller. If
callback
returns a Q promise, it will wait for this to resolve before
returning, as expected.
Add an event. This returns an object with a raise
attribute. Calling this
with any number of arguments raises the event with the given arguments.
Add a property. get_cb
should take no arguments and return the desired value
of the property. set_cb
should take a single argument, and set the property.
Watch an event. The callback will be called with the arguments of the event.
Call an action with some arguments. This returns a promise, which will resolve to the return value of the action.
Get a property. This returns a promise, which will resolve to the return value of the action.
Set a property to value
. This returns a promise, which will resolve when the
set completes.
- Examples
- Setting the root directory
- Removing properties/events/actions.
- Event added/removed events?
- Testing
MIT licensed; see LICENSE.
Built with CoffeeScript, Node.js, Socket.IO, Q, Browserify, recon, and Lazy.