MicrosoftEdge / WebView2Feedback

Feedback and discussions about Microsoft Edge WebView2
https://aka.ms/webview2
449 stars 55 forks source link

Prevent mic/webcam access via getUserMedia being terminated when app is minimised #2177

Open breenbob opened 2 years ago

breenbob commented 2 years ago

I am using WebView2 in a WinUI2 UWP app to develop "MS Teams-like" functionality. We use HTML5 getUserMedia() to get access to a MediaStream from the user's webcam/microphone for streaming to a WebRTC call. I'm finding that access to both are being terminated every time the user minimises the app.

This MSDN forum post suggests it is possible to keep the camera alive using an extended session. I've tried this in EnteringBackground event of Application in App.xaml.cs but the camera stops regardless, even though the extended execution request is granted and app termination deferral succeeds. It stops immediately when the app is minimised. Using the old WebView (or WebView1 if you like) it was possible to prevent this by combining the following code in the Application startup with the Background Media Playback capability:

SystemMediaTransportControls.GetForCurrentView().IsPlayEnabled = true; SystemMediaTransportControls.GetForCurrentView().IsPauseEnabled = true;

Is there any way to prevent this happening with WebView2 in WinUI2.8 pre-release for UWP? It makes a WebRTC type application like MS teams virtually unusable.

AB#38188114

breenbob commented 2 years ago

I should add that the web RTC session remains connected and audio streaming continues to work when the app is minimised. This works without extended execution so think this is down to above 2 lines of code and the media playback capability. This is what makes me lean towards this being a bug.

champnic commented 2 years ago

Hey @breenbob - I agree this sounds like a bug, or at least something that we'll probably have to dig in further to find the correct solution if not a bug. I'm adding this to our backlog.

breenbob commented 2 years ago

Thanks @champnic. I've done a sample repro to help demonstrate the issue and it has actually highlighted the issue is true of audio as well. I guess we had too many people on our test calls and the issue was less obvious with audio, either that or audio reconnected automatically on maximise and video did not.

2177_WebView2_BGWebcamIssue.zip

Will amend the bug title/desc to reflect this.

champnic commented 2 years ago

Thanks for the repro app @breenbob!

champnic commented 2 years ago

It looks like this is limited to UWP - WPF and WinUI 3 apps seems to continue working fine when minimized.

breenbob commented 2 years ago

Hi @champnic - can you give me an update on this issue as we hope to use this functionality in a production app soon? Is the issue with the WinUI2.8 WebView2.cpp wrapper?

champnic commented 2 years ago

Hey @breenbob - Unfortunately no update here either, and no specific timeline.