packages/ddp-server/livedata_server.js
function(userId) {
    var self = this;

    if (userId !== null && typeof userId !== "string")
      throw new Error("setUserId must be called on string or null, not " +
                      typeof userId);

    // Prevent newly-created universal subscriptions from being added to our
    // session; they will be found below when we call startUniversalSubs.
    //
    // (We don't have to worry about named subscriptions, because we only add
    // them when we process a 'sub' message. We are currently processing a
    // 'method' message, and the method did not unblock, because it is illegal
    // to call setUserId after unblock. Thus we cannot be concurrently adding a
    // new named subscription.)
    self._dontStartNewUniversalSubs = true;

    // Prevent current subs from updating our collectionViews and call their
    // stop callbacks. This may yield.
    self._eachSub(function (sub) {
      sub._deactivate();
    });

    // All subs should now be deactivated. Stop sending messages to the client,
    // save the state of the published collections, reset to an empty view, and
    // update the userId.
    self._isSending = false;
    var beforeCVs = self.collectionViews;
    self.collectionViews = {};
    self.userId = userId;

    // Save the old named subs, and reset to having no subscriptions.
    var oldNamedSubs = self._namedSubs;
    self._namedSubs = {};
    self._universalSubs = [];

    _.each(oldNamedSubs, function (sub, subscriptionId) {
      self._namedSubs[subscriptionId] = sub._recreate();
      // nb: if the handler throws or calls this.error(), it will in fact
      // immediately send its 'nosub'. This is OK, though.
      self._namedSubs[subscriptionId]._runHandler();
    });

    // Allow newly-created universal subs to be started on our connection in
    // parallel with the ones we're spinning up here, and spin up universal
    // subs.
    self._dontStartNewUniversalSubs = false;
    self.startUniversalSubs();

    // Start sending messages again, beginning with the diff from the previous
    // state of the world to the current state. No yields are allowed during
    // this diff, so that other changes cannot interleave.
    Meteor._noYieldsAllowed(function () {
      self._isSending = true;
      self._diffCollectionViews(beforeCVs);
      if (!_.isEmpty(self._pendingReady)) {
        self.sendReady(self._pendingReady);
        self._pendingReady = [];
      }
    });
  }
function(userId) {
    var self = this;

    if (userId !== null && typeof userId !== "string")
      throw new Error("setUserId must be called on string or null, not " +
                      typeof userId);

    // Prevent newly-created universal subscriptions from being added to our
    // session; they will be found below when we call startUniversalSubs.
    //
    // (We don't have to worry about named subscriptions, because we only add
    // them when we process a 'sub' message. We are currently processing a
    // 'method' message, and the method did not unblock, because it is illegal
    // to call setUserId after unblock. Thus we cannot be concurrently adding a
    // new named subscription.)
    self._dontStartNewUniversalSubs = true;

    // Prevent current subs from updating our collectionViews and call their
    // stop callbacks. This may yield.
    self._eachSub(function (sub) {
      sub._deactivate();
    });

    // All subs should now be deactivated. Stop sending messages to the client,
    // save the state of the published collections, reset to an empty view, and
    // update the userId.
    self._isSending = false;
    var beforeCVs = self.collectionViews;
    self.collectionViews = {};
    self.userId = userId;

    // Save the old named subs, and reset to having no subscriptions.
    var oldNamedSubs = self._namedSubs;
    self._namedSubs = {};
    self._universalSubs = [];

    _.each(oldNamedSubs, function (sub, subscriptionId) {
      self._namedSubs[subscriptionId] = sub._recreate();
      // nb: if the handler throws or calls this.error(), it will in fact
      // immediately send its 'nosub'. This is OK, though.
      self._namedSubs[subscriptionId]._runHandler();
    });

    // Allow newly-created universal subs to be started on our connection in
    // parallel with the ones we're spinning up here, and spin up universal
    // subs.
    self._dontStartNewUniversalSubs = false;
    self.startUniversalSubs();

    // Start sending messages again, beginning with the diff from the previous
    // state of the world to the current state. No yields are allowed during
    // this diff, so that other changes cannot interleave.
    Meteor._noYieldsAllowed(function () {
      self._isSending = true;
      self._diffCollectionViews(beforeCVs);
      if (!_.isEmpty(self._pendingReady)) {
        self.sendReady(self._pendingReady);
        self._pendingReady = [];
      }
    });
  }
function ( userId ) { var self = this ; if ( userId !== null && typeof userId !== "string" ) throw new Error ( "setUserId must be called on string or null, not " + typeof userId ) ; // Prevent newly-created universal subscriptions from being added to our // session; they will be found below when we call startUniversalSubs. // // (We don't have to worry about named subscriptions, because we only add // them when we process a 'sub' message. We are currently processing a // 'method' message, and the method did not unblock, because it is illegal // to call setUserId after unblock. Thus we cannot be concurrently adding a // new named subscription.) self . _dontStartNewUniversalSubs = true ; // Prevent current subs from updating our collectionViews and call their // stop callbacks. This may yield. self . _eachSub ( function ( sub ) { sub . _deactivate ( ) ; } ) ; // All subs should now be deactivated. Stop sending messages to the client, // save the state of the published collections, reset to an empty view, and // update the userId. self . _isSending = false ; var beforeCVs = self . collectionViews ; self . collectionViews = { } ; self . userId = userId ; // Save the old named subs, and reset to having no subscriptions. var oldNamedSubs = self . _namedSubs ; self . _namedSubs = { } ; self . _universalSubs = [ ] ; _ . each ( oldNamedSubs , function ( sub , subscriptionId ) { self . _namedSubs [ subscriptionId ] = sub . _recreate ( ) ; // nb: if the handler throws or calls this.error(), it will in fact // immediately send its 'nosub'. This is OK, though. self . _namedSubs [ subscriptionId ] . _runHandler ( ) ; } ) ; // Allow newly-created universal subs to be started on our connection in // parallel with the ones we're spinning up here, and spin up universal // subs. self . _dontStartNewUniversalSubs = false ; self . startUniversalSubs ( ) ; // Start sending messages again, beginning with the diff from the previous // state of the world to the current state. No yields are allowed during // this diff, so that other changes cannot interleave. Meteor . _noYieldsAllowed ( function ( ) { self . _isSending = true ; self . _diffCollectionViews ( beforeCVs ) ; if ( ! _ . isEmpty ( self . _pendingReady ) ) { self . sendReady ( self . _pendingReady ) ; self . _pendingReady = [ ] ; } } ) ; }
Sets the current user id in all appropriate contexts and reruns all subscriptions
Sets the current user id in all appropriate contexts and reruns all subscriptions