dndplayer/dnd-player

Add ability to ping map

Closed this issue · 3 comments

Add ability to ping map

Started having a look at this.
Assuming we want to keep bits in Firebase it seems our options are:

  • Use the Realtime Database which would work fairly easy as other clients would be able to easily detect the changing state and display pings. The downside of this is somehow we have to cleanup anything in the DB for this. Either the client that added the ping could remove it from the DB x secs later (but what if they disconnect, it will be orphaned) Or some function runs periodically to remove pings. This is assuming we want to remove them, we could just as well leave them in the DB (they won't use much space) and at-least in development it could be handy to know the historical state of pings etc.
  • The Firebase messaging, which would work well for this also, BUT it seems actually sending a notification/message isn't trivial. Clients aren't supposed to be the initiators of this from what I have read in the docs, instead a server or function is suppose to trigger them.

UPDATE:
Reading into functions a bit further, I think going with a combo of realtime DB and a cleanup function is probably easiest for now.
Function limits on the free plan are:

Invocations: 125K / month
GB-seconds: 40K / month
CPU-seconds: 40K / month
Outbound Networking: Google services only

So it would be easy to have a function trigger when someone adds an entry to the realtime DB at /pings (for example) and the function removes that entry a predefined amount of time later.
If this is too heavy on the limits (a function for EVERY ping) then a periodic function (every 15 mins for example) could just purge the /pings collection of any ping that is older than 1 min for example, so clients have some time to get the ping if their syncs are slow.

I'll start looking into a prototype of this shortly.

I've got most of this implemented (the way we discussed at lunch) and pushed so far in f98bc62

From that commit on you should send pings when left clicking anywhere on the stage and in response to the sync back you should see a console.log with details of the ping, the remainder is yet to push.

image

I've got the remainder half finished - with the UI/Map showing actual pings almost done and a toggle button needed still to enable click to ping so it doesn't happen all the time (unless that's possibly desired).

Now just need to finish the new animation and push that