Is there a way to make the firebase realtime database presence system detect disconnect faster

后端 未结 1 1907
臣服心动
臣服心动 2021-01-13 10:26

I am creating a flutter app, it would be essential to detect almost immediately a user goes offline from the realtime/firestore database and notify other users of the same.<

相关标签:
1条回答
  • 2021-01-13 11:18

    There are two ways a client can disconnected:

    • a clean disconnect, where the client lets the server know that it's disappearing.

    • a dirty disconnect, where the client disappears and it's up to the server to detect this condition.

    For clean disconnects, the onDisconnect writes you defined will run immediately.

    Dirty disconnects depend on socket time-outs, which means it may take multiple minutes before your onDisconnect writes happen. There is nothing you can do about this behavior, as it's an inherent part of how sockets work.

    If you want a faster way to detect what clients are still connected, you can write a keep-alive in the database. Essentially: every 10 seconds write a sentinel value from every client.

    0 讨论(0)
提交回复
热议问题