Expand my Community achievements bar.

SOLVED

How to subscribe to a "room is now empty" event?

Avatar

Level 1

Hi, I'm trying to figure out how to receive an event when the last user exits the room. I noticed I receive an event a few minutes after the last person quits but it doesn't contain anything meaningful to know what the event really is. Is there a way to know what the event is or do I have to connect to the room and compare the status? My goal is to delete the room after everybody has left the room. A few minutes delay is ok. Also, I would like to be able to fetch the chat content before deleting the room; is that information still available when the event is received?

Thanks!

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Hi

Are you using the RTCHOOKS.java to receive events?  if so, there are 6 methods each of them associated with event type, e.g. receiveNode, receiveNodeDeletion, receiveItem, receiveItemRetraction, receiveNodeConfiguration, and receiveUserRole)  each method will take collectionName, roomName as parameters, you should be able to get the type of the event. 

So for room closing, you should be getting "receiveItemRetraction" on RoomManager collection and roomState node, you should be able to explore the item object which is a java map object to see item details

If you haven't get the RTCHOOKS to work correctly, please take a look at our sample code (sampleApps/Server2Server/BlazeDSGateway_Java), I attached the README.txt here for your reference.

thanks

Dean

View solution in original post

6 Replies

Avatar

Employee

What you are probably talking is an event on RoomManager (the room is shutting down).

While you could "listen" to UserManager events and trigger your logic when there are no more users, I would probably suggest you use RoomManager instead. A user could be temporary disconnected and reconnect right away, but you still will get the notification that for a short time there were no users in the room.

That is why we wait for a couple of minutes  of inactivity before "shutting down" the room.

For chat messages, you can try to call "fetchItems" when the room shut down, but it may be too late (if the items are session dependents they may get deleted before you call fetchItems). One alternative is to listen to messages on the "chat" node instead and collect them while they are generated. Another alternative is to make the items for "chat" non session dependent, call "fetchItems" when the room ends and then delete the items.

Avatar

Level 1

I forgot to mention I'm using a BlazeDS callback hook for server to server communication. I subscribed to the RoomManager collection but the event I receive when the room is shutting down isn't tagged with the event name. How can I tell that this is the correct event and not some other event occurring?

I'll make the chat non session dependent since I'll be deleting the room shortly after anyway.

Thank you!

Avatar

Former Community Member

Hi there,

Can you give a little more detail on what you're seeing? What does the

event look like?

thanks!

nigel

Avatar

Correct answer by
Former Community Member

Hi

Are you using the RTCHOOKS.java to receive events?  if so, there are 6 methods each of them associated with event type, e.g. receiveNode, receiveNodeDeletion, receiveItem, receiveItemRetraction, receiveNodeConfiguration, and receiveUserRole)  each method will take collectionName, roomName as parameters, you should be able to get the type of the event. 

So for room closing, you should be getting "receiveItemRetraction" on RoomManager collection and roomState node, you should be able to explore the item object which is a java map object to see item details

If you haven't get the RTCHOOKS to work correctly, please take a look at our sample code (sampleApps/Server2Server/BlazeDSGateway_Java), I attached the README.txt here for your reference.

thanks

Dean

Avatar

Level 1

Hi Nigel, Hi Dean,

Thanks for the quick reply! I'm using the RTCHOOK.java example and added a loop to show the object map.

Here is the result I get a few minutes after the last person left the room (Room name: p001bz1sx4lb07ctyrfd2):

15:58:21,442 INFO  [STDOUT] LCCS -- receiveItemRetraction: [my token here] p001bz1sx4lb07ctyrfd2 RoomManager roomState

15:58:21,442 INFO  [STDOUT]         item map (publisherID) - __server__

15:58:21,442 INFO  [STDOUT]         item map (body) - active

15:58:21,442 INFO  [STDOUT]         item map (itemID) - item

15:58:21,443 INFO  [STDOUT]         item map (timeStamp) - 1.187719119485E12

15:58:21,443 INFO  [STDOUT]         item map (associatedUserID) - __server__

15:58:21,443 INFO  [STDOUT]         item map (nodeName) - roomState

15:58:21,443 INFO  [STDOUT]         item map (collectionName) - RoomManager

So, if I understand correctly, if I get the event receiveItemRetraction from RoomManager on the node roomState, that means the room is shutting down. Is this the correct way to do it?

Thanks,

Kaven

Avatar

Employee

Yes, this indicates that the room is just about to close (again, a couple of minutes after the last user has left)

Sent from my iPad

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] ----