Page 1 of 1

SwitchspectatortoPlayer

Posted: 14 Jun 2019, 11:36
by Moonshine|ashish
I have joined users to a room as a Spectator initially and at server level used SwitchSpectatorToPlayer method to make users as a Player
like this.

Code: Select all

room.switchSpectatorToPlayer(user);

But at client (HTML5 and Javascript) user is assumed as a Spectator only in current opened clients and whenever a new client window is opened its counted as a Player.

Is it possible to update room detail on currently opened client window whenever we switch spectator to player?

Re: SwitchspectatortoPlayer

Posted: 14 Jun 2019, 13:56
by Lapo
Hi,
you should listen to a specific event called SFSEvent.SPECTATOR_TO_PLAYER on the client side.
See the Javascript docs here:
http://docs2x.smartfoxserver.com/api-do ... _TO_PLAYER

When the event is triggered you can update the user list or any other visual element that distinguish a User playing from a User watching.

Hope it helps

Re: SwitchspectatortoPlayer

Posted: 19 Jun 2019, 09:48
by Moonshine|ashish
Thanks @lapo
I have achieved this using

Code: Select all

getApi().switchSpectatorToPlayer(user);
this will change the user as player and also update client at the same time.