Firebase onDisconnect如何触发其他功能 [英] Firebase onDisconnect how to trigger other function

查看:62
本文介绍了Firebase onDisconnect如何触发其他功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 onDisconnect 上阅读firebase文档,但它并没有提到我正在寻找的操作。
https://firebase.google.com/docs/ reference / js / firebase.database.OnDisconnect

I am reading firebase doc on onDisconnect but it didn't quite mention the operation i am looking for. https://firebase.google.com/docs/reference/js/firebase.database.OnDisconnect

目标:当连接断开连接时,我想运行一个更新其他不相关数据的函数到这个连接数据。

Goal: when a connection is disconnected, I want to run a function that updates other data that is not related to this connection data.

我的代码如下:

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???

我如何实现这一目标?

推荐答案

您可以将 onDisconnect()处理程序附加到数据库中的任何位置,并将数据移除或写入该位置。

You can attach an onDisconnect() handler to any location in your database and remove or write data to that location.

但要意识到 onDisconnect()的工作方式是先将写操作发送到Firebase服务器。因此,只要在附加 onDisconnect 侦听器时可以在客户端上计算该值,就可以编写任何值。

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 onDisconnect listener.

这篇关于Firebase onDisconnect如何触发其他功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆