This project demonstrates how to create a simple real-time web-based map visualization that communicates with a Node.js server over GRPC. The server and client communicate using GRPC, using code generated from the service defined in the proto
directory. The server has simulated "robots", which just move around randomly. Their positions are visualized on top of a map using Leaflet.
The project consists of three components:
- Web client
- GRPC server
- Envoy proxy
The web client communicates with the GRPC server via the Envoy proxy. A proxy layer is required because browsers do not provide fine-grained transport APIs required by GRPC. Envoy is the proxy used in the official docs.
All dependencies can be retrieved automatically given that you have some basic prerequisites installed. A single command will install dependencies and then start all three components locally in development mode. You can then navigate to the web client URL to see the project in action. See the next section for details.
Dependencies: Node 16+, npm, Docker
- Get pnpm:
npm install -g pnpm
pnpm start
- navigate to http://localhost:4567
When you're done:
- Stop the Envoy container using
pnpm stop-envoy
- Drag to pan map, scroll/pinch to zoom
- Machine locations are displayed as pin icons
- Select a machine using the dropdown, or by clicking on its icon
- With a machine selected, use the buttons to perform actions
There's no automated testing yet. Here are some things that could be tested:
- Start client and server, check that client shows "connected"
- A pin appears on the map for each distinct machine written to MachineStream
- When the server writes to MachineStream, a corresponding pin on the map moves
- Selecting a machine and clicking "(Un)Pause" causes the server to receive (Un)Pause RPC
- Clicking on a map pin selects the correct machine
- The client calls MachineStream again if the stream ends (reconnect)
- The server and client support hot-reloading.
- The client has hot module replacement via Parcel
- The server will be recompiled and restarted when changes occur
Dependencies: Python 3, protoc
on path
npm i -g protoc-gen-ts
cd proto
python generate.py