如何使用Firebase客户端使用多个客户端连接(Node.JS客户端库)连接到Nest API? [英] How to use Firebase client to connect to Nest API using multiple client connections (Node.JS client library)?

查看:117
本文介绍了如何使用Firebase客户端使用多个客户端连接(Node.JS客户端库)连接到Nest API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个中央模块,该模块需要处理多个用户,并将他们的嵌套数据更改订阅给他们.

I'm building a central module that needs to handle multiple users, subscribing them to data changes on their nests.

根据我一直在搜索的内容,Node.JS库不允许我与Google Nest API建立多个Firebase连接.

From what I've been searching, the Node.JS library won't allow me to do multiple firebase connections to the Google Nest API.

在不将REST或REST与流结合使用的情况下,是否有任何解决方法?

Is there any workaround without using REST or REST with streaming?

推荐答案

您可以通过为每个用户创建一个新的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.

这篇关于如何使用Firebase客户端使用多个客户端连接(Node.JS客户端库)连接到Nest API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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