Boxxy is the application which powers https://live.12urenloop.be. It functionality can be divided into two big parts:
- Receive info and updates from
count-von-count - Serve this information, together with visualisations to the users
Install all dependencies using
npm install
Run the server with
node src/server.js
Boxxy provides a JavaScript API which facilitates writing visualisations.
If the boxxy module is in scope, the initialize call provides you with an object that has all further information and methods:
var boxxy = boxxy.initialize();
The boxxy object has a number of fields. These should be used in a read-only
way.
-
boxxy.circuitLengthis simply the length of the running track (in meters). -
boxxy.startTimeis a string containing the date the event started. -
boxxy.stationsholds an object with the stations. The stations are simply the bluetooth receivers positioned around the circuit.{ 1: { name: "station 1", id: "1", position: 0 }, ... }positionis the position of the station along the circuit (in meters). -
boxxy.teamsholds an object with all the teams and their current scores.{ 1:{ name: "Politeia", updated: "2013-03-22T22:22:59.971Z", id: "1", laps: 23, station: "3" }, ... }stationrefers to the ID of the station where the team was last seen. This means you can do something like:boxxy.stations[boxxy.teams["1"].station] -
boxxy.lapsholds an array with thenlatest laps. Thisncan be configured by changing the variableboxxy.maxLaps.[ { timestamp: "2013-03-22T22:30:23.867Z", team:"4", total: 28, id: "113", reason: null, count: 1 }, { timestamp: "2013-03-22T22:27:12.489Z", team: "3", total: 26, id: "104", reason: "Draag de Praeses bonusronde", count: 3 }, ... ]totalis the total amount of laps up to that point.countis the number of points assigned for the lap. This is usually one, except for bonus laps: in the case of the latter,reasoncan also be provided by boxxy.
The server will send .messages to the client using the Socket.IO library. There is no need to manually deal with these messages. Instead, the user should set callbacks in the boxxy object. All callbacks are optional (but you probably want to set at least one).
-
boxxy.onPutState = function(stateDelta) {}This function is called when the boxxy object receives the initial list of teams, stations and laps. This method is also called when there has been a connection interrupt. The
stateDeltaargument is best ignored in client code, as you can useboxxyinstead. -
boxxy.onAddLap = function(lap) {}This function is called whenever a team completes a lap. The
lapargument has more information regarding the lap. -
boxxy.onUpdatePosition = function(position) {}When the position of a team changes, this method is called. The
positionargument is an object that looks like this:{ timestamp: "2013-03-22T22:36:59.670Z", station: "4", team: "4" } -
boxxy.onUpdate = function() {}When any of the above callbacks are invocated, the
onUpdatefunction is also called. This is useful if you want to the same thing in every callback: just setonUpdateand leave the other callbacks unset.
-
boxxy.listen(uri)conects the client object to the server. You should call this after setting up all your callbacks. -
boxxy.teamsByScore()returns an array with all the teams fromboxxy.teams, ordered by score (total number of laps).
boxxy allows displaying a notification to the users. This can be done using:
curl -XPUT localhost:8080/state \
-H 'Content-Type: application/json' \
-u 'count-von-count:zeusisawesome' \
-d '{"notification": "This is a message"}'
At some point close to the end of the competition, we may want to freeze the displayed scores. This can be done using:
curl -XPUT localhost:8080/state \
-H 'Content-Type: application/json' \
-u 'count-von-count:zeusisawesome' \
-d '{"frozen": true}'
Updating the state with the teams field updated
curl -XPUT localhost:8080/state \
-H 'Content-Type: application/json' \
-u 'count-von-count:zeusisawesome' \
-d '{"teams":{"0":{"id":0, "name":"VTK", "laps":10, "updated":"2019-10-03T19:00:00:03"}}}'
Updating the number of laps for a certain team
curl -XPUT localhost:8080/lap \
-H 'Content-Type: application/json' \
-u 'count-von-count:zeusisawesome' \
-d '{"team":0, "total":10, "timestamp":"2019-10-03T19:00:00:03"}'
Unfreezing can be done by setting the same parameter to false.
