我如何强制Firebase实时数据库使用WebSockets? [英] How can I force Firebase Realtime Database to use WebSockets?

查看:149
本文介绍了我如何强制Firebase实时数据库使用WebSockets?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Firebase实时数据库网络SDK可以使用WebSockets或长轮询与后端服务器通话。有没有办法迫使它只使用WebSockets?

解决方案

一般来说,你不想这样做,因为Firebase SDK会自动检测客户端是否支持WebSocket,并在可能的情况下使用它们。由于WebSocket在所有浏览器和所有环境下都不能可靠地工作(例如,代理偶尔不能可靠地支持WebSocket流量),所以强制使用WebSocket可能会导致您的应用在某些情况下无法可靠地工作。



作为诊断工具或解决非常具体的问题,可以通过将databaseURL更改为 wss://< app> .firebaseio.com,强制客户端使用WebSockets / 而不是 https://< app> .firebaseio.com / ,但是如果您发现自己需要这样做, 支持来查看是否有更好的解决方案。

I know the Firebase Realtime Database web SDK can use either WebSockets or long-polling to talk to the backend servers. Is there a way to force it to only use WebSockets?

解决方案

In general, you don't want to do this since the Firebase SDK automatically detects whether the client supports WebSockets and will use them if possible. Since WebSockets don't work reliably in all browsers and in all environments (e.g. proxies occasionally don't reliably support WebSocket traffic), forcing WebSocket usage may cause your app to not work reliably in some situations.

As a diagnostic tool or to work around very specific issues, you can force the client to use WebSockets by changing your databaseURL to wss://<app>.firebaseio.com/ instead of https://<app>.firebaseio.com/ but if you find yourself needing to do this, it's probably worth reaching out to support to see if there's a better solution.

这篇关于我如何强制Firebase实时数据库使用WebSockets?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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