2016-11-04 38 views
1

我試圖讓用戶權限對話框彈出navigator.getUserMedia,它在iframe中的外部頁面上調用。目前,樣本將顯示「權限被拒絕」,從未向用戶提供過對話。在UWP javascript應用程序中獲取iframe中getUserMedia的用戶權限

這是一個用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> 
+0

如果你想從一個iframe訪問數據/功能你必須做somethinkg像「(iframe_name).contentWindow」,這應該給你的iframe的數據和功能,如果它在同一個域上。 – user629283

+0

問題是它不在同一個域中。在未添加攝像頭功能時,我會收到NotFoundError。我只需要以某種方式自動授予webview或用戶權限對話框以顯示。 –

+1

應該顯示。你可以在jsfiddler上發佈它的例子嗎? – user629283

回答

1

的問題已經在這裏找到答案:
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

你也可以使用PermissionRequested事件啓用的WebRTC功能,需要攝像頭的能力。如果您使用權限對話框,請使用WebViewPermissionRequest.Defer創建可在用戶輸入後使用的WebViewDeferredPermissionRequest。欲瞭解更多信息,請參閱以下鏈接。
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(); 
     } 
} 
相關問題