使用.info / connected测试firebase连接

时间:2015-11-20 01:08:24

标签: firebase

我正在尝试根据Detect if Firebase connection is lost/regained

中的答案测试连接

我试过了:

var testRef=new Firebase('https://flickering-heat-528.firebaseio.com/test');

testRef.child('.info/connected').on('value', function(connectedSnap) {
  if (connectedSnap.val() === true) {
    alert('* we\'re connected! *');
  } else {
    alert('* we\'re disconnected! *');
  }
});

请参阅jsfiddle

但我得到:未捕获错误:Firebase.child失败:第一个参数是无效路径:" .info / connected"。路径必须是非空字符串,并且不能包含"。","#"," $"," [& #34;,或"]"

出了什么问题?

1 个答案:

答案 0 :(得分:5)

您只能在根目录下直接使用.info/connect作为子项,因此:

var testRef=new Firebase('https://flickering-heat-528.firebaseio.com/'); // I removed 'test' here

testRef.child('.info/connected').on('value', function(connectedSnap) {
  if (connectedSnap.val() === true) {
    alert('* we\'re connected! *');
  } else {
    alert('* we\'re disconnected! *');
  }
});