Expand my Community achievements bar.

SOLVED

How to know when all users leave a room using the server-to-server API

Avatar

Former Community Member

What should I subscribe to with the server-to-server API to receive a callback when there are no users in a room or when all users have left a room. From the client, I'm able to look at connectSession.userManager.userCollection, but is there a way to subscribe to this on the server side? Also, could you tell me the name of the collectionNode/node that I should be subscribing too?

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Hi,

On the server side , we don't have by default any code that will tell you if all users have left or not. You would need to build that logic in your server code by yourself. You have to first subscribe to the "UserManager" collection as "UserManager" is the name of UserManager collection node.

Once you do that, you would always get any item that is published on this collection in your 'receiveItem' hook function.

Now, whenever you get an item on the node called "UserList" under this collection , it means either an user has entered or exited or some user's userDescriptor has been modified.

Thus from any item on UserList, you can build a bookkeeping of the list of users on your server side code and whenever you get an item, you can check if your bookkeeping list is empty or not and if so, there is no user in that room.

We do it similarly on the client side too( you can refer to the onItemReceive function in UserManager.as ).

Hope this solves your issue

Thanks

Hironmay Basu

View solution in original post

1 Reply

Avatar

Correct answer by
Former Community Member

Hi,

On the server side , we don't have by default any code that will tell you if all users have left or not. You would need to build that logic in your server code by yourself. You have to first subscribe to the "UserManager" collection as "UserManager" is the name of UserManager collection node.

Once you do that, you would always get any item that is published on this collection in your 'receiveItem' hook function.

Now, whenever you get an item on the node called "UserList" under this collection , it means either an user has entered or exited or some user's userDescriptor has been modified.

Thus from any item on UserList, you can build a bookkeeping of the list of users on your server side code and whenever you get an item, you can check if your bookkeeping list is empty or not and if so, there is no user in that room.

We do it similarly on the client side too( you can refer to the onItemReceive function in UserManager.as ).

Hope this solves your issue

Thanks

Hironmay Basu

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----