每次我运行此脚本时,它第一次显示“未连接”,然后显示“已连接”。为什么总是先触发“未连接”? 有一些主题与此问题相同 link ,但没有答案。
var connectedRef = firebase.database().ref(".info/connected");
connectedRef.on("value", function(snap) {
if (snap.val() === true) {
alert("connected");
} else {
alert("not connected");
}
});
最佳答案
这是 Firebase 的一个正常的、有目的的功能,可以避免任何竞争条件。
引用文档: https://firebase.google.com/docs/database/web/offline-capabilities
Note that your app should queue the disconnect operations before a user is marked online, to avoid any race conditions in the event that the client's network connection is lost before both commands can be sent to the server.
关于javascript - Firebase 连接状态监听器在 javascript 中返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46294783/