We're implementing a notification system, where we want to notify clients with one and only one popup, when certain triggers occurs.
We are using system.util.sendMessage to notify the clients from the gateway, and then each client is trying to distribute that message to an appropriate page.
Basically we're checking the list of active pageIds, chose 1 and only 1, and use system.perspective.sendMessage to target that specific page, using the data the gateway sent to the session.
The problem we're facing, is when a browser user opens 2 tabs and then closes 1, seems like the session info keeps the 2 pageIDs as active until a refresh is performed. Is there anyway to check if a certain pageID is really opened, or to force a session info refresh?
Or is there an easier way to distribute messages with this specification?
No, there's a timeout. Browsers are not required to notify a server of tab closures, and generally don't. I think you are going to have missed notifications if you have to target only one page.
I suspected as much, about the timeout... Seems like we'll have to rethink strategies, or find a creative way to open only 1 popup.
Thanks again for the quick tips!
Perhaps you could share the final solution so that others that stumble across this thread in the future will know what to do
I'll compile the solution steps, which includes a small cheat
On specific trigger, the gateway sends a message to clients with system.util.sendMessage. On it's payload the type of message (popup, notification, ...), message text, context is identified.
the session events of the clients handle that message, and call a distribution function.This function will analyse the payload and determine the correct action. ALL actions are logged on a message history the user can explore.
If a popup is required, our itention is to show only one popup to the user. In order to do that, we are now cheating a bit until a better solution is found:
we get all active primaryView pageIDs
for each pageID we try to open the popup directly on that page. If it fails, we go to the next pageID until we hit a valid one... It's a ugly solution, we know, and it's still work in progress but we also don't expect to have a lot of gateway popup notifications..
We are considering alternatives, but for these specific kind of notifications, a popup is what we really need. We also know that we will run critical stations with workstation, where we don't expect "tabs" to be closed, but even so we're looking for the most reliable way to deliver critical messages to the operators.