cp2004 / OctoPrint-CameraStreamer-Control

Embed WebRTC (& more) streams provided by camera-streamer in OctoPrint
GNU Affero General Public License v3.0
18 stars 0 forks source link

Stream Timeout prevents camera-streamer to stop when browser tab or browser is closed. #3

Closed sarusani closed 9 months ago

sarusani commented 9 months ago

Because the stopStream function is using the timeout when called from onWebcamVisibilityChange, the camera-streamer stream is not properly stopped when the user closes the browser tab or browser. (I'm testing in Chrome)

If the code in onWebcamVisibilityChange is changed to self.stopStream(true) (force the stop) or the stream timeout is set to 0 in the settings, everything works as expected.

How to reproduce: Check CPU usage with top.

  1. switch from control tab to any other tab that isn't showing the cam (ex. temp) -> camera-streamer CPU usage falls bellow 1%
  2. switch back to control tab -> camer-streamer usage goes back up (depending on the settings, usually somewhere between 5% - 20%)
  3. close chrome tab or browser -> camera-streamer CPU usage stays up. Only way to bring it down is to restart the camera-streamer service.
cp2004 commented 9 months ago

Hmm yeah I can reproduce this easily as well with the steps provided. I think that camera-streamer should probably be killing off inactive streams itself, but I have added a beforeunload event listener to stop the streams myself. The timeout should still fire in all other cases, since it prevents constant load/unload cycle when switching tabs quickly for example.

cp2004 commented 9 months ago

Should be released as 1.0.1, and I'm going to put this plugin on the plugin repository imminently.