在 UWP javascript 应用的 iframe 中获取 getUserMedia 的用户权限

Get user permission for getUserMedia in iframe within a UWP javascript app

我正在尝试为 navigator.getUserMedia 弹出用户权限对话框,这是在 iframe 的外部页面上调用的。目前,示例将显示 "Permission denied",而不会向用户显示对话框。

这是用 javascript 编写的通用 Windows 应用程序。网络摄像头添加到功能中。

我试过找到与下面的地理定位功能类似的东西。但是我找不到网络摄像头的任何东西。

Windows.Devices.Geolocation.Geolocator.requestAccessAsync

代码非常简单。它是一个链接到 webRTC 示例的 x-ms-webview。

index.html

<html>
<head>
</head>
<body>
   <x-ms-webview style="left: 0px; top: 0px; width: 100%; height: 100%; position: absolute;" src="https://webrtc.github.io/samples/src/content/getusermedia/gum/"></x-ms-webview>
</body>
</html>

此处已回答问题:
https://social.msdn.microsoft.com/Forums/office/en-US/16e166d6-fd64-47cf-9e57-560c0d82b6df/how-to-resolve-a-permissiondeniederror-using-webrtc-in-xmswebview?forum=wpdevelop

You could also use PermissionRequested event to enable the webrtc feature that requires webcam capability. If you use a permission dialog, use WebViewPermissionRequest.Defer to create a WebViewDeferredPermissionRequest which can be used after user input. For more information, please refer to the following links.
https://msdn.microsoft.com/en-us/windows/uwp/controls-and-patterns/web-view https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/WebView

document.getElementById("webview").addEventListener("MSWebViewPermissionRequested", managePermissionRequest)
function managePermissionRequest(e) {
        if (e.permissionRequest.type == "media") {
                e.permissionRequest.allow();
        }
}

我不使用 x-ms-webview 也不喜欢它,我在 HTA 工作很多年了....

但这必须继承自 window/iframe 并且它可能有 allow 属性:

<!--Allow camera and microphone access within the context of this iframe-->
<iframe src="https://example.com" allow="camera *;microphone *"></iframe>

因为我们对 iframe 有同样的默认问题,默认情况下它们不允许getusermedia 并且您必须设置允许属性才能与 usermedia 一起使用...