简体   繁体   English

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

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

I'm trying to get the user permission dialog to pop up for navigator.getUserMedia, which is called on an external page in an iframe.我正在尝试为 navigator.getUserMedia 弹出用户权限对话框,该对话框在 iframe 的外部页面上调用。 Currently the sample will show "Permission denied" without ever having presented a dialog to the user.目前,该示例将显示“Permission denied”,而不会向用户显示对话框。

This is a universal Windows app written in javascript.这是一个用 javascript 编写的通用 Windows 应用程序。 The webcam has been added to the capabilities.网络摄像头添加到功能中。

I've tried finding something similar to the geolocation function below.我试图找到类似于下面的地理定位功能的东西。 But I could not find anything for the webcam.但我找不到网络摄像头的任何东西。

Windows.Devices.Geolocation.Geolocator.requestAccessAsync

The code is very simple.代码非常简单。 It is an x-ms-webview that links to a webRTC sample.它是一个链接到 webRTC 示例的 x-ms-webview。

index.html索引.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>

The question has been answered here:问题已在此处得到解答:
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 https://social.msdn.microsoft.com/Forums/office/en-US/16e166d6-fd64-47cf-9e57-560c0d82b6df/how-to-resolve-a-permissiondeniederror-using-webrtc-in-xmswebview?forum= wp开发

You could also use PermissionRequested event to enable the webrtc feature that requires webcam capability.您还可以使用 PermissionRequested 事件来启用需要网络摄像头功能的 webrtc 功能。 If you use a permission dialog, use WebViewPermissionRequest.Defer to create a WebViewDeferredPermissionRequest which can be used after user input.如果您使用权限对话框,请使用 WebViewPermissionRequest.Defer 创建一个 WebViewDeferredPermissionRequest,可在用户输入后使用。 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 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();
        }
}

I dont work with x-ms-webview and dont like it, I was worked with HTA many years ago ....我不使用 x-ms-webview 也不喜欢它,我多年前曾与 HTA 合作过......

But this must inherit from window / iframe and it maybe have allow properties:但这必须继承自window / iframe并且它可能具有允许属性:

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

Because we have same default problem for iframes, by default they has no allow to getusermedia and u must set allow properties for them to work with usermedia...因为我们对 iframe 有相同的默认问题,默认情况下它们不允许getusermedia并且您必须设置允许属性以使它们与 usermedia 一起使用...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM