Hi Tom,

Tom Krcha wrote:
> When you fix it, please let me know - so I will test the trunk.

As I already thought, this is not a bug in Red5 but a potential
wrong usage of scopes.

Let me explain this:
You create the SO and register the handler for it in "appStart".
This method will be called when the first client connects to your
main application i.e. "rtmp://server/application", so the (virtual)
path of your SO would be "application/flashSO".

I'm assuming, your clients connect to instances of your application
like "rtmp://server/application/room", so the (virtual) path of
their SOs would be "application/room/flashSO".  So when they call
a handler on the SO, only the other clients get notified not the
handler, because that is registered at another SO.

To verify this, I created a little test application in Red5.

Upon creation of a room, it creates the SO and registers a handler
on it:

  public boolean roomStart(IScope room) {
    if (!super.roomStart(room))
        return false;
                
    createSharedObject(room, "test", true);
    ISharedObject so = getSharedObject(room, "test");

    so.addSharedObjectListener(new SOEventListener());
    return true;                
  }


The application also has a method that invokes a handler on the
SO in the current scope:

  public void clientMessage(String param) {
    IScope scope = Red5.getConnectionLocal().getScope();
    ISharedObject so = getSharedObject(scope, "test");
    if (so == null) {
      // NOTE: this should not happen as we created the SO in roomStart
      log.error("No shared object found.");
      return;
    }

    ArrayList<String> list = new ArrayList<String>();
    list.add(param);
    so.sendMessage("serverMessage", list);
  }


On the client side, I connect to a room of my application and
register the handler:

  nc = new NetConnection();
  nc.connect("rtmp://localhost:1935/soTest/12345");
  var so: SharedObject = SharedObject.getRemote("test", nc.uri, true);
  so.serverMessage = function(param) {
    trace("ServerMessage: " + param);
  };
  so.connect(nc);


Now I can call the method on the server:

  nc.call("clientMessage", null, "Hello world!");


And what happens is what I expected ;)  The listener I registered in
"roomStart" above is notified about this call as are all connected
clients.

If you want to be able to connect to the application itself (i.e. without
a room), you will need to register a handler in "appStart" like you did.

Well, I hope this helps in understanding the concept of scopes in
Red5.  I'm aware that there is a lot of documentation missing for Red5,
so if anyone is interested in writing tutorials, we all would be very
happy!  Most of the things written in this mail will be part of my
FCS/FMS to Red5 migration guide...

Joachim

_______________________________________________
Red5 mailing list
[email protected]
http://osflash.org/mailman/listinfo/red5_osflash.org

Reply via email to