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

后端 未结 1 562
予麋鹿
予麋鹿 2021-01-22 06:46

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

相关标签:
1条回答
  • 2021-01-22 06:54

    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.

    0 讨论(0)
提交回复
热议问题