4

当QtWebEngine(使用QML插件或不使用QML插件时)时,如何允许WebRTC网络摄像头请求?

webengine.qml

import QtQuick 2.1
import QtQuick.Controls 1.1
import QtWebEngine 1.0

ApplicationWindow {
    width: 800
    height: 600
    color: "lightgray"
    visible: true
    WebEngineView {
        id: webview
        url: "https://opentokrtc.com/test"
        anchors.fill: parent
    }
}

在我的 Mac Yosemite 上,运行以下命令:

/usr/local/Cellar/qt5/5.4.0/bin/qmlscene webengine.qml 

但视频不会开始,因为它正在等待“允许”相机

在此处输入图像描述

在浏览器上你会有这个

在此处输入图像描述

有没有办法以编程方式设置 Chromium Web 引擎策略,例如VideoCaptureAllowed

4

3 回答 3

3

将此添加到您的 WebEngineView 项目以从所有来源授予任何请求的功能,或选择性地将其限制为特定来源和特定功能:

    onFeaturePermissionRequested: {
        grantFeaturePermission(securityOrigin, feature, true);
    }
于 2017-01-28T09:43:32.580 回答
2

你需要使用QtWebEngine.experimental请试试这个。

import QtQuick 2.4
import QtQuick.Window 2.2
import QtWebEngine 1.0
import QtWebEngine.experimental 1.0
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
import QtQuick.Layouts 1.1
import QtQuick.Controls.Private 1.0

Window {
    visible: true
    WebEngineView {
        id: webEngineView
        url: "https://test.webrtc.org/"
        anchors.fill: parent
        anchors.margins: 10
        experimental.onFeaturePermissionRequested: {
            console.log("request")
            experimental.grantFeaturePermission(securityOrigin, feature, true);
        }

        readonly property string hideElementsJS: "
            function hideElement(id) {
                const el = document.getElementById(id);
                if (el) {
                    el.style.display = 'none';
                }
            }

            function hideElementsByClass(className) {
                const elList = document.getElementsByClassName(className);
                for (var i = 0, n = elList.length; i < n; ++i) {
                    elList[i].style.display = 'none';
                }
            }

            hideElement('hnArea');
            hideElement('lxSocialBarWrapper');
            hideElement('footerContent');
            hideElement('ftDisclaimers');
            hideElement('bottomNav');
            hideElement('topLinks');
            hideElement('rightMenuButtons');

            hideElementsByClass('footerText');
            hideElementsByClass('disclaimers');
        "

        onLoadingChanged: {
            if(loadRequest.status === WebEngineView.LoadSucceededStatus) {
                console.log("start")
                runJavaScript(hideElementsJS);
                console.log("stop")
            }
        }
    }
}
于 2015-07-23T13:50:20.503 回答
1

打开fancybrowser项目在mainwindow.cpp函数内添加MainWindow::MainWindow(const QUrl& url)

connect(view->page(), SIGNAL(featurePermissionRequested(QUrl,QWebEnginePage::Feature)),SLOT(test(QUrl,QWebEnginePage::Feature)));

还添加

void MainWindow::test(QUrl q, QWebEnginePage::Feature f) {
    view->page()->setFeaturePermission(q, f, 
    QWebEnginePage::PermissionGrantedByUser); 
}

在 mainwindow.cpp 和 mainwindow.h 下面

受保护的插槽:

void test(QUrl q, QWebEnginePage::Feature f);

然后一切正常!

于 2016-01-31T07:39:56.633 回答