且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Firebase客户端使用多个客户端连接(Node.JS客户端库)连接到Nest API?

更新时间:2022-05-19 22:04:02

您可以通过为每个用户创建一个新的Firebase.Context在Firebase实时客户端库中解决此问题.这是Firebase构造函数的一个未记录的第二个参数,该参数在将来的发行版中可能会更改,但会指示该实例建立和维护新的TCP连接,而不是共享公用的TCP连接.

You can solve this in the Firebase realtime client libraries by creating a new Firebase.Context for each user. This is an undocumented second parameter to the Firebase constructor that may change in future releases, but instructs the instance to set up and maintain a new TCP connection rather than sharing the common one.

在Node.JS中使用它的一个例子是:

An example of its use in Node.JS would be:

var Firebase = require('firebase');
var authToken = 'some_long_auth_token';

var userRef = new Firebase('wss://developer-api.nest.com', new Firebase.Context());
userRef.authWithCustomToken(authToken, function(error) {
  // Handle auth error
});

Node.JS允许您维护的连接数量可能会受到限制,但我尚未对其进行测试.

There may well be limitations on how many connections Node.JS will allow you to maintain, but I haven't tested them.