group.vue 18 KB

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