TGRHavoc / live_map

A FiveM addon for live maps
https://docs.tgrhavoc.co.uk/livemap-resource/
62 stars 38 forks source link

Move from websockets to see #39

Open TGRHavoc opened 4 years ago

TGRHavoc commented 4 years ago

Websockets are probably not the best technology to use for LiveMap. We don't send any data back from the client so, SSE is looking more promising.

Plus, if we start to use SSE's we can take advantage of FiveM's reverse proxy and move their installations to Ssl-enabled websites.

Obviously this would need a re-write of the interface. It wouldn't be breaking on the resource side (no changes to the API) . Maybe would on the interface)(as we're scrapping websockets all together which, might be relied on by custom scripts).

TGRHavoc commented 4 years ago

Had a quick try at implementing it with the current code base. Then, tried to do it with Lua but... No success. My attempt is over at https://github.com/TGRHavoc/live_map/tree/failed/sse and doesn't work. It's just there to show that I am actively working on trying to find a solution.

I've tried to explain to the best of my ability what I think is wrong in commit 735df7b95d60a4ef69ba730d4f9ef8614ac01303.

In the mean time, I will look at re-writing the resource in C#. More specifically, dotnet. Hopefully I can get something working kind of like webadmin. Afaik, this resource does SSE successfully with an /events endpoint.

So, more research is required and, possibly, a rewrite is needed.

Note: The server-side events and stuff will all still be the same. This will not be a "breaking" change to others depending on the resource. It will however, need another version of the interface to work... Which, I will try and do as simply as possible. Hopefully it's just a matter of swicthing from Websockets to the EventSource API. God, I hope it's that simple.

TGRHavoc commented 4 years ago

Pretty sure this is not possible with the current implementation of FiveM. For some reason the headers don't seem to be sent to the client which, causes browsers' requests to hang until the connection is closed.

I've got a C# implementation over on commit 208bd3bf75479c272d7e0b6665d860d4ec641f46.

If anyone knows if any way of getting SSE to work on FiveM, do contact me on here.

As for now, going to stop working on trying to get SSE working... Good bye dreams of having a secure LiveMap out-of-the-box :disappointed:

robertne13 commented 2 years ago

is there any simple implementation to get the websocket offline and read the coords of every player from a mysql database for example? that server updates every x minutes?

TGRHavoc commented 6 months ago

If anyone knows if any way of getting SSE to work on FiveM, do contact me on here.

So, I've had a nice long break (life) and have come back to this project with a clearer mind. I've figured out a nice C# implementation that uses SSE instead of Websockets. Woo. Only issue I can see on the client side is old browsers might not support eventsource but, that's on them...

I plan on working on the resource first and getting that written mainly in C# (I've been working in that for a good couple of years so am a lot more comfortable than I was in 2020). I will try and plan to also update the interface side of it but I do rember having some difficult problem. Maybe a fresh start is in order 🤔