index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. <template>
  2. <div class="live">
  3. <!--顶部-->
  4. <div class="live-top">
  5. <div class="live-title">
  6. <div class="live-title-name">{{ roomInfo.cs_item_name }} {{ roomInfo.task_name }}</div>
  7. <div>
  8. <el-button @click="exitRoom">退出房间</el-button>
  9. </div>
  10. </div>
  11. <div class="live-course-name">{{ roomInfo.course_name }}</div>
  12. <div class="live-teacher">
  13. <span class="live-teacher-name">
  14. <svg-icon icon-class="person" />{{ roomInfo.teacher_name }}
  15. </span>
  16. <span><svg-icon icon-class="people" />{{ roomInfo.student_count }}</span>
  17. </div>
  18. </div>
  19. <!-- 主容器 -->
  20. <div class="live-container">
  21. <!-- 左侧 -->
  22. <div class="live-container-left">
  23. <div v-show="callLoading" class="loading">
  24. <div class="loading-wrapper">
  25. <p class="loading-title">教师邀请您连麦中</p>
  26. <div>
  27. <el-button
  28. type="success"
  29. icon="el-icon-phone-outline"
  30. circle
  31. @click="inviteAccept"
  32. ></el-button>
  33. </div>
  34. </div>
  35. </div>
  36. <div v-show="connect" class="student-parent">
  37. <div v-show="roomInfo.video_mode === 1 || remoteStreamType === 1" id="student"></div>
  38. <template v-if="remoteStreamType !== 1">
  39. <template v-if="roomInfo.video_mode === 1">
  40. <el-button type="danger" @click="handsDown">
  41. <svg-icon icon-class="hang-up" /> 挂断
  42. </el-button>
  43. </template>
  44. <template v-else>
  45. <div class="student-audio">
  46. <el-avatar icon="el-icon-user" :src="roomInfo.teacher_image_url" />
  47. <el-button type="danger" circle @click="handsDown">
  48. <svg-icon icon-class="hang-up" />
  49. </el-button>
  50. </div>
  51. </template>
  52. </template>
  53. </div>
  54. <div v-show="isDraw" id="draw-parent">
  55. <div v-show="isDrawSetting" class="draw-setting">
  56. <span class="brush-shape">
  57. <svg-icon icon-class="brush-shape" />
  58. </span>
  59. <span
  60. v-for="item in drawColorList"
  61. :key="item"
  62. :class="['draw-color', item === '#FF4747' ? 'current' : '']"
  63. :style="{ 'background-color': item }"
  64. ></span>
  65. <span v-for="item in drawThicknessList" :key="item" class="draw-thickness">
  66. <span :style="{ width: item * 2 + 'px', height: item * 2 + 'px' }"></span>
  67. </span>
  68. <span class="brush-clear">
  69. <svg-icon icon-class="clear" />
  70. </span>
  71. </div>
  72. </div>
  73. <div class="button-group">
  74. <div class="button-group-left"></div>
  75. <div class="button-group-right"></div>
  76. </div>
  77. <div class="live-container-left-chat">
  78. <div class="chat-top">
  79. <span>聊天</span>
  80. </div>
  81. <div class="chat-window">
  82. <ul class="chat-window-ul">
  83. <li v-for="(item, i) in chatList" :key="i">
  84. <div class="msg-normal">
  85. <span>{{ item.username }}: </span>
  86. <span>{{ item.msg }}</span>
  87. </div>
  88. </li>
  89. </ul>
  90. </div>
  91. <div class="chat-speak">
  92. <el-input
  93. v-model="msg"
  94. placeholder="输入发言"
  95. maxlength="400"
  96. @keydown.enter.native="sendMsg"
  97. >
  98. <el-button slot="append" @click="sendMsg">发送</el-button>
  99. </el-input>
  100. </div>
  101. </div>
  102. </div>
  103. <!-- 右侧 -->
  104. <div class="live-container-right">
  105. <div
  106. class="live-teacher-lens"
  107. @mouseover="liveMenuShow = true"
  108. @mouseout="liveMenuShow = false"
  109. >
  110. <div id="live"></div>
  111. <div :style="{ bottom: liveMenuShow ? '0' : '-40px' }" class="live-wrapper">
  112. <div>
  113. {{ roomInfo.teacher_name }}
  114. </div>
  115. <div></div>
  116. </div>
  117. </div>
  118. <div class="student-list">
  119. <div class="student-list-title">学生列表</div>
  120. <ul>
  121. <li v-for="item in student_list" :key="item.room_user_id">
  122. <div class="student-list-left">
  123. <el-avatar icon="el-icon-user" size="small" :src="item.student_image_url" />
  124. <span class="name">{{ item.student_name }}</span>
  125. </div>
  126. </li>
  127. </ul>
  128. </div>
  129. </div>
  130. </div>
  131. <!-- 学员当前推送资料 -->
  132. <cur-material
  133. :task-id="task_id"
  134. :dialog-visible-material="dialogVisibleMaterial"
  135. :material-id="material_id"
  136. :material-name="material_name"
  137. :material-type="material_type"
  138. :material-picture-url="material_picture_url"
  139. @dialogMaterialClose="dialogMaterialClose"
  140. />
  141. </div>
  142. </template>
  143. <script>
  144. import {
  145. GetLiveRoomStudentList,
  146. StudentExitLiveRoom,
  147. GetCurMaterialSent,
  148. GetLiveRoomInfo
  149. } from '@/api/live';
  150. import CurMaterial from '@/components/live/CurMaterial.vue';
  151. import * as common from './live';
  152. export default {
  153. name: 'Live',
  154. components: {
  155. CurMaterial
  156. },
  157. data() {
  158. return {
  159. task_id: this.$route.query.task_id,
  160. room_user_id: this.$route.query.room_user_id,
  161. // 已连接
  162. connect: false,
  163. // 等待接通
  164. callLoading: false,
  165. dialogVisibleMaterial: false,
  166. // 资料信息
  167. material_id: '',
  168. material_name: '',
  169. material_type: '',
  170. material_picture_url: '',
  171. // 定时器
  172. timer: null,
  173. remoteStreamType: -1,
  174. rtc: null,
  175. roomData: {
  176. desc: '直播间标题',
  177. name: '姓名',
  178. user: {
  179. id: '',
  180. name: '',
  181. role: 'talker',
  182. rommid: ''
  183. },
  184. max_users: 1,
  185. allow_chat: true,
  186. allow_audio: true,
  187. allow_speak: true
  188. },
  189. roomInfo: {
  190. room_id: '',
  191. video_mode: 1,
  192. task_name: '',
  193. cs_item_name: '',
  194. course_name: '',
  195. teacher_name: '',
  196. student_count: 0
  197. },
  198. loadedNumber: 0,
  199. speakData: {},
  200. roomContext: {},
  201. msg: '',
  202. chatList: [],
  203. isDrawSetting: false,
  204. drawColorList: ['#FF4747', '#343434', '#628EFF', '#FFCA0E'],
  205. drawThicknessList: ['1', '3', '5'],
  206. // 直播间学员列表
  207. student_list: [],
  208. // 直播状态
  209. liveStat: false,
  210. liveMenuShow: false
  211. };
  212. },
  213. computed: {
  214. // 画板模式
  215. isDraw() {
  216. return !this.connect && !this.callLoading;
  217. }
  218. },
  219. watch: {
  220. loadedNumber(newVal) {
  221. if (newVal === 5) {
  222. common.createScript(
  223. 'https://class.csslcloud.net/static/SDK/docSDK/drawSdk_3.0.js'
  224. ).onload = () => {
  225. this.initSDK();
  226. this.$loading().close();
  227. };
  228. }
  229. }
  230. },
  231. created() {
  232. this.$loading({
  233. text: '加载直播所需SDK中...',
  234. background: '#fff'
  235. });
  236. common.downloadWebSDK(this);
  237. this.getLiveRoomStudentList();
  238. this.getLiveRoomInfo();
  239. },
  240. mounted() {
  241. this.getCurMaterialSent();
  242. this.getLiveRoomStudentListPolling();
  243. },
  244. beforeDestroy() {
  245. // 清除所有定时器
  246. // let end = setInterval(() => {}, 1000);
  247. // for (let i = 1; i <= end; i++) {
  248. // clearInterval(i);
  249. // }
  250. clearInterval(this.timer);
  251. StudentExitLiveRoom({ task_id: this.task_id, room_user_id: this.room_user_id });
  252. if (this.callLoading || this.connect) {
  253. this.handsDown();
  254. }
  255. },
  256. methods: {
  257. initSDK() {
  258. const { live_room_sys_user_id, room_id, session_id } = this.$route.query;
  259. this.rtc = common.initSDK({
  260. userid: live_room_sys_user_id,
  261. roomid: room_id,
  262. sessionid: session_id
  263. });
  264. common.initListener(this); // 注册监听事件
  265. this.getLiveStat();
  266. },
  267. getLiveRoomInfo() {
  268. GetLiveRoomInfo({ task_id: this.task_id }).then(
  269. ({
  270. room_id,
  271. video_mode,
  272. task_name,
  273. cs_item_name,
  274. course_name,
  275. teacher_name,
  276. student_count,
  277. teacher_image_url
  278. }) => {
  279. this.roomInfo = {
  280. room_id,
  281. video_mode,
  282. task_name,
  283. cs_item_name,
  284. course_name,
  285. teacher_name,
  286. student_count,
  287. teacher_image_url
  288. };
  289. }
  290. );
  291. },
  292. exitRoom() {
  293. StudentExitLiveRoom({ task_id: this.task_id, room_user_id: this.room_user_id }).then(() => {
  294. this.$router.push('/');
  295. });
  296. },
  297. getLiveStat() {
  298. common.getLiveStat({
  299. success: data => {
  300. this.liveStat = data.started;
  301. },
  302. fail: str => {
  303. this.liveStat = false;
  304. console.log('直播关闭状态或查询直播失败', str);
  305. }
  306. });
  307. },
  308. // 下麦
  309. handsDown() {
  310. common.handsDown({
  311. uid: this.room_user_id,
  312. success: str => {
  313. this.callLoading = false;
  314. console.log('下麦成功', str);
  315. this.$message.success('下麦成功');
  316. },
  317. fail: data => {
  318. console.log('下麦失败', data);
  319. }
  320. });
  321. },
  322. // 发消息
  323. sendMsg() {
  324. common.sendMsg(this.msg);
  325. this.msg = '';
  326. },
  327. getDevice() {
  328. common.getDevice();
  329. },
  330. inviteAccept() {
  331. common.inviteAccept({
  332. success: str => {
  333. console.log('接受邀请成功', str);
  334. },
  335. fail: data => {
  336. console.log('接受邀请失败', data);
  337. this.$message.warning(`接受邀请失败 ${data.errorMsg}`);
  338. this.callLoading = false;
  339. }
  340. });
  341. },
  342. getLiveRoomStudentList() {
  343. GetLiveRoomStudentList({ task_id: this.task_id }).then(({ student_list }) => {
  344. this.student_list = student_list;
  345. });
  346. },
  347. getLiveRoomStudentListPolling() {
  348. this.timer = setInterval(() => {
  349. this.getLiveRoomStudentList();
  350. }, 5000);
  351. },
  352. // 弹出框方法
  353. dialogMaterialClose() {
  354. this.dialogVisibleMaterial = false;
  355. this.getCurMaterialSent();
  356. },
  357. getCurMaterialSent() {
  358. const timer = setInterval(() => {
  359. GetCurMaterialSent({ task_id: this.task_id })
  360. .then(({ material_id, material_name, material_type, material_picture_url }) => {
  361. if (material_id !== undefined && material_id.length > 0) {
  362. this.dialogVisibleMaterial = true;
  363. this.material_id = material_id;
  364. this.material_name = material_name;
  365. this.material_type = material_type;
  366. this.material_picture_url = material_picture_url;
  367. clearInterval(timer);
  368. }
  369. })
  370. .catch(() => {
  371. clearInterval(timer);
  372. });
  373. }, 2000);
  374. }
  375. }
  376. };
  377. </script>
  378. <style lang="scss">
  379. @import '~@/styles/mixin.scss';
  380. $live-bc: #3d3938;
  381. .live {
  382. @include container;
  383. // 顶部
  384. &-top {
  385. background-color: #fff;
  386. padding: 24px 32px;
  387. border-top-left-radius: 8px;
  388. border-top-right-radius: 8px;
  389. .live-title {
  390. display: flex;
  391. justify-content: space-between;
  392. &-name {
  393. font-size: 22px;
  394. }
  395. .el-button {
  396. border-radius: 4px;
  397. padding: 7px 12px;
  398. }
  399. }
  400. .live-course-name {
  401. font-size: 14px;
  402. color: #737373;
  403. line-height: 30px;
  404. }
  405. .live-teacher {
  406. margin-top: 12px;
  407. .svg-icon {
  408. margin-right: 8px;
  409. }
  410. &-name {
  411. margin-right: 60px;
  412. }
  413. }
  414. }
  415. // 主容器
  416. &-container {
  417. display: flex;
  418. justify-content: left;
  419. &-left {
  420. width: 832px;
  421. background-color: #fff;
  422. border-radius: 8px;
  423. .loading {
  424. position: relative;
  425. width: 100%;
  426. height: 468px;
  427. color: #fff;
  428. background-color: #646464;
  429. display: flex;
  430. justify-content: center;
  431. align-items: center;
  432. &-wrapper {
  433. text-align: center;
  434. .loading-title {
  435. margin-bottom: 24px;
  436. }
  437. }
  438. }
  439. .student-parent {
  440. position: relative;
  441. width: 100%;
  442. height: 468px;
  443. #student {
  444. width: 100%;
  445. height: 468px;
  446. border: 1px solid #ccc;
  447. position: relative;
  448. background-color: $live-bc;
  449. }
  450. > .el-button {
  451. position: absolute;
  452. bottom: 40px;
  453. left: calc(50% - 44px);
  454. }
  455. .student-audio {
  456. width: 100%;
  457. height: 100%;
  458. background-color: #646464;
  459. display: flex;
  460. flex-direction: column;
  461. justify-content: center;
  462. align-items: center;
  463. > .el-avatar {
  464. width: 96px;
  465. height: 96px;
  466. line-height: 96px;
  467. margin-bottom: 24px;
  468. &--icon {
  469. font-size: 36px;
  470. }
  471. }
  472. }
  473. }
  474. #draw-parent {
  475. width: 100%;
  476. height: 468px;
  477. border: 1px solid #ccc;
  478. position: relative;
  479. background-color: $live-bc;
  480. overflow: hidden;
  481. // 设置屏幕画笔
  482. .draw-setting {
  483. position: absolute;
  484. bottom: 13px;
  485. left: 22px;
  486. z-index: 9999;
  487. background-color: #a0a0a0;
  488. padding: 6px;
  489. border-radius: 40px;
  490. height: 40px;
  491. width: 275px;
  492. line-height: 28px;
  493. & > span {
  494. display: inline-block;
  495. text-align: center;
  496. margin-right: 10px;
  497. }
  498. & > span.brush-shape {
  499. width: 28px;
  500. height: 28px;
  501. border-radius: 50%;
  502. background-color: #fff;
  503. cursor: pointer;
  504. }
  505. .draw-color {
  506. position: relative;
  507. top: 5px;
  508. height: 18px;
  509. width: 18px;
  510. border-radius: 50%;
  511. cursor: pointer;
  512. }
  513. .current::after {
  514. content: '';
  515. position: absolute;
  516. bottom: -7px;
  517. left: 7px;
  518. width: 4px;
  519. height: 4px;
  520. border-radius: 50%;
  521. background-color: #292929;
  522. }
  523. .draw-thickness {
  524. height: 18px;
  525. width: 18px;
  526. cursor: pointer;
  527. display: inline-flex;
  528. flex-direction: column;
  529. justify-content: center;
  530. vertical-align: middle;
  531. align-items: center;
  532. span {
  533. border-radius: 50%;
  534. background-color: #000;
  535. }
  536. }
  537. & > .brush-clear {
  538. width: 28px;
  539. height: 28px;
  540. border-radius: 50%;
  541. background-color: #666;
  542. cursor: pointer;
  543. margin-right: 0;
  544. }
  545. }
  546. }
  547. .button-group {
  548. display: flex;
  549. justify-content: space-between;
  550. height: 48px;
  551. background-color: #4d4d4d;
  552. padding: 0 15px;
  553. border-bottom-left-radius: 5px;
  554. .svg-icon {
  555. font-size: 20px;
  556. }
  557. &-left {
  558. > span {
  559. display: inline-block;
  560. height: 100%;
  561. padding: 14px 16px;
  562. cursor: pointer;
  563. &:active,
  564. &:hover {
  565. background-color: #3d3d3d;
  566. }
  567. }
  568. }
  569. }
  570. // 聊天窗口
  571. &-chat {
  572. height: 278px;
  573. border: 1px solid #ccc;
  574. border-bottom-left-radius: 8px;
  575. display: flex;
  576. flex-direction: column;
  577. justify-content: space-between;
  578. .chat-top {
  579. display: flex;
  580. justify-content: space-between;
  581. padding: 15px 15px 10px;
  582. border-bottom: 1px solid #e6e6e6;
  583. color: #959595;
  584. label {
  585. cursor: pointer;
  586. }
  587. .allow-chat {
  588. margin-right: 12px;
  589. }
  590. }
  591. .chat-window {
  592. position: relative;
  593. width: 100%;
  594. height: 100%;
  595. overflow: hidden;
  596. &-ul {
  597. position: absolute;
  598. top: 0;
  599. left: 0;
  600. width: 100%;
  601. height: 100%;
  602. overflow: auto;
  603. .msg-normal {
  604. padding: 7px 16px;
  605. }
  606. }
  607. }
  608. .chat-speak {
  609. padding: 16px;
  610. }
  611. }
  612. }
  613. &-right {
  614. padding: 8px;
  615. background-color: #2c2c2c;
  616. border-end-end-radius: 8px;
  617. .live-teacher-lens {
  618. position: relative;
  619. overflow: hidden;
  620. #live {
  621. width: 352px;
  622. height: 198px;
  623. background-color: $live-bc;
  624. }
  625. .live-wrapper {
  626. position: absolute;
  627. height: 40px;
  628. width: 100%;
  629. background-color: #000;
  630. opacity: 0.7;
  631. color: #fff;
  632. line-height: 40px;
  633. padding: 0 16px;
  634. transition: all 300ms ease-in 0s;
  635. }
  636. }
  637. .student-list {
  638. width: 100%;
  639. padding: 24px 16px;
  640. margin-top: 2px;
  641. height: calc(100% - 200px);
  642. background-color: #2c2c2c;
  643. font-size: 14px;
  644. color: #fff;
  645. &-title {
  646. margin-bottom: 16px;
  647. }
  648. li {
  649. display: flex;
  650. margin-bottom: 16px;
  651. .student-list-left {
  652. flex: 7;
  653. .name {
  654. vertical-align: super;
  655. margin-left: 8px;
  656. }
  657. }
  658. .student-list-right {
  659. flex: 3;
  660. .svg-icon {
  661. font-size: 18px;
  662. cursor: pointer;
  663. margin-top: 7px;
  664. margin-right: 8px;
  665. }
  666. }
  667. }
  668. }
  669. }
  670. }
  671. }
  672. </style>