We have a system where users have a licence and we want to decrease the licence count if the user closes the browser window / tab.
We’re using the Beacon API to detect this event in the detach listener but detaching is called for other reasons and we can’t discern explicitly if it was because of a browser window / tab close event.
Can you give us a clue of how to find the cause of the detach event?
We’ve looked through all of the variables in the debugger and looked through the Vaadin documentation and can’t find anything.
but detaching is called for other reasons and we can’t discern explicitly if it was because of a browser window / tab close event.
Not sure I understand the reasoning here. Why shouldn’t the license count be reduced also for other detach reasons? A assume you will anyways increase the count again whenever a new UI instance is created which means that you will end up with an ever increasing count if you don’t count all detaches.
There isn’t any directly supported way of detecting the detach reason. What you could try is to look at the HTTP request to find out if it’s in the format send through the Beacon API. I guess you could do this by accessing VaadinRequest.getCurrent() in the detach handler or by using a servlet filter.