// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include <QGuiApplication>
#include <QQmlEngine>
#include <QQuickItem>
#include <algorithm>
#include <cctype>
#include <chrono>
#include <cstdlib>
#include <cstring>
#include <optional>
#include <string_view>
#include <thread>
#include <utility>
#include "CallDevices.h"
#include "ChatPage.h"
#include "Logging.h"
#include "UserSettingsPage.h"
#include "WebRTCSession.h"
#include "voip/ScreenCastPortal.h"
#ifdef GSTREAMER_AVAILABLE
extern "C"
{
#include "gst/gl/gstgldisplay.h"
#include "gst/gst.h"
#include "gst/sdp/sdp.h"
#define GST_USE_UNSTABLE_API
#include "gst/webrtc/webrtc.h"
}
#if !GST_CHECK_VERSION(1, 20, 0)
#define gst_element_request_pad_simple gst_element_get_request_pad
#endif
#endif
// https://github.com/vector-im/riot-web/issues/10173
#define STUN_SERVER "stun://turn.matrix.org:3478"
using webrtc::CallType;
using webrtc::ScreenShareType;
using webrtc::State;
WebRTCSession::WebRTCSession()
: devices_(CallDevices::instance())
{
// qmlRegisterUncreatableMetaObject(webrtc::staticMetaObject,
// "im.nheko",
// 1,
// 0,
// "CallType",
// QStringLiteral("Can't instantiate enum"));
// qmlRegisterUncreatableMetaObject(webrtc::staticMetaObject,
// "im.nheko",
// 1,
// 0,
// "ScreenShareType",
// QStringLiteral("Can't instantiate enum"));
// qmlRegisterUncreatableMetaObject(webrtc::staticMetaObject,
// "im.nheko",
// 1,
// 0,
// "WebRTCState",
// QStringLiteral("Can't instantiate enum"));
connect(this, &WebRTCSession::stateChanged, this, &WebRTCSession::setState);
init();
}
bool
WebRTCSession::init(std::string *errorMessage)
{
#ifdef GSTREAMER_AVAILABLE
if (initialised_)
return true;
GError *error = nullptr;
if (