Browse Source

添加 登录后自动进入第一个默认房间

zhuizhu 7 months ago
parent
commit
32ecb3cdcd
2 changed files with 27 additions and 1 deletions
  1. 1 1
      LearningSmartClient.pro
  2. 26 0
      MainPanel.cpp

+ 1 - 1
LearningSmartClient.pro

@@ -1,7 +1,7 @@
 QT       += core gui network svg
 QT += multimedia websockets
 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
-# CONFIG += console
+CONFIG += console
 CONFIG += c++17
 LIBS += -lshell32
 QT += opengl

+ 26 - 0
MainPanel.cpp

@@ -141,6 +141,32 @@ void MainPanel::setPushRoomId(const QString &id)
 
     // 重新进入房间
     chatView->initWebsocket(id);
+
+    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(); });
+    }
 }
 void MainPanel::setPlayerWidget(QWidget *newPlayer)
 {