-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_protocol.cc
165 lines (123 loc) · 5.6 KB
/
http_protocol.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "http_protocol.hh"
#include <QJsonDocument>
#include <QJsonObject>
#include "http_service.hh"
#include "header.hh"
const std::string sever_address = std::string("http://") + SEVER_IP + ":3000/";
BaseProtocol::BaseProtocol(QObject* parent) : QObject(parent) {
connect(&watcher, &QFutureWatcher<QNetworkReply*>::finished,
[this]() { emit finished(watcher.result()); });
}
// QuickMeetingProtocol
QuickMeetingProtocol::QuickMeetingProtocol(QObject* parent)
: BaseProtocol(parent) {}
void QuickMeetingProtocol::MakeRequest(const ResponseHandler& handler) {
auto& service = HttpService::getInstance();
auto* reply =
service.post(QUrl(std::string(sever_address + "quick_meeting").c_str()), QByteArray());
connect(reply, &QNetworkReply::finished, [reply, handler]() {
handler(reply);
reply->deleteLater();
});
}
QuickMeetingProtocol::~QuickMeetingProtocol() {}
JoinMeetingProtocol::JoinMeetingProtocol(const std::string& user_id, const std::string& meeting_id, QObject* parent)
: BaseProtocol(parent), user_id_(user_id), meeting_id_(meeting_id) {}
JoinMeetingProtocol::~JoinMeetingProtocol() {}
void JoinMeetingProtocol::MakeRequest(const ResponseHandler& handler) {
auto& service = HttpService::getInstance();
// 创建一个包含 user_id 和 meeting_id 的 JSON 对象
QJsonObject json;
json["user_id"] = QString::fromStdString(user_id_);
json["meeting_id"] = QString::fromStdString(meeting_id_);
// 将 JSON 对象转换为 QByteArray
QJsonDocument doc(json);
QByteArray data = doc.toJson();
// 发送 POST 请求
auto* reply = service.post(QUrl(std::string(sever_address + "join_meeting").c_str()), data);
connect(reply, &QNetworkReply::finished, [reply, handler]() {
handler(reply);
reply->deleteLater();
});
}
LeaveMeetingProtocol::LeaveMeetingProtocol(const std::string& user_id, const std::string& meeting_id, QObject* parent)
: BaseProtocol(parent), user_id_(user_id), meeting_id_(meeting_id) {}
LeaveMeetingProtocol::~LeaveMeetingProtocol() {}
void LeaveMeetingProtocol::MakeRequest(const ResponseHandler& handler) {
auto& service = HttpService::getInstance();
// 创建一个包含 user_id 和 meeting_id 的 JSON 对象
QJsonObject json;
json["user_id"] = QString::fromStdString(user_id_);
json["meeting_id"] = QString::fromStdString(meeting_id_);
// 将 JSON 对象转换为 QByteArray
QJsonDocument doc(json);
QByteArray data = doc.toJson();
// 发送 POST 请求
auto* reply = service.post(QUrl(std::string(sever_address + "leave_meeting").c_str()), data);
connect(reply, &QNetworkReply::finished, [reply, handler]() {
handler(reply);
reply->deleteLater();
});
}
RequestUpStreamProtocol::RequestUpStreamProtocol(const std::string& user_id, const std::string& meeting_id, int media_type, QObject* parent) : BaseProtocol(parent), user_id_(user_id), meeting_id_(meeting_id), media_type_(media_type) {
}
RequestUpStreamProtocol::~RequestUpStreamProtocol() {
}
void RequestUpStreamProtocol::MakeRequest(const ResponseHandler& handler) {
auto& service = HttpService::getInstance();
// 创建一个包含 user_id 和 meeting_id 的 JSON 对象
QJsonObject json;
json["user_id"] = QString::fromStdString(user_id_);
json["meeting_id"] = QString::fromStdString(meeting_id_);
json["media_type"] = media_type_;
// 将 JSON 对象转换为 QByteArray
QJsonDocument doc(json);
QByteArray data = doc.toJson();
// 发送 POST 请求
auto* reply = service.post(QUrl(std::string(sever_address + "request_up_stream").c_str()), data);
connect(reply, &QNetworkReply::finished, [reply, handler]() {
handler(reply);
reply->deleteLater();
});
}
UserStatusProtocol::UserStatusProtocol(const std::string& meeting_id, const UserStatus& user_status, QObject* parent)
: BaseProtocol(parent), meeting_id_(meeting_id), user_status_(user_status) {}
UserStatusProtocol::~UserStatusProtocol() {}
void UserStatusProtocol::MakeRequest(const ResponseHandler& handler) {
auto& service = HttpService::getInstance();
QJsonObject json;
json["meeting_id"] = QString::fromStdString(meeting_id_);
json["user_id"] = QString::fromStdString(user_status_.user_id);
json["is_audio_on"] = user_status_.is_audio_on;
json["is_video_on"] = user_status_.is_video_on;
json["is_screen_on"] = user_status_.is_screen_on;
json["audio_stream_id"] = QString::fromStdString(user_status_.audio_stream_id);
json["video_stream_id"] = QString::fromStdString(user_status_.video_stream_id);
json["screen_stream_id"] = QString::fromStdString(user_status_.screen_stream_id);
QJsonDocument doc(json);
QByteArray data = doc.toJson();
auto* reply = service.post(QUrl(std::string(sever_address + "user_status").c_str()), data);
connect(reply, &QNetworkReply::finished, [reply, handler]() {
handler(reply);
reply->deleteLater();
});
}
RequestUserStatusProtocol::RequestUserStatusProtocol(const std::string& meeting_id, QObject* parent)
: BaseProtocol(parent), meeting_id_(meeting_id) {}
RequestUserStatusProtocol::~RequestUserStatusProtocol() {
}
void RequestUserStatusProtocol::MakeRequest(const ResponseHandler& handler) {
auto& service = HttpService::getInstance();
// 创建一个包含 user_id 和 meeting_id 的 JSON 对象
QJsonObject json;
json["meeting_id"] = QString::fromStdString(meeting_id_);
// 将 JSON 对象转换为 QByteArray
QJsonDocument doc(json);
QByteArray data = doc.toJson();
// 发送 POST 请求
auto* reply = service.post(QUrl(std::string(sever_address + "request_user_status").c_str()), data);
connect(reply, &QNetworkReply::finished, [reply, handler]() {
handler(reply);
reply->deleteLater();
});
}