Wednesday, May 31, 2017

Re: Restricting the user from closing the browser tab so that the server side APIs are called.

Rahul,

I don't think you're going to find a reliable way to ensure that the
APIs are called from the browser.  There are too many ways for
the user to close the browser, or for the browser to crash, or for
the browser to lose connectivity to the server unexpectedly
(ISP has a glitch, local wireless router has a glitch, laptop carried
too far from the WiFi router, cell phone enters a tunnel or drives
into some other dead zone), etc.

Instead, you may want to do something like this to handle the
cases where the user never clicks your end-call button:
- Have a frequent timer in the browser make an Ajax call to the
   server saying that it is still active -- a "keep-alive" or "heartbeat"
   call, as it is sometimes known.
- Have a server-side process do the necessary cleanup that the API
   call would have done, but only if the keep-alive calls stop coming
   in.

--Fred

Fred Stluka -- mailto:fred@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

On 5/31/17 5:05 PM, Rahul Paul wrote:
Hi,

We are working on a django project in which we are developing a two way audio visual solution for the users. Now we have certain set of APIs that need to be called from JavaScript through ajax request when user ends the call through our end-call button. Some of these ajax calls are sequential i.e. based on result of one ajax call another ajax call is made.

Now our problem is if the user close the tab or browser using the cross button of tab or browser, then these APIs are not called and many of our functionalities does not work. Hence to solve this we were looking into the following options : 

1. Restricting the user from closing the tab or browser until the user clicks on end-call button and all functionalities related to ending the call is done.
2. Calling the APIs before the browser or tab close when user tries to close the browser or tab.
3. Opening our template as a modal so that we can modify the closing of modal to satisfy our use case.

First option is not possible since it poses security risks w.r.t. browser. Currently our web page is opening as new tab. We have tried opening the page as new window and hiding the menu bar, minimize/maximize and cross button, but we could not hide the cross button. 

We tried the second option using window.onbeforeunload and window.onunload feature of JavaScript window object, but we could not call the APIs.

We are now thinking of the third option, but here we are stuck as we are not sure if the template can be directly rendered as a modal from django views. 

Also our web page will have the following major components : 

* video tag, where 2-way A/V will play.
* iframe where we have another feature.
* chat section where communication happens through django channels.
* File upload and download feature.
* Many functionalities are based on API call hence many ajax request.

In short our web page will be heavy and will have a lot of javascript files to be loaded. So will we get the same efficiency with modal as we get with proper web page? What will be the limitation and if possible how we can render our template as modal?

Our main intention have the same flow when the user clicks the end-call button or close the tab or browser i.e. all the functionalities that are happening when end-call button is clicked, must also happen when the user close the tab or browser.

Please help me with resolving this issue. You can also provide options other then what we have considered. All suggestions are welcome.

Thank you.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c0aff7ca-137a-4b28-80ab-a246f35dd4df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment