In server.js, there are two variables that keep track of channel users: 'tokenChannels' and 'channels'. I can't seem to find out what the appropriate use cases are for each of them. As far as I can tell, they seemingly serve the same purpose, namely grouping users into channels. The difference is that 'channels' uses a channel name to identify channels, while 'tokenChannels' uses a generated token. Could you please explain why there are two ways to do seemingly the same thing, and when each of those are appropriate to use?

Thank you.

Comments

Gergely Lekli created an issue.

dabbor’s picture

I would really appreciate some info on this topic as well.

There is no documentation explaining channels and tokenChannels and I'm starting to realize that there is quite a big difference between those two.

There is a function:

ClientManager.prototype.setupClientConnection = function (sessionId, authData, contentTokens) {

located in the file client-manager.js of Node.js application "drupal-node.js"

That function contains this code:

// ...
var clientToken = '';
  for (var tokenChannel in contentTokens) {
    // @TODO: Need to check contentTokens.hasOwnProperty()?
    this.tokenChannels[tokenChannel] = this.tokenChannels[tokenChannel] || {'tokens': {}, 'sockets': {}};

    clientToken = contentTokens[tokenChannel];
    if (this.tokenChannels[tokenChannel].tokens[clientToken]) {
      this.tokenChannels[tokenChannel].sockets[sessionId] = this.tokenChannels[tokenChannel].tokens[clientToken];

      this.logger.debug("setupClientConnection: Added token " + clientToken + " for channel " + tokenChannel + " for socket " + sessionId);

      delete this.tokenChannels[tokenChannel].tokens[clientToken];
    }
  }
// ...

And I'm mostly concerned about the line:

delete this.tokenChannels[tokenChannel].tokens[clientToken];

So it seems like the token channel is limited just for one client and probably just for one-time usage.

Anonymous’s picture

http://theoleschool.com/blog/using-drupal-content-channel-tokens-nodejs/

'You can think of content token channels as a per page (or piece of content) channel subscription. This differs from the user channels in that it targets users who are currently viewing a specific page rather than users targeted by some property of the user object (regardless of where they are on the site).'