检测 Firebase 连接是否丢失/恢复 [英] Detect if Firebase connection is lost/regained
本文介绍了检测 Firebase 连接是否丢失/恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种策略可以在当前的 Firebase 产品中使用来检测服务器连接是否丢失和/或重新获得?
Is there a strategy that would work within the current Firebase offering to detect if the server connection is lost and/or regained?
我正在考虑针对移动设备的一些离线突发事件,我想要一种可靠的方法来确定 Firebase 数据层何时可用.
I'm considering some offline contingencies for mobile devices and I would like a reliable means to determine when the Firebase data layer is available.
推荐答案
这是一个普遍要求的功能,我们刚刚发布了一个 API 更新来让您做到这一点!
This is a commonly requested feature, and we just released an API update to let you do this!
var firebaseRef = new Firebase('http://INSTANCE.firebaseio.com');
firebaseRef.child('.info/connected').on('value', function(connectedSnap) {
if (connectedSnap.val() === true) {
/* we're connected! */
} else {
/* we're disconnected! */
}
});
完整文档可在 https://firebase.google.com/docs/database/web/offline-capabilities.
这篇关于检测 Firebase 连接是否丢失/恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文