Pl3xMap
Pl3xMap copied to clipboard
Use SSE Events to push realtime data from the internal server to the webmap
Overview
This pull request introduces the integration of Server-Sent Events (SSE) into our internal webserver, enabling real-time data updates for our webmap. Using SSE we can achieve seamless real-time updates, significantly enhancing the user experience.
Details
Here are the key features and functionalities that this pull request will bring:
- SSE provides real-time player position updates, allowing the webmap to track and display accurate player positions as they rotate and run around.
- SSE facilitates immediate marker updates, making sure that any adjustments or additions to markers are instantly reflected on the webmap.
- In cases where SSE connections are closed or nonexistent, the system gracefully falls back to updating through the old system, which is done through files.
- When an SSE connection is established, the frontend bypasses file-based checks entirely.
What if I want this but I have the internal server off???
You can still get the advantages of this change if you use an external server. Just re-enable the internal web server under a different port and setting up a reverse proxy that points only to the /sse
endpoint. This means you can gain the functionality of real-time data updates while the server is running, while also keeping the map available to view, even if the minecraft server is offline.
/sse
reverse proxy Caddy example:
map.example.com {
root * /var/www/map.example.com/
file_server
handle_path /sse* {
rewrite * /sse{uri}
reverse_proxy localhost:1234
}
@gz {
path *.gz
}
handle @gz {
header Content-Encoding gzip
}
}
TODO:
- [ ] adjust how often the SSE task should run (currently every tick, maybe increase?)
- [ ] better SSE disconnection handling
- [ ] better SSE handling in webmap
- [ ] fallback to old system if data from SSE takes longer than a second?
- [ ] clean up implementation
- [ ] remove
SSE_EVENTS
option - [ ] anything else i think of