Kstars

wsmedia.cpp
1/*
2 SPDX-FileCopyrightText: 2019 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "wsmedia.h"
8
9#include <QTimer>
10#include <QTemporaryFile>
11#include <KFormat>
12
13#include "indi_debug.h"
14
15namespace ISD
16{
17
18WSMedia::WSMedia(Camera *manager): m_Manager(manager)
19{
20 connect(&m_WebSocket, &QWebSocket::connected, this, &WSMedia::onConnected);
21 connect(&m_WebSocket, &QWebSocket::disconnected, this, &WSMedia::onDisconnected);
22 connect(&m_WebSocket, static_cast<void(QWebSocket::*)(QAbstractSocket::SocketError)>(&QWebSocket::error), this, &WSMedia::onError);
23
24}
25
26void WSMedia::connectServer()
27{
28 QUrl requestURL(m_URL);
29 m_WebSocket.open(requestURL);
30
31 qCInfo(KSTARS_INDI) << "Connecting to Websocket server at" << requestURL.toDisplayString();
32}
33
34void WSMedia::disconnectServer()
35{
36 m_WebSocket.close();
37}
38
39void WSMedia::onConnected()
40{
41 qCInfo(KSTARS_INDI) << "Connected to media Websocket server at" << m_URL.toDisplayString();
42
43 connect(&m_WebSocket, &QWebSocket::textMessageReceived, this, &WSMedia::onTextReceived);
44 connect(&m_WebSocket, &QWebSocket::binaryMessageReceived, this, &WSMedia::onBinaryReceived);
45
46 m_isConnected = true;
47 m_ReconnectTries = 0;
48
49 emit connected();
50}
51
52void WSMedia::onDisconnected()
53{
54 qCInfo(KSTARS_INDI) << "Disonnected from media Websocket server.";
55 m_isConnected = false;
56
57 disconnect(&m_WebSocket, &QWebSocket::textMessageReceived, this, &WSMedia::onTextReceived);
58 disconnect(&m_WebSocket, &QWebSocket::binaryMessageReceived, this, &WSMedia::onBinaryReceived);
59
60 m_sendBlobs = true;
61
62 emit disconnected();
63}
64
65void WSMedia::onError(QAbstractSocket::SocketError error)
66{
67 qCritical(KSTARS_INDI) << "Media Websocket connection error" << m_WebSocket.errorString();
70 {
71 if (m_ReconnectTries++ < RECONNECT_MAX_TRIES)
72 QTimer::singleShot(RECONNECT_INTERVAL, this, SLOT(connectServer()));
73 }
74}
75
76void WSMedia::onTextReceived(const QString &message)
77{
78 extension = message;
79}
80
81void WSMedia::onBinaryReceived(const QByteArray &message)
82{
83 emit newFile(message, extension);
84}
85
86}
ISD is a collection of INDI Standard Devices.
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void binaryMessageReceived(const QByteArray &message)
void connected()
void disconnected()
QAbstractSocket::SocketError error() const const
void textMessageReceived(const QString &message)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.