How to get the number of times a user has joined a given room?

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

shahidbits2012
Posts: 16
Joined: 09 Jun 2021, 07:23

How to get the number of times a user has joined a given room?

Postby shahidbits2012 » 23 Sep 2022, 10:10

Hi,

We have a usecase where we want to know the number of times a user has joined a particular room.
There are couple of ways like maintaining a userId->count map in room variable/session and update it on user join room event.

But, wanted to check with you if there is an inbuilt-way to get that?

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

Re: How to get the number of times a user has joined a given room?

Postby Lapo » 23 Sep 2022, 11:57

Hi,
there is no pre-built functionality like the one you have described.

There are couple of ways like maintaining a userId->count map in room variable/session and update it on user join room event.

It's a good idea, but there can be side effects. If Rooms are persistent (i.e. they are never removed) you will need to keep track of Users leaving the server and remove their entry in the map that keeps count. Otherwise you'll end up with an ever-growing table of associations.

Other than that the idea of using a map seems good. I would probably recommend using AtomicIntegers to keep count, so that you don't have to worry about concurrent updates.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 62 guests