Contextual scope handlers in Red5 (appLeave vs roomLeave, appStop vs roomStop, etc)

The issue is

In Red5 different scope handlers triggered by universal events (such as a client disconnecting) will be invoked depending on whether or not the universal event applies to the application scope (the root scope) or a child scope. For instance, if a client disconnects from the application, this will call the appStop, appLeave and appDisconnect handlers. By disconnecting from the application scope the client is also disconnecting from all child scopes (ie: rooms), however these handlers are not called.

A little bit confusing

Of itself, that behaviour’s not too difficult to grasp and I certainly haven’t had anywhere close to enough exposure to the design premise behind red5 to comment on it. Having said that, there are a couple of things which I find a little bit confusing:

  1. The difference between the disconnect and leave handlers is not immediately obvious. It appears that both these handlers are called from the disconnect method on the Scope class (org.red5.server.Scope). My best guess at the moment is that the duplicitous methods have been left in for backwards compatibility or cohesion with FMS.
  2. It seems like the only time the room handlers will be called is if a client is directly connected to a child scope and then wishes to regress to a higher scope. ie: the client connects directly to a room and then drops back to the application scope. In my case the reverse is usually true; the client connects to a lobby and then proceeds to connect to a room (child scope). Connecting to a child scope however is treated by a red5 as a completely new connection, triggering the appConnect handler and resulting in a new client id being assigned to the connection.

I’ve only been using Red5 for a couple of weeks now, so it’s likely a lot of the confusion is my own fault. The code I’m using to connect to a child scope on the server-side was provided by flashmonkey at http://www.flashmonkey.org/?p=341:

public void changeScope() {
IConnection connection = Red5.getConnectionLocal(); IScope currentScope = connection.getScope(); boolean success = currentScope.createChildScope("ChildScope"); if (success) {
IScope newScope = currentScope.getScope("ChildScope"); newScope.connect(connection);
}
}
  1. No comments yet.

  1. No trackbacks yet.