Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwasmcapturablewindows.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include "private/qcapturablewindow_p.h"
6#include <QtCore/private/qstdweb_p.h>
7#include <QGuiApplication>
8#include <QWindow>
9#include <QUuid>
10
11#include <QDebug>
12
14
15QWasmCapturableWindows::QWasmCapturableWindows()
16{
17 m_capurableWindows.push_back(QCapturableWindowPrivate::create(
18 static_cast<QCapturableWindowPrivate::Id>(111),
19 QStringLiteral("Any Window")));
20}
21
22QList<QCapturableWindow> QWasmCapturableWindows::windows() const
23{
24 return m_capurableWindows;
25}
26
27void QWasmCapturableWindows::getDisplayMedia()
28{
29// populate windows from getDisplayMedia which includes windows from host platform.
30
31 emscripten::val navigator = emscripten::val::global("navigator");
32 emscripten::val mediaDevices = navigator["mediaDevices"];
33
34 if (mediaDevices.isNull() || mediaDevices.isUndefined()) {
35 qWarning() << "No media devices found";
36 return;
37 }
38
39 emscripten::val constraints = emscripten::val::object();
40
41 constraints.set("video", true);
42 constraints.set("selfBrowserSurface", std::string("include"));
43
44 // will ask for permissions!
45 qstdweb::PromiseCallbacks getDisplayMediaCallback{
46 // default
47 .thenFunc =
48 [this](emscripten::val stream) {
49 QUuid uid(QString::fromStdString(stream["id"].as<std::string>()));
50
51 m_capurableWindows.push_back(QCapturableWindowPrivate::create(
52 static_cast<QCapturableWindowPrivate::Id>(uid.toByteArray().toLong()),
53 QString::fromStdString(stream["id"].as<std::string>())));
54 },
55 .catchFunc =
56 [](emscripten::val) {
57 }
58 };
59 qstdweb::Promise::make(mediaDevices, QStringLiteral("getDisplayMedia"),
60 std::move(getDisplayMediaCallback), constraints);
61}
62
63bool QWasmCapturableWindows::isWindowValid(const QCapturableWindowPrivate &) const
64{
65 return m_capurableWindows.count() > 0;
66}
67
68QT_END_NAMESPACE
Combined button and popup list for selecting options.