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

标签 javascript iframe uwp win-universal-app webrtc

我正在尝试为 navigator.getUserMedia 弹出用户权限对话框,它在 iframe 的外部页面上调用。目前,示例将显示“权限被拒绝”,而不会向用户显示对话框。

这是一个用 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();
        }
}

关于javascript - 在 UWP javascript 应用程序的 iframe 中获取 getUserMedia 的用户权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40424172/

相关文章:

javascript - 获取外部文件信息(状态和大小)时出现问题

javascript - 如何将一个类更改为所有div?

javascript - 链接未在 iframe 中加载

html - 透明 div 内的非透明 iframe

xaml - 使用 MvvmCross 在 UWP 应用程序中打开新窗口

c# - Windows 10 上的 Google AdMob

javascript - 使用 javascript 从模板调用函数

javascript - 将 javascript 变量发送到框架中

javascript - 切换 iFrame 沙盒

uwp - 模板 10 : Hide HamBurgerMenu if no internet