firebasenest-api

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


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?


Solution

  • 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.