【问题标题】:Need help in creating a cloud function to respond to onDisconnect event on a particular node - Firebase在创建云函数以响应特定节点上的 onDisconnect 事件时需要帮助 - Firebase
【发布时间】:2018-07-23 23:06:11
【问题描述】:

我在编写 Firebase 云函数以响应 onDisconnect 事件时需要帮助,由于我的客户端正在连接到特定节点,如何监听特定节点以断开连接,我是云函数的新手,非常感谢您的帮助.

提前致谢。

【问题讨论】:

  • 我想实现类似var amOnline = new Firebase('https://<demo>.firebaseio.com/.info/connected'); var userRef = new Firebase('https://<demo>.firebaseio.com/presence/' + userid); amOnline.on('value', function(snapshot) { if (snapshot.val()) { userRef.onDisconnect().set(Firebase.ServerValue.TIMESTAMP); userRef.set(true); } }); 的功能,但在云功能中,是否有可能,因为我的客户端可能会在不更新节点的情况下断开互联网连接。

标签: firebase firebase-realtime-database google-cloud-functions


【解决方案1】:

没有从用户断开连接到触发云功能的直接触发。你会use the regular Realtime Database functionality for storing presence information in the database

然后,您可以通过该数据库写入触发 Cloud Functions,例如:

exports.onlineStateChanged = functions.database.ref('/status/{uid}/')
    .onWrite((change, context) => {

这与using the Realtime Database to get a presence information into Cloud Firestore的解决方案非常相似。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-14
    相关资源
    最近更新 更多