检测Firebase连接是否丢失/重新获得 [英] Detect if Firebase connection is lost/regained

查看:163
本文介绍了检测Firebase连接是否丢失/重新获得的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种策略可以在当前的Firebase产品中检测服务器连接是否丢失和/或重新获得?

我正在考虑一些离线意外事件对于移动设备,我希望有一个可靠的方法来确定Firebase数据层何时可用。

解决方案

功能,我们刚刚发布了一个API更新,让你这样做!

  var firebaseRef = new Firebase('http:// INSTANCE.firebaseio.com'); 
firebaseRef.child('。info / connected')。on('value',function(connectedSnap){
if(connectedSnap.val()=== true){
/ * * /
} else {
/ *我们断线!* /
}
});

完整的文档可在 https://firebase.google.com/docs/database/web/offline-capabilities


Is there a strategy that would work within the current Firebase offering to detect if the server connection is lost and/or regained?

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.

解决方案

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! */
  }
});

Full docs are available at https://firebase.google.com/docs/database/web/offline-capabilities.

这篇关于检测Firebase连接是否丢失/重新获得的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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