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: 19609
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: 19609
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: 19609
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

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 2 guests