Waboodoo / HTTP-Shortcuts

Android app to create home screen shortcuts that trigger arbitrary HTTP requests
https://http-shortcuts.rmy.ch
MIT License
1.17k stars 113 forks source link

[BUG] Fullscreen window running in background when closed with "X" #276

Closed hubmartin closed 2 years ago

hubmartin commented 2 years ago

Steps To Reproduce

  1. Go to action response handling
  2. Set Display Type to Fullscreen window
  3. Set URL to any page streaming MJPEG stream media
  4. Start the action
  5. Click the "X" close symbol in the top left corner to close the window.
  6. The window closes but runs in background. In case I have MJPEG video stream, the video is streaming (eating from data plan) until I close the app from the list of running Android apps.

Expected behavior Fullscreen tab should close when I click the X and will not run in background Actual behavior Page runs in background, in case of video stream it continue to stream in background

Context (please complete the following information):

Thanks for this awesome app and keeping it active!

Any workaround is also welcome. For now I can open garage and watch the doors very easily from Android main screen, but then I need to open Tasks and swipe up to close that app and during that time I'm already driving which is really inconvinient.

I tried scripting with wait() and abort() but with no luck. I also tried to add to my page some javascript that stops streaming after 20 seconds. It works in chrome on desktop and android, but it seems like javascript is not executed in the HTTP Shortcut fullscreen window:

<html>
    <head></head>
    <body>
        <h1>OK</h1>
        <img src="https://xxx/webcam" style="width:100%" id="img"/>
        <input type="button" onclick="stopStream()" value="webcam" />
        <script>

        setTimeout(stopStream, 20000);

        function stopStream()
        {
            document.getElementById('img').src=''
        }

        </script>
    </body>
</html>
Waboodoo commented 2 years ago

Thanks for the bug report.

I'm actually a little surprised that MJPEG streaming works at all, I had not even thought of that. When the app displays a response as HTML, it does so in a quite simplistic way, meaning that it does not act as a browser and therefore also does not support things like running JavaScript.

I will look into the issue of the MJPEG stream remaining open in the background, and include a fix for it in the next release.

As a workaround for now I can only suggest to not use the in-app displaying of the response, and instead try to open the MJPEG-URL in a browser. Perhaps you could have your server just return the URL of the MJPEG stream, and then have a script that opens a browser, like this:

openUrl(response.body);
abort();

Or if you want to avoid having to change the server's response, you could try to parse it and extract the URL from it, like this:

const parsed = parseXML(response.body);
const url = parsed.children[1].children[1].attributes.src;
openUrl(url);
abort();
Waboodoo commented 2 years ago

This bug is fixed in version 2.18.0, which is currently being prepared for release. It will soon become available for beta testing.

hubmartin commented 2 years ago

Thanks for the quick fix. I have already tested it, and it works perfectly!

This is what I'm now observing in 2.18.0 when I run the shortcut from the Android launcher.

When I exit the fullscreen window with any of the actions:

I get back to the Android launcher, and the MJPEG stream stops. I see no more data is transferred in the background. However, the window is still in the launched apps, and when I select it again, the MJPEG stream starts again. (but the HTTP/POST action with my custom HTTP header parameter is not called again, which is correct). Is this stream stopping and recovery a feature of the HTTP Shortcuts or some Android smart behaviour to stop data when the App is in the background? I'm just curious. Thanks again for the fix.

Waboodoo commented 2 years ago

When the window is closed (regardless of how), the HTTP Shortcuts app will now make sure that all of its resources are released. This is the part that was not fully implemented prior to 2.18.0. If after this you select the window again from the launched apps, it will essentially re-create the window and thereby reopen the MJPEG connection that was previously closed. This window is only responsible for displaying data though, not for making the actual HTTP request, so it will just show the same state as before you closed it, but loading the MJPEG stream is part of that displaying.

hubmartin commented 2 years ago

Thanks for the explanation. I've donated to your PayPal as thanks for this awesome app. Would suggest putting the donate button higher on the page and closer to the main page ;) Feel free to close this issue.

Waboodoo commented 2 years ago

Thanks a lot, much appreciated. I was considering moving the button somewhere else, but my humbleness and the fact that the Play Store reviewers sometimes decide that they don't like it kept me from it, so I think it's fine where it is ;).