Page 1 of 1

[SOLVED] Room/User variables

Posted: 20 May 2011, 07:27
by mente
Hello,
Using latest java client API I can not catch any (room, user) variables update. I've added listener to event SFSEvent.

Code: Select all

      client.addEventListener(SFSEvent.CONNECTION, listener);
      client.addEventListener(SFSEvent.CONNECTION_LOST, listener);
      client.addEventListener(SFSEvent.LOGIN, listener);
      client.addEventListener(SFSEvent.LOGIN_ERROR, listener);
      client.addEventListener(SFSEvent.EXTENSION_RESPONSE, listener);
      client.addEventListener(SFSEvent.LOGOUT, listener);
      client.addEventListener(SFSEvent.ROOM_JOIN, listener);
      client.addEventListener(SFSEvent.ROOM_JOIN_ERROR, listener);
      client.addEventListener(SFSEvent.USER_VARIABLES_UPDATE, listener);
      client.addEventListener(SFSEvent.ROOM_VARIABLES_UPDATE, listener);

All events are caught, except 2 last ones. I know exactly, that user and room variables are set (visible in admin panel). However I can not receive it in client.
At least I can grab user variables from client, using client.getMyself(). But room variables are not updated on the client, as well.

Posted: 20 May 2011, 08:31
by mente
Solved on my own - in extension I have to call like this:

Code: Select all

getApi().setRoomVariables(room.getOwner(), room, new ArrayList<RoomVariable>(){{add(weatherVariable);}});

Previously I set variable directly on the room

Code: Select all

room.setVariable(weatherVariable);


Question then: why does room has method setVariable, that actually doesn't propagate variables to clients? Mark pls in doc, that this method sets hidden variable, ignoring isHidden() of the variable

Re: [SOLVED] Room/User variables

Posted: 30 May 2012, 06:55
by kalani96746
I was wondering the same thing...however rather than do as you described I found the following to work...

Code: Select all

user.setVariable(new SFSUserVariable("role", roleName));
this.getApi().getResponseAPI().notifyUserVariablesUpdate(user, user.getVariables());

Re: [SOLVED] Room/User variables

Posted: 30 May 2012, 08:21
by Bax
The change mente did is the right way to go. Always go through the API to set values, never modify the objects directly (in the API documentation the methods you are not supposed to use aren't documented - unfortunately there's no way to hide them from autocomplete).
kalani96746, your approach is wrong, follow the other way.