How to get all users and rooms from sfs using javascript

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

scribbledarena
Posts: 3
Joined: 30 Dec 2016, 09:57

How to get all users and rooms from sfs using javascript

Postby scribbledarena » 30 Dec 2016, 10:02

Hi

I need to get all users and rooms by using javascript without any event listener just to call function for users and rooms with intervals for updations


Thanks
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to get all users and rooms from sfs using javascript

Postby Lapo » 30 Dec 2016, 10:32

Hi,
you can create this from server side and then call the Extension from a Javascript client.

I need to warn you that it may not be a good idea to send a global list of users and rooms if the server is very trafficked as you may have thousands of Rooms and clients, which in turn would generate very large data.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
scribbledarena
Posts: 3
Joined: 30 Dec 2016, 09:57

Re: How to get all users and rooms from sfs using javascript

Postby scribbledarena » 02 Jan 2017, 11:12

can you please tell me how should i implement the same?

which class and method i need to use to get whole data

Please give me one example



Thanks
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to get all users and rooms from sfs using javascript

Postby Lapo » 02 Jan 2017, 15:36

If you're familiar with developing Extensions you can access the Zone's current room list and User list like this:

Code: Select all

Collection<User> userList = getParentZone().getUserList();
List<Room> roomList =  getParentZone().getRoomList();

You can serialize the User or Room object by calling toSFSArray() and deserialize them via the User or Room newFromSFSArray() method on the client side.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to get all users and rooms from sfs using javascript

Postby Lapo » 14 Jan 2017, 10:04

Actually since you're using Javascript the method to deserialize is called "fromArray".

Sorry for the confusion.
Lapo

--

gotoAndPlay()

...addicted to flash games
FireSmartFox
Posts: 33
Joined: 28 Sep 2018, 19:47

Re: How to get all users and rooms from sfs using javascript

Postby FireSmartFox » 28 Sep 2018, 19:52

Lapo wrote:I need to warn you that it may not be a good idea to send a global list of users and rooms if the server is very trafficked as you may have thousands of Rooms and clients, which in turn would generate very large data.

I also plan to include a global user list of around 200 active users.
What about the server sends a single update on every join and left event? I would just submit the username and if he/she left or logged in. I am not sure because this would cause multiple events per second on high traffic - but they would be small. Is there a limit of events per seconds I should try not to exceed? Better a lot of small updates or every two seconds one big update for such cases?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to get all users and rooms from sfs using javascript

Postby Lapo » 29 Sep 2018, 08:48

FireSmartFox wrote:
Lapo wrote:I need to warn you that it may not be a good idea to send a global list of users and rooms if the server is very trafficked as you may have thousands of Rooms and clients, which in turn would generate very large data.

I also plan to include a global user list of around 200 active users.
What about the server sends a single update on every join and left event?

The server already does that at Room Level. In other words when you join a Room you get the full list of users present in that Room and you get updated every time a new user enters or leaves.

To see this in action check the basic Examples we provide for your favorite platform:
https://www.smartfoxserver.com/download ... p=examples

You can also follow the relative tutorials here:
http://docs2x.smartfoxserver.com/

(Just click the Examples sections in the left side menu)

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 23 guests