SwitchspectatortoPlayer

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

Moonshine|ashish

SwitchspectatortoPlayer

Postby Moonshine|ashish » 14 Jun 2019, 11:36

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?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: SwitchspectatortoPlayer

Postby Lapo » 14 Jun 2019, 13:56

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
Lapo
--
gotoAndPlay()
...addicted to flash games
Moonshine|ashish

Re: SwitchspectatortoPlayer

Postby Moonshine|ashish » 19 Jun 2019, 09:48

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.

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 21 guests