The critical thing appears to be that clients join two rooms simultaneously.Then if there are two clients active, one gets a single u8
(the one who sent the u70). Everyone else gets multiple u8's all identical,
at least in the log.
I'm not sure how to get it to do more than two, but it will.
I've seen 3 and 4 repetitions.
Perhaps if you join and leave a few more rooms.
Here's a test case: [ see end of message for a note about making it even simpler ]
Start with Orbiter Chat Room example:
http://www.unionplatform.com/?page_id=3318- join a second room (any other room)
- Instead of sending a chat message, send a room module message.
The name of that message is used to update a client attribute for the client who sent it.
Here's the client side code:
- Code: Select all
29a30
> var UPC = net.user1.orbiter.UPC;
54c55,56
< orbiter.connect("tryunion.com", 80);
---
> //orbiter.connect("tryunion.com", 80);
> orbiter.connect("localhost", 9100);
69a72
> chatRoom.addEventListener(net.user1.orbiter.RoomEvent.UPDATE_CLIENT_ATTRIBUTE, cliAttChanged);
75a79,80
> orbiter.getRoomManager().joinRoom("SOME_OTHER_ROOM"); // Can be any other existing room
>
91a97,103
> function cliAttChanged(e)
> {
> var att = e.getChangedAttr();
> if (att.name == "_PING") return;
> displayChatMessage("Client Attr Changed " + att.name);
> }
>
110a123
>
113c126,127
< chatRoom.sendMessage("CHAT_MESSAGE", "true", null, outgoing.value);
---
> orbiter.getMessageManager().sendUPC(UPC.SEND_ROOMMODULE_MESSAGE, "chatRoom", outgoing.value);
> //chatRoom.sendMessage("CHAT_MESSAGE", "true", null, outgoing.value);
Here's the room module: chat_mod.js
- Code: Select all
importClass(org.apache.log4j.Logger);
importClass(net.user1.union.core.attribute.Attribute);
importClass(net.user1.union.core.def.RoomDef);
importClass(net.user1.union.core.def.AttributeDef);
importClass(net.user1.union.core.def.ModuleDef);
importClass(net.user1.union.api.Room);
importClass(net.user1.union.core.event.RoomEvent);
importClass(net.user1.union.core.event.ServerEvent);
var moduleContext;
var wrapper;
var myRoom;
var server;
var log = Logger.getLogger("chat_mod");
function init(ctx, wrap)
{
moduleContext = ctx;
wrapper = wrap;
myRoom = ctx.getRoom();
server = ctx.getServer();
wrapper.addRoomEventListener(RoomEvent.MODULE_MESSAGE, "onModuleMessage");
wrapper.addRoomEventListener(RoomEvent.ADD_CLIENT, "newOcc");
}
function newOcc(e)
{
var cl = e.getClient();
cl.setAttribute("seated", "", Attribute.SCOPE_GLOBAL,
Attribute.FLAG_SHARED | Attribute.FLAG_SERVER_ONLY);
}
function onModuleMessage(e)
{
var cl = e.getClient();
cl.setAttribute("seated", e.getMessage().getMessageName(), Attribute.SCOPE_GLOBAL,
Attribute.FLAG_SHARED | Attribute.FLAG_SERVER_ONLY);
}
// This method must be implemented by every room module script.
function shutdown()
{
}
Add this to union.xml:
- Code: Select all
<room>
<id>chatRoom</id>
<modules>
<module>
<id>chat_mod</id>
<source type="script">chat_mod.js</source>
</module>
</modules>
</room>
For an even simpler test case, you don't need the Room Module.
Instead of sending a Room Module Message,
just do orbiter.self().setClientAttribute( .... ).
Then what you see in the log is:
u3 for the client setting the attribute and
double u8 for the other client, and no u8 for the first client,
and finally a u73, set_client_attribute_result.
Again, joining two rooms simultaneously seems to be the key factor.