index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. <template>
  2. <BaseLive :room-info="roomInfo">
  3. <div class="teacher">
  4. <div class="middle">
  5. <!-- 教师学员列表 -->
  6. <PersonnelList
  7. :has-video="isShowPersonnelList"
  8. :student-list="student_list"
  9. :teacher-name="roomInfo.teacher_name"
  10. @invite="invite"
  11. @kickOut="kickOut"
  12. />
  13. <!-- 直播视频与连线 -->
  14. <div v-show="!isShowDraw" class="live-main">
  15. <div class="live-connection" :style="{ 'padding-top': connect || callLoading ? '131px' : '0' }">
  16. <div class="live">
  17. <div v-show="hasVideo" id="live"></div>
  18. </div>
  19. <div v-show="callLoading" class="call-loading">
  20. <span>等待接通...</span>
  21. </div>
  22. <div v-show="connect" id="student" class="student-video"></div>
  23. </div>
  24. <div v-show="callLoading || connect" class="close">
  25. <el-button type="danger" @click="() => (remoteStreamType === 1 ? unPubShareStream() : handsDown())">
  26. {{ remoteStreamType === 1 ? '关闭共享' : '结束连线' }}
  27. </el-button>
  28. </div>
  29. </div>
  30. <!-- 画板 -->
  31. <div class="draw" :style="{ left: isShowDraw ? '0' : `-${innerWidth}px` }">
  32. <div id="draw-parent">
  33. <div class="draw-setting">
  34. <span class="brush-shape" @click="changeDraw('type', 2)">
  35. <svg-icon icon-class="brush-shape" />
  36. </span>
  37. <!-- 画笔颜色 -->
  38. <span
  39. v-for="item in drawColorList"
  40. :key="item"
  41. :class="['draw-color', item === curColor ? 'current' : '']"
  42. :style="{ 'background-color': item }"
  43. @click="changeDraw('color', item)"
  44. ></span>
  45. <span
  46. v-for="item in drawThicknessList"
  47. :key="item"
  48. class="draw-thickness"
  49. @click="changeDraw('thickNess', item)"
  50. >
  51. <span :style="{ width: item * 2 + 'px', height: item * 2 + 'px' }"></span>
  52. </span>
  53. <span class="eraser" @click="changeDraw('type', 9)">
  54. <svg-icon icon-class="back" />
  55. </span>
  56. <span class="eraser" @click="changeDraw('type', 10)">
  57. <svg-icon icon-class="eraser" />
  58. </span>
  59. <span class="brush-clear" @click="changeDraw('type', 0)">
  60. <svg-icon icon-class="clear" />
  61. </span>
  62. </div>
  63. </div>
  64. </div>
  65. <!-- 聊天 -->
  66. <ChatPage ref="cPage" :chat-list="chatList" :chat-show="chatShow" @sendMsg="sendMsg" />
  67. <!-- 成员列表 -->
  68. <MemberList :member-show="memberShow" :student-list="student_list" @invite="invite" @kickOut="kickOut" />
  69. </div>
  70. <div class="bottom">
  71. <div class="operation">
  72. <div class="operation-item" @click="playOrPauseAudio">
  73. <img :src="hasAudio ? require('@/assets/live/voice.png') : require('@/assets/live/voice-off.png')" alt="" />
  74. <span>{{ hasAudio ? '开启静音' : '解除静音' }}</span>
  75. </div>
  76. <div class="operation-item" @click="playOrPauseVideo">
  77. <img
  78. :src="hasVideo ? require('@/assets/live/monitor.png') : require('@/assets/live/monitor-off.png')"
  79. alt="视频流开关"
  80. />
  81. <span>{{ hasVideo ? '关闭视频' : '开启视频' }}</span>
  82. </div>
  83. </div>
  84. <div class="operation">
  85. <div class="operation-item" @click="publishShareStream">
  86. <img src="@/assets/live/laptop-computer.png" alt="" />
  87. <span>共享屏幕</span>
  88. </div>
  89. <div class="operation-item" @click="changeWhiteboard">
  90. <img src="@/assets/live/laptop-computer.png" alt="" />
  91. <span>{{ isShowDraw ? '退出白板' : '互动白板' }}</span>
  92. </div>
  93. <div class="operation-item" @click="dialogVisible = true">
  94. <img src="@/assets/live/folder-upload.png" alt="" />
  95. <span>课件推送</span>
  96. </div>
  97. <el-popover width="280" popper-class="group-discussion" title="分组设置" trigger="click" placement="top">
  98. <div>
  99. <el-form :model="groupForm" label-width="80px" label-position="left">
  100. <el-form-item label="分组方式">
  101. <el-radio v-model="groupForm.operation_mode" label="group_count">按组</el-radio>
  102. <el-radio v-model="groupForm.operation_mode" label="person_count">按人</el-radio>
  103. </el-form-item>
  104. <el-form-item label="分成几组">
  105. <el-input-number
  106. v-model="groupForm.group_count"
  107. :disabled="groupForm.operation_mode !== 'group_count'"
  108. size="small"
  109. :min="1"
  110. />
  111. </el-form-item>
  112. <el-form-item label="几人一组">
  113. <el-input-number
  114. v-model="groupForm.person_count"
  115. :disabled="groupForm.operation_mode !== 'person_count'"
  116. size="small"
  117. :min="1"
  118. />
  119. </el-form-item>
  120. <el-form-item>
  121. <el-button size="small" @click="startGroup">确定</el-button>
  122. </el-form-item>
  123. </el-form>
  124. </div>
  125. <div slot="reference" class="operation-item">
  126. <img src="@/assets/live/every-user.png" alt="" />
  127. <span>分组讨论</span>
  128. </div>
  129. </el-popover>
  130. <span class="line"></span>
  131. <div :class="['operation-item', { active: chatShow }]" @click="toggle(toggleList[0].type)">
  132. <img src="@/assets/live/communication.png" alt="" />
  133. <span>聊天</span>
  134. </div>
  135. <div :class="['operation-item', { active: memberShow }]" @click="toggle(toggleList[1].type)">
  136. <img src="@/assets/live/peoples.png" alt="" />
  137. <span>成员列表</span>
  138. </div>
  139. <div class="operation-item">
  140. <img src="@/assets/live/recording.png" alt="" />
  141. <span>录制</span>
  142. </div>
  143. </div>
  144. <div class="operation">
  145. <button class="live-button" @click="() => (liveStat ? closeLiveRoom() : startLive())">
  146. {{ liveStat ? '结束直播' : '开始直播' }}
  147. </button>
  148. </div>
  149. </div>
  150. </div>
  151. <!-- 选择设备 -->
  152. <SelectDevice
  153. :dialog-visible-device="dialogVisibleDevice"
  154. :device="device"
  155. @dialogDeviceClose="dialogDeviceClose"
  156. />
  157. <!-- 推送资料 -->
  158. <SelectMaterial
  159. :dialog-visible="dialogVisible"
  160. :task-id="task_id"
  161. @dialogClose="dialogClose"
  162. @dialogPush="dialogPush"
  163. />
  164. <!-- 教师查看当前完成列表 -->
  165. <CompleteList
  166. :task-id="task_id"
  167. :material-id="materialId"
  168. :material-type="materialType"
  169. :dialog-visible-complete="dialogVisibleComplete"
  170. @dialogCompleteClose="dialogCompleteClose"
  171. />
  172. </BaseLive>
  173. </template>
  174. <script>
  175. export default {
  176. name: 'TeacherLive'
  177. };
  178. </script>
  179. <script setup>
  180. import { ref, computed, watch, provide, inject } from 'vue';
  181. import { CloseLiveRoom } from '@/api/live';
  182. import { Message, MessageBox } from 'element-ui';
  183. import { useRoute, useRouter } from 'vue-router/composables';
  184. import { useInit, useChat, useMemberList, useLive } from '../common/common';
  185. import { useTeacherLiveRtc, useInitListener, useConnect, useGroup, useWhiteboard, usePushMaterial } from './live';
  186. import { app } from '@/store/mutation-types';
  187. import store from '@/store';
  188. import BaseLive from '../common/BaseLive.vue';
  189. import SelectDevice from '../common/SelectDevice';
  190. import ChatPage from '../common/ChatList.vue';
  191. import MemberList from '../common/MemberList.vue';
  192. import PersonnelList from '../common/PersonnelList.vue';
  193. import SelectMaterial from '@/components/live/SelectMaterial.vue';
  194. import CompleteList from './components/CompleteList.vue';
  195. const router = useRouter();
  196. const route = useRoute();
  197. const task_id = route.query.task_id;
  198. provide('task_id', task_id);
  199. const $t = inject('$t');
  200. let remoteStreamType = ref(-1);
  201. let roomData = ref({
  202. desc: '直播间标题',
  203. name: '姓名',
  204. user: {
  205. id: '',
  206. name: '',
  207. role: 'talker',
  208. rommid: ''
  209. },
  210. max_users: 1,
  211. allow_chat: true,
  212. allow_audio: true,
  213. allow_speak: true
  214. });
  215. let speakData = ref({});
  216. let roomContext = ref({});
  217. const innerWidth = window.innerWidth;
  218. const { dialogClose, dialogCompleteClose, dialogPush, dialogVisible, dialogVisibleComplete, materialId, materialType } =
  219. usePushMaterial();
  220. // 聊天
  221. let cPage = ref();
  222. const { chatList, chatShow, sendMsg, toggle: chatToggle } = useChat(cPage);
  223. // 成员列表
  224. const { memberShow, toggle: memberToggle } = useMemberList();
  225. // 多个附属界面切换
  226. const toggleList = [
  227. {
  228. type: 'chat',
  229. toggle: chatToggle
  230. },
  231. {
  232. type: 'member',
  233. toggle: memberToggle
  234. }
  235. ];
  236. function toggle(type) {
  237. let item = toggleList.find((item) => item.type === type);
  238. if (item === undefined) return;
  239. item.toggle();
  240. toggleList.forEach((item) => {
  241. if (item.type !== type) {
  242. item.toggle(false);
  243. }
  244. });
  245. }
  246. const { startLive, stopLive, kickOut, publishShareStream, unPubShareStream } = useTeacherLiveRtc();
  247. const { pauseVideo, playVideo, pauseAudio, playAudio, closeVideo, createLocalStream } = useLive();
  248. const { groupForm, startGroup } = useGroup(task_id, router);
  249. // 本地视频流画面、声音
  250. let device = ref({
  251. video: [],
  252. audio: []
  253. });
  254. let hasVideo = ref(false);
  255. let hasAudio = ref(false);
  256. let isShowPersonnelList = computed(() => {
  257. return hasVideo.value || connect.value || callLoading.value || isShowDraw.value;
  258. });
  259. /**
  260. * 本地流视频开启、关闭
  261. */
  262. function playOrPauseVideo() {
  263. if (device.value.video.length === 0) {
  264. return Message.warning($t('Key399'));
  265. }
  266. if (hasVideo.value) {
  267. pauseVideo({
  268. streamName: 'main',
  269. success: () => {
  270. Message.success($t('Key433'));
  271. hasVideo.value = false;
  272. },
  273. fail: (str) => {
  274. Message.warning(str);
  275. }
  276. });
  277. } else {
  278. playVideo({
  279. streamName: 'main',
  280. success: () => {
  281. Message.success($t('Key434'));
  282. hasVideo.value = true;
  283. },
  284. fail: (str) => {
  285. Message.warning(str);
  286. }
  287. });
  288. }
  289. }
  290. /**
  291. * 本地流音频开启、关闭
  292. */
  293. function playOrPauseAudio() {
  294. if (device.value.audio.length === 0) {
  295. return Message.warning($t('Key401'));
  296. }
  297. if (hasAudio.value) {
  298. pauseAudio({
  299. streamName: 'main',
  300. success: () => {
  301. Message.success($t('Key435'));
  302. hasAudio.value = false;
  303. },
  304. fail: (str) => {
  305. Message.warning(str);
  306. }
  307. });
  308. } else {
  309. playAudio({
  310. streamName: 'main',
  311. success: () => {
  312. Message.success($t('Key436'));
  313. hasAudio.value = true;
  314. },
  315. fail: (str) => {
  316. Message.warning(str);
  317. }
  318. });
  319. }
  320. }
  321. let dialogVisibleDevice = ref(false);
  322. let isRecreate = ref(false);
  323. // 设置音视频设备
  324. function setDevice(isRec) {
  325. isRecreate.value = isRec;
  326. dialogVisibleDevice.value = true;
  327. }
  328. function dialogDeviceClose(device) {
  329. store.commit(`app/${app.SET_DEVICE}`, device);
  330. dialogVisibleDevice.value = false;
  331. if (isRecreate.value) {
  332. closeVideo({
  333. streamName: 'main',
  334. success: () => {
  335. createLocalStream('main', hasAudio, hasVideo);
  336. },
  337. fail: (str) => {
  338. console.log(str);
  339. }
  340. });
  341. } else {
  342. createLocalStream('main', hasAudio, hasVideo);
  343. }
  344. }
  345. const {
  346. callLoading,
  347. connect,
  348. connectStudent,
  349. connectUid,
  350. liveStat,
  351. material_list,
  352. roomInfo,
  353. student_list,
  354. getLiveRoomData_DRTD
  355. } = useInit(useInitListener, {
  356. roomData,
  357. chatList,
  358. device,
  359. roomContext,
  360. speakData,
  361. remoteStreamType,
  362. setDevice,
  363. hasAudio,
  364. hasVideo
  365. });
  366. watch(
  367. () => roomInfo.value.is_enable_whiteboard,
  368. (val) => {
  369. changeWhiteboard(val);
  370. }
  371. );
  372. const { changeDraw, changeWhiteboard, isShowDraw, curColor, drawColorList, drawThicknessList } = useWhiteboard(
  373. task_id,
  374. connect,
  375. callLoading
  376. );
  377. const { handsDown, invite } = useConnect({
  378. connect,
  379. callLoading,
  380. connectStudent,
  381. roomInfo,
  382. connectUid,
  383. getLiveRoomData_DRTD
  384. });
  385. /**
  386. * 关闭直播间
  387. */
  388. function closeLiveRoom() {
  389. MessageBox.confirm('是否关闭当前直播?', '提示', {
  390. confirmButtonText: '确定',
  391. cancelButtonText: '取消',
  392. type: 'warning'
  393. }).then(() => {
  394. CloseLiveRoom({ task_id }).then(() => {
  395. router.push('/');
  396. Message.success($t('Key426'));
  397. });
  398. stopLive();
  399. });
  400. }
  401. </script>
  402. <style lang="scss" scoped>
  403. .teacher {
  404. display: flex;
  405. flex-direction: column;
  406. height: 100%;
  407. .middle {
  408. position: relative;
  409. flex: 1;
  410. overflow: hidden;
  411. .live-main {
  412. display: flex;
  413. flex-direction: column;
  414. width: 100%;
  415. height: 100%;
  416. background-color: #434343;
  417. .live-connection {
  418. display: flex;
  419. flex: 1;
  420. .live {
  421. flex: 1;
  422. background-color: #000;
  423. #live {
  424. width: 100%;
  425. height: 100%;
  426. }
  427. }
  428. .call-loading {
  429. display: flex;
  430. flex-basis: 50%;
  431. align-items: center;
  432. justify-content: center;
  433. color: #fff;
  434. background-color: #333;
  435. }
  436. .student-video {
  437. flex-basis: 50%;
  438. }
  439. }
  440. .close {
  441. display: flex;
  442. justify-content: center;
  443. padding: 90px 0 16px;
  444. }
  445. }
  446. .draw {
  447. position: absolute;
  448. width: 100%;
  449. height: 100%;
  450. overflow: hidden;
  451. #draw-parent {
  452. height: 100%;
  453. margin: auto;
  454. .draw-setting {
  455. position: absolute;
  456. bottom: 13px;
  457. left: 22px;
  458. z-index: 9999;
  459. height: 40px;
  460. padding: 6px;
  461. line-height: 28px;
  462. background-color: #a0a0a0;
  463. border-radius: 40px;
  464. > span {
  465. display: inline-block;
  466. margin-right: 10px;
  467. text-align: center;
  468. }
  469. > span.brush-shape {
  470. width: 28px;
  471. height: 28px;
  472. cursor: pointer;
  473. background-color: #fff;
  474. border-radius: 50%;
  475. }
  476. .draw-color {
  477. position: relative;
  478. top: 5px;
  479. width: 18px;
  480. height: 18px;
  481. cursor: pointer;
  482. border-radius: 50%;
  483. }
  484. .current::after {
  485. position: absolute;
  486. bottom: -7px;
  487. left: 7px;
  488. width: 4px;
  489. height: 4px;
  490. content: '';
  491. background-color: #292929;
  492. border-radius: 50%;
  493. }
  494. .draw-thickness {
  495. display: inline-flex;
  496. flex-direction: column;
  497. align-items: center;
  498. justify-content: center;
  499. width: 18px;
  500. height: 18px;
  501. vertical-align: middle;
  502. cursor: pointer;
  503. span {
  504. background-color: #000;
  505. border-radius: 50%;
  506. }
  507. }
  508. > %brush-clear,
  509. .brush-clear {
  510. width: 28px;
  511. height: 28px;
  512. margin-right: 0;
  513. cursor: pointer;
  514. background-color: #666;
  515. border-radius: 50%;
  516. }
  517. > .eraser {
  518. @extend %brush-clear;
  519. margin-right: 12px;
  520. }
  521. }
  522. }
  523. }
  524. }
  525. .bottom {
  526. display: flex;
  527. align-items: center;
  528. justify-content: space-between;
  529. height: 96px;
  530. padding: 12px 16px;
  531. background-color: #f8f8f8;
  532. .operation {
  533. display: flex;
  534. column-gap: 16px;
  535. &-item {
  536. display: flex;
  537. flex-direction: column;
  538. row-gap: 4px;
  539. align-items: center;
  540. width: 80px;
  541. height: 70px;
  542. padding: 8px;
  543. cursor: pointer;
  544. border-radius: 8px;
  545. transition: background-color 0.3s;
  546. &.active,
  547. &:active {
  548. background-color: #e5e5e5;
  549. }
  550. img {
  551. width: 32px;
  552. height: 32px;
  553. }
  554. }
  555. .line {
  556. width: 2px;
  557. height: 70px;
  558. background-color: #d0d0d0;
  559. }
  560. .live-button {
  561. height: 48px;
  562. padding: 8px 24px;
  563. font-size: 20px;
  564. font-weight: 500;
  565. color: #e52e2e;
  566. cursor: pointer;
  567. border: 2px solid #e52e2e;
  568. border-radius: 4px;
  569. }
  570. }
  571. }
  572. }
  573. </style>
  574. <style lang="scss">
  575. .group-discussion {
  576. padding: 24px;
  577. background-color: #fff;
  578. .el-form {
  579. &-item:last-child {
  580. margin-bottom: 0;
  581. .el-form-item__content {
  582. display: flex;
  583. justify-content: flex-end;
  584. .el-button {
  585. margin-right: 18px;
  586. color: #fff;
  587. background-color: #3fa1fb;
  588. }
  589. }
  590. }
  591. }
  592. .el-radio__input.is-checked .el-radio__inner {
  593. background-color: #0052d9;
  594. border-color: #0052d9;
  595. }
  596. .el-input-number {
  597. width: 136px;
  598. .el-input__inner {
  599. width: 62px;
  600. height: 33px;
  601. padding: 0;
  602. margin-left: 36px;
  603. }
  604. &__decrease,
  605. &__increase {
  606. border: 1px solid #dcdfe6;
  607. }
  608. }
  609. .el-popover {
  610. &__title {
  611. font-weight: 600;
  612. color: #000;
  613. }
  614. &[x-placement^='bottom'] .popper__arrow::after {
  615. border-bottom-color: #fff;
  616. }
  617. }
  618. }
  619. </style>