|
|
@@ -2,15 +2,24 @@
|
|
|
#include <QSplitter>
|
|
|
#include <QVBoxLayout>
|
|
|
#include <QListWidget>
|
|
|
-#include "widgets/userprofilewidget.h"
|
|
|
-#include "widgets/chatView/chatwindow.h"
|
|
|
+
|
|
|
+#include <util/jsonmapper.h>
|
|
|
+
|
|
|
+#include <QDebug>
|
|
|
+
|
|
|
+#include <qtpromise/qpromise.h>
|
|
|
+#include <qtpromise/qpromisefuture.h>
|
|
|
+#include <qtpromise/qpromisehelpers.h>
|
|
|
+
|
|
|
#include "widgets/bubbletip.h"
|
|
|
+#include "widgets/chatView/chatwindow.h"
|
|
|
+#include "widgets/maskoverlay.h"
|
|
|
+#include "widgets/userprofilewidget.h"
|
|
|
+
|
|
|
+#include "AvPlayer2/PlayWidget.h"
|
|
|
#include "api/roomapi.h"
|
|
|
-#include "api/userapi.h"
|
|
|
#include "appevent.h"
|
|
|
#include "ui/av_recorder.h"
|
|
|
-#include "AvPlayer2/PlayWidget.h"
|
|
|
-#include <QDebug>
|
|
|
|
|
|
MainPanel::MainPanel(QWidget *parent)
|
|
|
: QWidget(parent)
|
|
|
@@ -19,7 +28,8 @@ MainPanel::MainPanel(QWidget *parent)
|
|
|
{
|
|
|
// setupUI
|
|
|
userProfile = new UserProfileWidget(this);
|
|
|
- chatView = new ChatWindow();
|
|
|
+ webSocketClient = new WebSocketClient(this);
|
|
|
+ chatView = new ChatWindow(webSocketClient);
|
|
|
chatView->setMinimumWidth(400);
|
|
|
|
|
|
QWidget *rightWidget = new QWidget;
|
|
|
@@ -28,10 +38,10 @@ MainPanel::MainPanel(QWidget *parent)
|
|
|
vbox->addWidget(userProfile, 0);
|
|
|
vbox->addWidget(chatView, 1);
|
|
|
|
|
|
- roomListWidget = new QListWidget;
|
|
|
+ m_roomListWidget = new QListWidget;
|
|
|
splitter = new QSplitter(Qt::Horizontal, this);
|
|
|
playerContainer = new QWidget(this);
|
|
|
- splitter->addWidget(roomListWidget);
|
|
|
+ splitter->addWidget(m_roomListWidget);
|
|
|
splitter->addWidget(playerContainer);
|
|
|
splitter->addWidget(rightWidget);
|
|
|
splitter->setStretchFactor(0, 10);
|
|
|
@@ -49,6 +59,37 @@ MainPanel::MainPanel(QWidget *parent)
|
|
|
userProfile->setStatus(connected ? "在线" : "离线");
|
|
|
}
|
|
|
});
|
|
|
+ connect(m_roomListWidget, &QListWidget::itemDoubleClicked, this, &MainPanel::roomItemChanged);
|
|
|
+ connect(userProfile, &UserProfileWidget::logoutClicked, this, &MainPanel::logoutClicked);
|
|
|
+ connect(webSocketClient, &WebSocketClient::liveStatus, this, [this](const QString &msg) {
|
|
|
+ // 这里可以处理 liveStatus 相关逻辑
|
|
|
+ QJsonParseError err;
|
|
|
+ QJsonDocument doc = QJsonDocument::fromJson(msg.toUtf8(), &err);
|
|
|
+ if (err.error != QJsonParseError::NoError || !doc.isObject()) {
|
|
|
+ qDebug() << "[MainPanel] liveStatus: 解析失败" << err.errorString();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ QJsonObject obj = doc.object();
|
|
|
+ int liveStatus = obj.value("liveStatus").toInt(0); // 默认-1
|
|
|
+ if (liveStatus == 1) {
|
|
|
+ qDebug() << "[MainPanel] liveStatus: 直播中";
|
|
|
+ if (chatView) {
|
|
|
+ const QString id = webSocketClient->roomId();
|
|
|
+ if (PlayWidget *playWidget = qobject_cast<PlayWidget *>(playerWidget)) {
|
|
|
+ if (!playWidget->isPlaying()) {
|
|
|
+ playWidget->startToPlay("rtmp://106.55.186.74:1935/stream/V1/" + id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 你的处理逻辑
|
|
|
+ } else if (liveStatus == 2) {
|
|
|
+ qDebug() << "[MainPanel] liveStatus: 未开播";
|
|
|
+ // 你的处理逻辑
|
|
|
+ } else {
|
|
|
+ qDebug() << "[MainPanel] liveStatus: 未知状态" << liveStatus;
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
MainPanel::~MainPanel()
|
|
|
@@ -58,7 +99,43 @@ MainPanel::~MainPanel()
|
|
|
userProfile = nullptr;
|
|
|
}
|
|
|
}
|
|
|
+void MainPanel::setRole(const QStringList &roleList)
|
|
|
+{
|
|
|
+ QWidget *newPlayer = nullptr;
|
|
|
+ if (roleList.contains("role.admin")) {
|
|
|
+ newPlayer = new AvRecorder(this);
|
|
|
+ } else {
|
|
|
+ newPlayer = new PlayWidget(this);
|
|
|
+ }
|
|
|
+ setPlayerWidget(newPlayer);
|
|
|
+
|
|
|
+ // 如果是管理也就是教师 直接过滤当前教师的选项
|
|
|
+ if (AppEvent::instance()->hasRole("role.admin")) {
|
|
|
+ // roomInfo.ownerId = AppEvent::instance()->userId();
|
|
|
+ m_roomListWidget->hide();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ m_roomListWidget->show();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置初始化信息
|
|
|
+ const QString &name = AppEvent::instance()->userName();
|
|
|
+ userProfile->setUsername(name);
|
|
|
+}
|
|
|
|
|
|
+void MainPanel::setPushRoomId(const QString &id)
|
|
|
+{
|
|
|
+ // 推流配置
|
|
|
+ if (AvRecorder *avRecorder = qobject_cast<AvRecorder *>(playerWidget)) {
|
|
|
+ SettingsPage::Param param;
|
|
|
+ param.liveUrl = "rtmp://106.55.186.74:1935/stream/V1";
|
|
|
+ param.liveName = id.toStdString();
|
|
|
+ avRecorder->setSettings(param);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 重新进入房间
|
|
|
+ chatView->initWebsocket(id);
|
|
|
+}
|
|
|
void MainPanel::setPlayerWidget(QWidget *newPlayer)
|
|
|
{
|
|
|
if (playerWidget) {
|
|
|
@@ -82,13 +159,48 @@ void MainPanel::setPlayerWidget(QWidget *newPlayer)
|
|
|
vbox->addWidget(playerWidget);
|
|
|
}
|
|
|
|
|
|
-void MainPanel::setRole(const QStringList &roleList)
|
|
|
+void MainPanel::roomItemChanged(QListWidgetItem *item)
|
|
|
{
|
|
|
- QWidget *newPlayer = nullptr;
|
|
|
- if (roleList.contains("role.admin")) {
|
|
|
- newPlayer = new AvRecorder(this);
|
|
|
- } else {
|
|
|
- newPlayer = new PlayWidget(this);
|
|
|
+ if (item) {
|
|
|
+ const QString id = item->data(Qt::UserRole + 100).value<QString>();
|
|
|
+
|
|
|
+ if (!playerWidget) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // // 推流配置
|
|
|
+ // if (AvRecorder *avRecorder = qobject_cast<AvRecorder *>(playerWidget)) {
|
|
|
+ // SettingsPage::Param param;
|
|
|
+ // param.liveUrl = "rtmp://106.55.186.74:1935/stream/V1";
|
|
|
+ // param.liveName = id.toStdString();
|
|
|
+ // avRecorder->setSettings(param);
|
|
|
+ // }
|
|
|
+ // 拉取视频流程
|
|
|
+ if (PlayWidget *playWidget = qobject_cast<PlayWidget *>(playerWidget)) {
|
|
|
+ MaskOverlay::instance()->show(nullptr, 0, MaskOverlay::ActiveWindow);
|
|
|
+
|
|
|
+ QFuture<HttpResponse> getRoomFuture = getRoomApi(id);
|
|
|
+ QtPromise::QPromise<HttpResponse> roomListPromise = QtPromise::resolve(getRoomFuture);
|
|
|
+
|
|
|
+ roomListPromise
|
|
|
+ .then([this, playWidget, id](const HttpResponse &response) {
|
|
|
+ qDebug() << response.code << response.data << response.message;
|
|
|
+ if (response.code != 0) {
|
|
|
+ BubbleTip::showTip(this, response.message, BubbleTip::Top, 3000);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ RoomInfo roomInfo = JsonMapper::formJsonEx<RoomInfo>(response.data.toObject());
|
|
|
+
|
|
|
+ qDebug() << "roomInfo.liveStatus.has_value()"
|
|
|
+ << roomInfo.liveStatus.has_value();
|
|
|
+
|
|
|
+ int status = roomInfo.liveStatus.value_or(0);
|
|
|
+ if (status == 1) {
|
|
|
+ qDebug() << "open" << ("rtmp://106.55.186.74:1935/stream/V1/" + id);
|
|
|
+ playWidget->startToPlay("rtmp://106.55.186.74:1935/stream/V1/" + id);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .finally([]() { MaskOverlay::instance()->hide(); });
|
|
|
+ }
|
|
|
}
|
|
|
- setPlayerWidget(newPlayer);
|
|
|
-}
|
|
|
+}
|