Firebase onDisconnect how to trigger other function
I am reading firebase doc on
onDisconnect but it didn’t quite mention the operation i am looking for.
Goal: when a connection is disconnected, I want to run a function that updates other data that is not related to this connection data.
My code is below:
let PlayerRef = database.ref("/players"); let MessageRef = database.ref("/messages"); let con=playersRef.child(0).push('test'); con.onDisconnect().remove(); // yes i want to remove that current connection // BUT I also want to update the MessageRef that is //using the data in the "con", how can I acheive this???
How would I achieve this?
You can attach an
onDisconnect() handler to any location in your database and remove or write data to that location.
But realize that
onDisconnect() works by sending the write operation to the Firebase servers up front. So you can write any value, as long as that value can be calculated on the client when you attach the
Answered By – Frank van Puffelen