[SOLVED] Room/User variables

Post here your questions about the Java client / Android API for SFS2X

Moderators: Lapo, Bax

mente
Posts: 73
Joined: 14 Apr 2011, 14:27

[SOLVED] Room/User variables

Postby mente » 20 May 2011, 07:27

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.
mente
Posts: 73
Joined: 14 Apr 2011, 14:27

Postby mente » 20 May 2011, 08:31

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
kalani96746
Posts: 6
Joined: 21 Jun 2008, 17:24

Re: [SOLVED] Room/User variables

Postby kalani96746 » 30 May 2012, 06:55

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());
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: [SOLVED] Room/User variables

Postby Bax » 30 May 2012, 08:21

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.
Paolo Bax
The SmartFoxServer Team

Return to “SFS2X Java / Android API”

Who is online

Users browsing this forum: No registered users and 12 guests