The server tries to load each *.js file from the modules
folder with require(). Modules must export an init
function that gets called with an api
object from the server.
The *.html files are treated as riot.js tag files, they are compiled with riot and concatenated into a single block of JavaScript code that is returned when /riot-tags.js
is requested from the server.
##How they work Most of the "streaming" modules just run a shell command and capture, process and publish the standard output to a wsPubSub object that forwards the data through a WebSocket channel to the client. On the client each module can subscribe to one or more "channels". The first subscription starts the process so even if there are many clients connected, there will be only one process running for each stream.
I know that running a command and parsing its output is not very efficient, and I could get all the data by reading from the /proc
filesystem, but me being a mostly UI developer I started with the easy part and worked on the client side. Maybe in phase 2 of learning linux I'll change it to a "proper" implementation.
Runs the top
command as a separate process and captures its standard output then parses it and sends updates to the client.
Raspberry Pi specific: Runs cputmpstream.sh which prints out the temperature and voltage of the Pi.
Runs the nethogs
command as a separate process and captures its standard output then parses it and sends updates to the client.
Note: Nethogs might need to be installed manually.
Runs the iotop
command as a separate process and captures its standard output then parses it and sends updates to the client.
- Server module: diskfree.js
- Tag file: diskfree.html
Runs dfstream.sh which runs the df
command every 10 seconds.
- Server module: services.js
- Tag file: services.html
Runs servicesstream.sh which runs
service --status-all
every 60 seconds.
- Server module: commands.js
- Tag file: commands.html
This is a bit different from the other modules, this sends a list of commands that are registered and can be executed on the Pi. These can be configured in the commands module.
This is experimental! - Does NOT work on Android 4.2 default browser.
- Server module: webcam.js
- Tag file: webcam.html
This module does NOT directly stream the video through the same websocket channel. Instead when the 'stream' is started it starts mjpg-streamer which does the HTTP streaming (I'll post more about its configuration later). The view just includes an <img> tag that points to the HTTP stream.
I'm planning to use something like Paparazzo in the future, or use its code to process the mjpeg stream and actually stream images through websocket. I'm not sure if I should base64 encode it and just use the Data URI support, or open a second, binary websocket.