瀏覽代碼

完善直播

dusenyao 3 年之前
父節點
當前提交
fdad529e5b
共有 6 個文件被更改,包括 133 次插入32 次删除
  1. 4 0
      src/api/live.js
  2. 7 0
      src/icons/svg/draw.svg
  3. 5 0
      src/icons/svg/push.svg
  4. 7 0
      src/icons/svg/share.svg
  5. 86 16
      src/views/live/index.vue
  6. 24 16
      src/views/live/live.js

+ 4 - 0
src/api/live.js

@@ -30,6 +30,10 @@ export function GetLiveRoomStudentList(data) {
   });
 }
 
+/**
+ * 学员退出直播间
+ * @param {Object} data { task_id 任务ID, room_user_id 学员所在直播间的用户ID}
+ */
 export function StudentExitLiveRoom(data) {
   let params = getRequestParams('live_room-live_room_dispatch-StudentExitLiveRoom');
 

+ 7 - 0
src/icons/svg/draw.svg

@@ -0,0 +1,7 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M20 3H4C3.44772 3 3 3.44772 3 4V12C3 12.5523 3.44772 13 4 13H20C20.5523 13 21 12.5523 21 12V4C21 3.44772 20.5523 3 20 3Z" stroke="white" stroke-width="1.5" stroke-linejoin="round"/>
+<path d="M7 6.5H11" stroke="white" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
+<path d="M7 9.5H17" stroke="white" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
+<path d="M4 22L6.44445 19H17.3333L20 22" stroke="white" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
+<path d="M12 13V22" stroke="white" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
+</svg>

+ 5 - 0
src/icons/svg/push.svg

@@ -0,0 +1,5 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M24 0H0V24H24V0Z" fill="white" fill-opacity="0.01"/>
+<path d="M21.5 2.5L14.85 21.5L11.05 12.95L2.5 9.15L21.5 2.5Z" stroke="white" stroke-width="1.5" stroke-linejoin="round"/>
+<path d="M21.5 2.5L11.05 12.95" stroke="white" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
+</svg>

+ 7 - 0
src/icons/svg/share.svg

@@ -0,0 +1,7 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M24 0H0V24H24V0Z" fill="white" fill-opacity="0.01"/>
+<path d="M10.5 19.5C10.5 15.0817 6.9183 11.5 2.5 11.5" stroke="white" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
+<path d="M6.5 19.5C6.5 17.2908 4.70914 15.5 2.5 15.5" stroke="white" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
+<path fill-rule="evenodd" clip-rule="evenodd" d="M2.75 20.5C3.44036 20.5 4 19.9404 4 19.25C4 18.5597 3.44036 18 2.75 18C2.05964 18 1.5 18.5597 1.5 19.25C1.5 19.9404 2.05964 20.5 2.75 20.5Z" fill="white"/>
+<path d="M2 8.0283V4H22V20H14.3856" stroke="white" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
+</svg>

+ 86 - 16
src/views/live/index.vue

@@ -9,11 +9,13 @@
           <span class="live-name">{{ roomData.name }}</span>
         </div>
         <div>
-          <el-button @click="startLive">开启直播</el-button>
-          <el-button @click="stopLive">结束直播</el-button>
+          <el-button v-if="userType === 'TEACHER'" @click="startLive">开启直播</el-button>
+          <el-button v-if="userType === 'TEACHER'" @click="stopLive">结束直播</el-button>
+          <el-button v-if="userType === 'TEACHER'" @click="publishStream">推流</el-button>
         </div>
       </div>
     </div>
+    <!-- 主容器 -->
     <div class="live-container">
       <!--左侧-->
       <div class="live-container-left">
@@ -38,19 +40,30 @@
           </div>
         </div>
         <div class="button-group">
-          <div>
-            <!-- <el-button>群组讨论</el-button>
+          <div class="button-group-left">
+            <span v-if="userType === 'TEACHER'" @click="publishShareStream">
+              <svg-icon icon-class="share" />
+            </span>
+            <span v-if="userType === 'TEACHER'" @click="showDrawSetting">
+              <svg-icon icon-class="draw"></svg-icon>
+            </span>
+            <span v-if="userType === 'TEACHER'">
+              <svg-icon icon-class="push"></svg-icon>
+            </span>
+          </div>
+          <!-- <el-button>群组讨论</el-button>
             <el-button>推送课件</el-button> -->
-            <el-button @click="showDrawSetting">屏幕画笔</el-button>
+          <!-- <el-button @click="showDrawSetting">屏幕画笔</el-button>
           </div>
           <div>
             <el-button @click="publishShareStream">共享屏幕</el-button>
-          </div>
+          </div> -->
+          <div class="button-group-right"></div>
         </div>
         <div class="live-container-left-chat">
           <div class="chat-top">
-            <span>聊天窗口</span>
-            <a @click="chatBans">群体禁言</a>
+            <span>聊天</span>
+            <a @click="chatBans">禁言</a>
           </div>
           <div class="chat-window">
             <ul class="chat-window-ul">
@@ -175,6 +188,9 @@ export default {
       true
     );
   },
+  beforeDestroy() {
+    // document.querySelector('script[src="https://image.csslcloud.net/js/dpc.js"]').remove();
+  },
   methods: {
     // 加载直播所需 SDK,加载完成后才能初始化
     downloadWebSDK() {
@@ -249,6 +265,17 @@ export default {
       common.startLive();
     },
 
+    getLiveStat() {
+      common.getLiveStat({
+        success: data => {
+          console.log('直播开启状态', data);
+        },
+        fail: str => {
+          console.log('直播关闭状态或查询直播失败', str);
+        }
+      });
+    },
+
     // 推送桌面共享
     publishShareStream() {
       common.publishShareStream();
@@ -306,6 +333,10 @@ export default {
       StudentExitLiveRoom({ task_id: this.task_id, room_user_id }).then(() => {
         this.getLiveRoomStudentList();
       });
+    },
+
+    publishStream() {
+      common.publishStream('main');
     }
   }
 };
@@ -313,10 +344,18 @@ export default {
 
 <style lang="scss">
 @import '~@/styles/mixin.scss';
+$live-bc: #3d3938;
 
 .live {
   @include container;
 
+  &-top {
+    background-color: #fff;
+    padding: 24px 32px;
+    border-top-left-radius: 8px;
+    border-top-right-radius: 8px;
+  }
+
   &-page-title {
     font-size: 12px;
   }
@@ -339,27 +378,26 @@ export default {
   &-container {
     display: flex;
     justify-content: left;
-    margin-top: 17px;
 
     &-left {
       width: 832px;
+      background-color: #fff;
+      border-radius: 8px;
 
       #student {
         width: 100%;
         height: 468px;
-        margin-bottom: 14px;
         border: 1px solid #ccc;
         position: relative;
-        background-color: #3d3938;
+        background-color: $live-bc;
       }
 
       #draw-parent {
         width: 100%;
         height: 468px;
-        margin-bottom: 14px;
         border: 1px solid #ccc;
         position: relative;
-        background-color: #3d3938;
+        background-color: $live-bc;
 
         // 设置屏幕画笔
         .draw-setting {
@@ -438,14 +476,36 @@ export default {
       .button-group {
         display: flex;
         justify-content: space-between;
+        height: 48px;
+        background-color: #4d4d4d;
+        padding: 0 15px;
+        border-bottom-right-radius: 5px;
+        border-bottom-left-radius: 5px;
+
+        .svg-icon {
+          font-size: 20px;
+        }
+
+        &-left {
+          > span {
+            display: inline-block;
+            height: 100%;
+            padding: 14px 16px;
+            cursor: pointer;
+
+            &:active,
+            &:hover {
+              background-color: #3d3d3d;
+            }
+          }
+        }
       }
 
       // 聊天窗口
       &-chat {
-        margin-top: 15px;
         height: 278px;
         border: 1px solid #ccc;
-        border-radius: 8px;
+        border-bottom-left-radius: 8px;
         display: flex;
         flex-direction: column;
         justify-content: space-between;
@@ -455,6 +515,7 @@ export default {
           justify-content: space-between;
           padding: 15px 15px 10px;
           border-bottom: 1px solid #e6e6e6;
+          color: #959595;
         }
 
         .chat-window {
@@ -476,18 +537,27 @@ export default {
             }
           }
         }
+
+        .chat-speak {
+          padding: 16px;
+        }
       }
     }
 
     &-right {
+      padding: 8px;
+      background-color: #2c2c2c;
+      border-end-end-radius: 8px;
+
       #live {
         width: 352px;
         height: 198px;
+        background-color: $live-bc;
       }
 
       .student-list {
         width: 100%;
-        padding: 24px;
+        padding: 24px 16px;
         margin-top: 2px;
         height: calc(100% - 200px);
         background-color: #2c2c2c;

+ 24 - 16
src/views/live/live.js

@@ -139,15 +139,13 @@ export function initListener(vue) {
       type: 'success'
     });
     vue.roomData = data;
+    // 初始化画板需要的数据
     let canvasInitData = {
       allowDraw: data.user.role === 'presenter', // 是否具有书写画笔权限(讲师权限) true / false
       id: 'draw-parent',
-      pptDisplay: 0 // 文档展示方式。默认0,按窗口  1, 按宽度
+      pptDisplay: 1, // 文档展示方式。默认0,按窗口  1, 按宽度
+      liveId: data.live.status === 1 ? data.live.id : '' // 如果直播已经开始,需将直播 id 传入 sdk 中
     };
-    // 如果直播已经开始,需将直播id传入sdk中,
-    if (data.live.status === 1) {
-      canvasInitData.liveId = data.live.id;
-    }
     // 初始化画板
     rtc.canvasInit(canvasInitData);
   });
@@ -181,11 +179,10 @@ export function initListener(vue) {
         tryStream: stream,
         success: function (stream) {
           // 订阅流成功
-          console.log(stream.streamType());
-          let streamId = stream.id(); // 获取流id
-          console.log('订阅流成功', streamId);
-          stream.show(stream.streamType() === 0 ? 'live' : 'student', 'contain'); // 将流显示到id为 live 的盒子中
-          if (stream.streamType() === 10) {
+          let streamType = stream.streamType();
+          console.log('订阅流成功', stream.id()); // 获取流id
+          stream.show(streamType === 0 ? 'live' : 'student', 'contain'); // 将流显示到id为 live 的盒子中
+          if (streamType === 10 || streamType === 1) {
             vue.connection = true;
           }
         },
@@ -204,11 +201,19 @@ export function initListener(vue) {
   // 直播未开始,不能推流
   rtc.on('not_live', function () {
     console.log('直播未开始,不能推流');
+    Message({
+      message: '直播未开始,不能推流',
+      type: 'warning'
+    });
   });
 
   // 推流前查询直播状态失败,导致没有推流
   rtc.on('local_stream_publish_failed', function () {
     console.log('推流前查询直播状态失败,导致没有推流');
+    Message({
+      message: '推流前查询直播状态失败,导致没有推流',
+      type: 'warning'
+    });
   });
 
   // 房间全量信息事件(人员进出时广播)
@@ -224,10 +229,6 @@ export function initListener(vue) {
 
   rtc.on('end_stream', str => {
     console.log('直播已关闭', str);
-    Message({
-      message: '直播已关闭',
-      type: 'success'
-    });
   });
 
   rtc.on('switch_user_settings', settingData => {
@@ -258,7 +259,7 @@ export function initListener(vue) {
   // 监听通知移除流事件
   rtc.on('stream_removed', function (stream) {
     console.log('监听通知移除流事件');
-    if (stream.streamType() === 10) {
+    if (stream.streamType() === 10 || stream.streamType() === 1) {
       vue.connection = false;
     }
   });
@@ -366,7 +367,7 @@ export function stopLive() {
     success() {
       Message({
         type: 'success',
-        message: '结束直播成功'
+        message: '直播已结束'
       });
     },
     fail(data) {
@@ -457,6 +458,13 @@ export function publishShareStream() {
 }
 
 /**
+ * 关闭桌面共享
+ */
+export function unPubShareStream() {
+  rtc.unPubShareStream();
+}
+
+/**
  * @description 开启、结束、暂停、恢复录制
  * @param { String } status: 'start' 开启, 'end' 结束, 'pause' 暂停, 'resume' 恢复
  */