How to use Firebase client to connect to Nest API using multiple client connections (Node.JS client library)?

旧街凉风 提交于 2019-12-02 06:34:24

问题


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

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

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


回答1:


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.

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
});

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



来源:https://stackoverflow.com/questions/28242306/how-to-use-firebase-client-to-connect-to-nest-api-using-multiple-client-connecti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!