Thursday, August 12, 2010

When to Namespace Faye Channels

‹prev | My Chain | next›

Up tonight more cleanup from my recent gutting of my (fab) game. I am still quite pleased with replacing my home grown comet solution with faye, but it was a quick (and thorough) replacement.

One of the things not working quite right is player idle timeout. That turns out to be a mismatch in channel names. In the client, I am listening on the "/quit" channel:
  this.faye.subscribe('/quit', function(message) {
self.player_quit(message);
});
In the server, I am broadcasting on the "/players/drop" channel:
  drop_player: function(id) {
puts("Dropping player \""+ id +"\"");
this.faye.publish("/players/drop", id);
delete this._[id];
}
The solution is easy enough—I simply need to choose a common channel—but which? As can be seen in the client, I am not doing a good job of being consistent with my channel names:
PlayerList.prototype.init_subscriptions = function() {
var self = this;

this.faye.subscribe('/move', function(message) {
self.walk_player(message);
});

this.faye.subscribe('/bounce', function(message) {
self.bounce_player(message);
});

this.faye.subscribe('/chat', function(message) {
self.player_say(message);
});

this.faye.subscribe('/players/drop', function(message) {
self.player_quit(message);
});

this.faye.subscribe('/players/create', function(message) {
if (message.id != self.me.id) self.new_player(message);
});
};
At this point, I do not recall why I chose to namespace some of the actions in "/players" nor why most actions did not make the cut for being included in said namespace (all of them are player related). Regardless, I think it makes sense to namespace these actions. At some point I might want to broadcast messages from the room itself or from other entities, so namespacing seems reasonable.

So I search and replace my top level channels with their "/players/*" equivalent, ack through the code (client and server) for subscribe() and publish() calls to make sure that I have not missed anything. With that, I believe that I have resolved all of the minor little problems after switching to faye.

Up tomorrow, who knows? Maybe adding a new feature or two.


Day #193

No comments:

Post a Comment