如何检测firestore连接失败 [英] How to detect firestore connection failure

查看:136
本文介绍了如何检测firestore连接失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用angularfire2来了解云端防火墙数据库是否可访问以及我是否可以获取集合值?

I would like to know how it is possible with angularfire2 to know if the cloud firestore database is accessible and that I can get collection values?

此处的目标是如果它失败了,我会去获取本地数据。

The goal here is if it fails, I will go get local data instead.

我有类似的东西

this.afStore.collection('messages').valueChanges().subscribe(
  (messages: any[]) => {

    // DO STUFF
  });

谢谢

推荐答案

Firestore不会暴露在线或离线的概念。在内部,SDK管理连接,并无限期地重试,直到它可以重新获得连接。 SDK通常假设您的应用程序处于联机状态,暂时中断。

Firestore doesn't expose a concept of being "online" or "offline". Internally, the SDK manages the connection, and retries indefinitely until it can regain its connection. The SDK generally assumes that your app is online, with temporary moments of outage.

在重新获得连接之前,本地持久性缓存用于满足读取和写入。无法从缓存中读取的读取等待10秒以获取来自服务器的响应(除非您的连接非常慢)。涉及事务的写入无法写入本地缓存 - 必须在完全联机时执行。

Until a connection is regained, the local persistence cache is used to satisfy reads and writes. A read that cannot come from cache waits 10s for a response from the server (unless your connection is really slow). A write that involves a transaction can't be written to local cache - it must be performed while fully online.

如果存在某种类型,您可以尝试自行检查连接,但不保证SDK具有与服务端的即时可用连接。

You could attempt to check for yourself if there is some sort of connectivity, but that doesn't guarantee that the SDK has an immediately available connection to the service side.

这篇关于如何检测firestore连接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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