README.md

Valet

Realtime node.js + socket.io server in a box.

Valet is a simple server built on node.js and socket.io. You can deploy it locally with one command, or remotely with a few clicks. Clever namespaces allow you to use Valet for multiple projects simultaneously.

Deploying Valet to Nodejitsu

Pull down a local copy of Valet - this is the copy you'll be modifying and deploying.

cd /some/directory/
npm install valet

Edit the subdomain field in package.json. Your app will be served from your-subdomain.jit.su

Deploy your app:

jitsu deploy

Config files

Valet will look for a file called config.json in your root project directory. If it can't find one, it will use the one located in the valet root. If you want to name your amazon app zomething other than valet, you should copy the included config.json file and tweak it as needed.

Namespaces

Namespaces split clients into groups, to allow many projects to use a single Valet instance simultaneously.

Clients (frontends, devices, or even other servers) determine what namespaces they want to join by connecting to a specific URL. Multiple namespaces can be joined by calling connect multiple times (only one websocket connection will actually be used).

For example, to join the /temperature and /humidity namespaces, your client would have code that looks something like:

Valet extends socket.io's namespaces in a useful way: if you use more complex namespaces, your events and data will "bubble up". For example, data you send to a namespace like /buildings/123/rooms/456/temperature will be emitted on the following three namespaces:

This means that you can listen to /buildings/123/rooms/456/temperature to get events from temperature sensors in room 456, /buildings/123/temperature to get events from all of the temperature sensors in building 123, or /temperature to get events from all of the temperature sensors, everywhere.

Sending data to Valet

You can pass data to Valet by either sending a POST request to your Valet server, or by emitting a socket event called "post". For example, to send data from your terminal using CURL:

Note - if your client does not support sending an application/json, you can send the json as a string in the POST body called value

To send the same data using a socket is a two step process - first, you must connect to your Valet server on the root namespace. Then, emit an event called post containing the event, namespace, and data you would like to emit. For example:

In either case, an event called reading with data {temp:83.3826} will be emitted on the three namespaces described in the "Namespaces" section above.

Clients

Anything that can run socket.io can be a Valet client. Simply require socket.io on your client, connect on whatever namespaces you like, and listen for events.

Here is an example client that listens for temperature readings. To demonstrate the namespace "event bubbling" behavior described above, this example listens for events on the /buildings/123/temperature namespace, even though they will be sent to the server on the /buildings/123/rooms/456/temperature namespace.

Faq

Usually this is due to a port conflict - make sure you don't have any other instances of Valet running, or anything else on port 9200. You can also change the default port in the config.json file in the Valet root folder.