index.vue 19 KB

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