wtg / shuttletracker

🚐 Shuttle tracking for RPI.
https://shuttles.rpi.edu
GNU Affero General Public License v3.0
46 stars 53 forks source link

Push vehicle locations over WebSocket #231

Closed kochman closed 5 years ago

kochman commented 5 years ago

Clients used to poll /updates every few seconds to get vehicle locations. Now they are pushed over the Fusion WebSocket to clients. This decreases the amount of data transferred and also decreases the amount of latency between Shuttle Tracker receiving a location update and clients showing the new update. Client maps are now updated almost instantly as Shuttle Tracker receives vehicle positions from iTrak.

On the server, this is implemented by adding a trigger to the locations table that is fired whenever the updater inserts a vehicle location. It sends a notification that a subscriber (i.e. LocationService) picks up, and then the location is retrieved from the database and put into a channel for Fusion manager to push out to connected clients. When a new client subscribes, the most recent location for each vehicle is pushed out to it.

On the client, vehicle locations are now stored as members of vehicles instead of separately. Every 30 seconds, the client hides vehicles from the map if the last recorded movement was more than five minutes in the past.

Since Fusion is now an integral part of Shuttle Tracker, a "reconnecting" message is displayed in the top bar if Fusion becomes disconnected. The message disappears when Fusion reconnects.

Additionally, the ETA message animations have been tweaked and I think they're nicer now. Travis will fail the build if package.json and package-lock.json are not in sync.

Resolves #58.

codecov[bot] commented 5 years ago

Codecov Report

Merging #231 into master will increase coverage by 0.35%. The diff coverage is 48.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #231      +/-   ##
==========================================
+ Coverage   37.02%   37.37%   +0.35%     
==========================================
  Files          17       17              
  Lines        1453     1549      +96     
==========================================
+ Hits          538      579      +41     
- Misses        857      906      +49     
- Partials       58       64       +6
Impacted Files Coverage Δ
api/api.go 80% <100%> (ø) :arrow_up:
postgres/postgres.go 51.35% <100%> (+2.77%) :arrow_up:
api/fusion.go 11% <28.57%> (+0.96%) :arrow_up:
postgres/location.go 65.33% <47.36%> (-18.88%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 35110a3...205a35b. Read the comment docs.