code: function registerHandlersAndDomains(ws, port) {
              // Called if we succeed at the final setup
              function success() {
                  self._ws.onclose = function () {
                      if (self._autoReconnect) {
                          var $promise = self.connect(true);
                          self.trigger("close", $promise);
                      } else {
                          self._cleanup();
                          self.trigger("close");
                      }
                  };
                  deferred.resolve();
              }
              // Called if we fail at the final setup
              function fail(err) {
                  self._cleanup();
                  deferred.reject(err);
              }
  
              self._ws = ws;
              self._port = port;
              self._ws.onmessage = self._receive.bind(self);
  
              // refresh the current domains, then re-register any
              // "autoregister" modules
              self._refreshInterface().then(
                  function () {
                      if (self._registeredModules.length > 0) {
                          self.loadDomains(self._registeredModules, false).then(
                              success,
                              fail
                          );
                      } else {
                          success();
                      }
                  },
                  fail
              );
          }
docs: Called after a successful connection to do final setup steps