Developers
The timer app
All developer pages · From docs/timer.md in the release that is running.
The club timing app, served from https://pub-runners.com/timer/. It started as a Google Apps Script app and now runs on the pub-runners.com API. This page covers what still needs to change, what must stay as it is, and which API call each screen makes.
It is a static app in public/timer. The site serves index.html with a Content Security Policy that only allows requests to the site itself and map tiles from OpenStreetMap, so nothing can load from a CDN or another site.
What needs to change
Each item is its own pull request. The first three only touch public/timer. The last two need a server change first, which the club makes: ask, and do not work around them in the app.
In the app
- Install for offline use.
- Now: the app has a manifest, so it installs on a phone, but there is no service worker. It will not open without signal.
- Change: add a service worker in
public/timerthat caches the app's own files (index.html,app.js,app.css,map.js, the icons), and register it fromapp.js. Never cache/api/or/sanctum/responses: taps already wait in browser storage and resend. - Done when: an installed app opens in airplane mode, and taps made offline arrive once signal returns. If the server needs a new header or route for the worker, say so in the pull request.
- A QR code for the join link.
- Now: the timer shows the code and the link
/timer/?join=CODEas text. - Change: draw a QR code for that link on the code panel. Generate it on the phone with a script in
public/timer; the security policy blocks QR libraries from CDNs and QR image services. - Done when: pointing a phone camera at the timer's screen opens the join screen with the code filled in.
- Now: the timer shows the code and the link
- Keep PB alerts across a reload.
- Now: course PB alerts for the timer are held in memory (
S.pbs), so they vanish if the page reloads before someone taps "Got it". Milestone alerts already survive, because their dismissals are stored. - Change: keep unacknowledged PB alerts in
localStoragefor the run, and clear them when tapped. - Done when: a reload mid-run still shows every PB alert that has not been acknowledged.
- Now: course PB alerts for the timer are held in memory (
Needs the club first
- Renaming someone.
- Now: the only renaming is naming an unchecked runner (
assign). Wrong names are fixed in the admin. - Needs: a new event or endpoint on the server. Once it exists, add a "Rename" action to the timer.
- Now: the only renaming is naming an unchecked runner (
- Fixes after the results are built.
- Now: building the results closes the run to new events, so later fixes happen in the admin. The app says so.
- Needs: a server decision on whether timers may reopen a run. Until then, leave it as it is.
What must stay as it is
These are deliberate. A change that undoes one will not be merged.
- Who can time: timers are hosts signed in on pub-runners.com (
/timer/sign-in). Never put a shared code, key or password in a file. - Who can join: participants join tonight's run with the club's join code (
1901unless a host changes it), shown on the timer, or with the link/timer/?join=CODE. - Taps never wait: each tap is an event with a UUID made on the phone. It goes into a queue in browser storage and is resent until the server accepts it, and the screen updates straight away. Any signed-in host can tap, and taps from several phones all count.
- Names stay private: participants search with three or more letters and get ten matches at most. Only timers get the full roster.
- Routes come from the run: use
route_gpx_urlfrom the API, not files in the app. - Fixes are more events: use
void,self_reportedandassign, never an edit, so the full history is kept. - Results are built on the site: "Build the results" finalises the run, and a host checks and publishes them in the admin.
How each action maps to the API
| Screen action | API |
|---|---|
| Check in (participant) | POST /api/v1/participant/join, then POST /participant/checkin |
| Start my run (late) | POST /participant/start (server clock) |
| Not you? | DELETE /participant/checkin |
| Open tonight | POST /api/v1/timing/runs/tonight |
| Show the code | GET /timing/join-code |
| Change the code | PATCH /timing/join-code |
| Start, finish, end, back, late start | gun, finish, end, back and start events |
| Several finishing together | one finish with up to 10 runners |
| Unchecked runner, then name them | finish with no runners, then assign |
| Undo, remove, resume | void of the event in question |
| Fix a time | self_reported with the seconds |
| Swap times | void both finishes, then two finish events at the same moments, swapped |
| Change type | attendance (walked, pubbed, timed), or void it to make them a runner again |
| Build the results | POST /timing/runs/{id}/finalise (force for "ran, no time") |
| Live screen | GET /timing/runs/{id}/state every 4 seconds with If-None-Match |
Developing
See Contributing (CONTRIBUTING.md): change the files in public/timer, open a pull request, and try it on the pull request's preview site.