Jellyfin Qt
QML Library for interacting with the Jellyfin multimedia server
Loading...
Searching...
No Matches
websocket.h
Go to the documentation of this file.
1/*
2Sailfin: a Jellyfin client written using Qt
3Copyright (C) 2021 Chris Josten
4
5This library is free software; you can redistribute it and/or
6modify it under the terms of the GNU Lesser General Public
7License as published by the Free Software Foundation; either
8version 2.1 of the License, or (at your option) any later version.
9
10This library is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public
16License along with this library; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19#ifndef JELLYFIN_WEBSOCKET_H
20#define JELLYFIN_WEBSOCKET_H
21
22#include <QJsonDocument>
23#include <QJsonArray>
24#include <QJsonObject>
25#include <QJsonValue>
26#include <QDebug>
27#include <QObject>
28#include <QtGlobal>
29#include <QTimer>
30#include <QUuid>
31
32#include <QtWebSockets/QWebSocket>
33
34#include "apiclient.h"
35
36Q_DECLARE_LOGGING_CATEGORY(jellyfinWebSocket);
37
38namespace Jellyfin {
39class ApiClient;
40
41
42namespace DTO {
43 class UserItemDataDto;
44 using UserData = UserItemDataDto;
45}
52class WebSocket : public QObject {
53 Q_OBJECT
54public:
61 explicit WebSocket(ApiClient *client);
88 Q_PROPERTY(QAbstractSocket::SocketState state READ state NOTIFY stateChanged)
89 Q_ENUM(MessageType)
90
91 QAbstractSocket::SocketState state() const {
92 return m_webSocket.state();
93 }
94public slots:
95 void open();
98private slots:
99 void textMessageReceived(const QString &message);
100 void onConnected();
101 void onDisconnected();
102
103 void sendKeepAlive();
104 void onWebsocketStateChanged(QAbstractSocket::SocketState newState) { emit stateChanged(newState); }
105signals:
106 void commandReceived(QString command, QVariantMap args);
107 void stateChanged(QAbstractSocket::SocketState newState);
108
109protected:
111 QWebSocket m_webSocket;
112
117
118
119 void setupKeepAlive(int data);
120 void sendMessage(MessageType type, QJsonValue data = QJsonValue());
121 QString generateMessageId();
122};
123}
124
125#endif // JELLYFIN_WEBSOCKET_H
An Api client for Jellyfin. Handles requests and authentication.
Definition apiclient.h:90
Keeps a connection with the Jellyfin server to receive real time updates.
Definition websocket.h:52
WebSocket(ApiClient *client)
WebSocket creates a webSocket for a Jellyfin server to handle real time updates.
Definition websocket.cpp:32
void stateChanged(QAbstractSocket::SocketState newState)
void open()
Definition websocket.cpp:55
QTimer m_keepAliveTimer
Definition websocket.h:113
void commandReceived(QString command, QVariantMap args)
int m_sessionInfoSubscribeCount
Definition websocket.h:116
ApiClient * m_apiClient
Definition websocket.h:110
MessageType
Definition websocket.h:62
@ UserDataChanged
Server to client: user data for an item has changed.
Definition websocket.h:74
@ ForceKeepAlive
Server to client: instruct client to send periodical KeepAlive messages.
Definition websocket.h:66
@ SessionsStop
Client to server: unsubscribe from playback session updates.
Definition websocket.h:82
@ KeepAlive
Client to server: keep the connection alive.
Definition websocket.h:70
@ Sessions
Server to client: session information has changed.
Definition websocket.h:86
@ SessionsStart
Client to server: Subscribe to playback update sessions.
Definition websocket.h:78
QAbstractSocket::SocketState state
Definition websocket.h:88
QWebSocket m_webSocket
Definition websocket.h:111
void setupKeepAlive(int data)
Definition websocket.cpp:176
int m_reconnectAttempt
Definition websocket.h:115
void unsubscribeToSessionInfo()
Definition websocket.cpp:77
QString generateMessageId()
Definition websocket.cpp:184
void sendMessage(MessageType type, QJsonValue data=QJsonValue())
Definition websocket.cpp:188
void subscribeToSessionInfo()
Definition websocket.cpp:68
QTimer m_retryTimer
Definition websocket.h:114
UserItemDataDto UserData
Definition apiclient.h:58
Q_DECLARE_LOGGING_CATEGORY(jellyfinWebSocket)