Page 1 of 1

How to get all users and rooms from sfs using javascript

Posted: 30 Dec 2016, 10:02
by scribbledarena
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

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

Posted: 30 Dec 2016, 10:32
by Lapo
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

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

Posted: 02 Jan 2017, 11:12
by scribbledarena
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

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

Posted: 02 Jan 2017, 15:36
by Lapo
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

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

Posted: 14 Jan 2017, 10:04
by Lapo
Actually since you're using Javascript the method to deserialize is called "fromArray".

Sorry for the confusion.

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

Posted: 28 Sep 2018, 19:52
by FireSmartFox
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?

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

Posted: 29 Sep 2018, 08:48
by Lapo
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