Just to be sure all websocket classes that raised the WebSocket_Connected will eventually raise the WebSocket_Disconnected at some point. This is the natural behavior no?
My project requires two rules:
1. the app runs in only one tab of the browser
2. the users can login only from one device/browser
So for the first rule I created a Map that holds each SessionId as key and a counter as value so in all websocket classes (pages) in WebSocket_Connected I verify if the SessionId is already in the map, if so I show a message to the user that the app runs only in one tab of the browser, if not i put the SessionId in the map with the counter set to 1 and let the user continue. Also In WebSocket_Disconnected I get the counter from the map and subtract 1 from the counter. If it reaches to 0 I remove the session id from the map.
For the second rule I created another Map that holds each authenticated UserId as key so in Login method I verify if the users already exists in the map, if so I show a message to the user that he is logged in already in another windows, if not i add the user id to the map and let it continue. Also in all websocket classes (pages) on WebSocked_Connected i add the user id to the map and in WebSocket_Disconnected I remove the user id from the map.
So you see why I need all websocket class that raised Connected eventually at some point (browser exit, device restart, loss of internet connection) to raise the Disconnected event.
If this is the right way to do it do i need to initialize the map as Thread Safe Maps ?
Or maybe is there another way to achieve what i need !?