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 getDisplayMedia();
22}
23
24QList<QCapturableWindow> QWasmCapturableWindows::windows() const
25{
26 return m_capurableWindows;
27}
28
29void QWasmCapturableWindows::getDisplayMedia()
30{
31// populate windows from getDisplayMedia which includes windows from host platform.
32
33 emscripten::val navigator = emscripten::val::global("navigator");
34 emscripten::val mediaDevices = navigator["mediaDevices"];
35
36 if (mediaDevices.isNull() || mediaDevices.isUndefined()) {
37 qWarning() << "No media devices found";
38 return;
39 }
40
41 emscripten::val constraints = emscripten::val::object();
42
43 constraints.set("video", true);
44 constraints.set("selfBrowserSurface", std::string("include"));
45
46 // will ask for permissions!
47 qstdweb::PromiseCallbacks getDisplayMediaCallback{
48 // default
49 .thenFunc =
50 [this](emscripten::val stream) {
51 QUuid uid(QString::fromStdString(stream["id"].as<std::string>()));
52
53 m_capurableWindows.push_back(QCapturableWindowPrivate::create(
54 static_cast<QCapturableWindowPrivate::Id>(uid.toByteArray().toLong()),
55 QString::fromStdString(stream["id"].as<std::string>())));
56 },
57 .catchFunc =
58 [](emscripten::val) {
59 }
60 };
61
62 qstdweb::Promise::make(mediaDevices, QStringLiteral("getDisplayMedia"),
63 std::move(getDisplayMediaCallback), constraints);
64}
65
66bool QWasmCapturableWindows::isWindowValid(const QCapturableWindowPrivate &) const
67{
68 return m_capurableWindows.count() > 0;
69}
70
71QT_END_NAMESPACE