SMART icon indicating copy to clipboard operation
SMART copied to clipboard

WIP: Django Channels for timeout

Open schittarath3-rti opened this issue 3 years ago • 0 comments

Rather than continuously polling for admin access. This PR adds Django Channels to open a websocket and communicate with the SMART server. This is more resource intensive upfront (creating the socket, opening the connection, etc), but produces less strain on the server over long periods because communication only happens when there needs to be.

Steps: Admin 1 and admin 2 join the coding page for the same project, but since admin 1 joins first, admin 1 get access. They both create a websocket addressed to the project's channel.

Admin 1 timeouts due to inactivity and admin 2 refreshes.

The server sees that admin 1 timeouts and sends a broadcast to all admins containing the userID of the timeout admin. Admin 1 sees that the message is targeted to admin 1. Admin 1 gets its tabs removed and admin access removed.

Admin 2 gets access and is able to immediately use it.

Strange cases: A window going off focus then on focus can cause it to not work properly on the client-side. Probably because the browser hibernates the tab if there is inactivity.

Notes: The websocket disconnect may be the answer to the beforeunload() function as the browser calls the disconnect function before it exits. There are some comments about it under the SMARTConsumer.disconnect function.

This branch was built upon the other coding timeout branch, but they are mutually exclusive to each other functionally.

schittarath3-rti avatar Aug 12 '22 18:08 schittarath3-rti