aprsworld / wsBroadcast

1 stars 1 forks source link

wsBroadcast

Broadcast data system. Receives data via TCP and broadcasts data via TCP, HTTP, and WebSockets.

Data is JSON object based with a global namespace. Objects can be made to expire, not-expire, or to be persistent between reboots.

Written in node.js.

Installation

To execute:

Command Line Options

Default Ports

Persistence

If --persist=[file] is specified on the command line, it will attempt to load and save persistent data to that file. Everytime it gets a persistent update it will attempt to write to the file and continue on happily if it cant. When the server receives a SIGHUP signal, it will attempt to write the latest changes to that file as well.

HTTP Interface

Any GET request to '/data/now.(json|dat)[/URI]' will return only the portion of the tree specified in the URI. A POST request to that will replace that portion with the data specified in JSON via POST. If in that POST the query parameter persist=true is sent, it will persist that data forever. Setting any value to null will prune that whole portion of the data.

Examples:

Copying data from one server to another

curl http://192.168.8.2:8888/data/now.json/webdisplay > /tmp/tmp.json && curl --data-binary @/tmp/tmp.json http://cam.aprsworld.com/data/now.json/webdisplay?persist=true && rm /tmp/tmp.json

Replace webdisplay with the URI of the data you want to copy and remove ?persist=true if you don't want the changes to be persistent.

Debugging / dumping data using wscat

If wscat is not on your system, install with:

Dump data with:

Using nc

Data Manager

This is the main object in this project. It basically just stores data that is to be broadcast and handles the broadcasting of this data to the servers which can be attached to it.

Servers

It currently has 3 server types; HTTP, Websockets (under the HTTP Server), and TCP. The base server type from which these are derived handles logging and other glue components. Each server takes in a configuration object which can be used to customize the instances of that server such as port and so on. If any empty object is passed in all defaults will be used.

At this time the data is always input and output as a JSON object. In the future this could be extended to allow other formats as well. The HTTP Server has the capability to do content negotiation and I believe WebSockets does as well, but the TCP Server would have to include a handshake in order to achieve this.

HTTP Server

The HTTP Server currently just serves static file content and the dynamic data (under '/.data/') as a fallback for AJAX HTTP Polling and for other uses. It also allows updates via HTTP POSTS as well.

The data is served in JSON with a mime-type of 'application/json', though in the future may do some content negotation. If there is a trailing '.txt' in the URI, the server will send a mime-type of 'text/plain' for compatibility with IE.

Currently the HTTP server defaults to running on port 8888.

WebSockets Server (Under the HTTP Server)

(DOCUMENTATION FOR PROTOCOL COMMING SOON)

For diagnostic and debugging the 'wscat' module is recommended. (npm install -g wscat)

TCP Server

The TCP Server allows updating the dynamic data via standard JSON messages. The protocol is a very simple input only terminated (The '\n' or 0x0A ASCII character) message passing system with each message being a JSON object with absolutely no handshake. It may be extended in the future.

Currently three TCP Servers are run, one on port 1229 which is for input, one on port 1230 for a single output of the current data, and one on port 1337 for continuous updates of the data.