roomDetail.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  1. <template>
  2. <div id="roomsDetail">
  3. <el-row>
  4. <el-col :span="24" class="video" :style="{ height: oheight }"> </el-col>
  5. </el-row>
  6. <van-overlay :show="show" :style="{ height: oheight, width: '100%' }">
  7. <div id="transformid" class="wrapper" :style="{ transform: transform, height: vheight, width: vwidth, padding: vpadding, position: 'absolute' }">
  8. <div :style="{ height: lheight, width: lwidth }" id="look-video-left" class="video-box col-div look-video-left"></div>
  9. <div id="look-video-right" :style="{ height: rheight, width: rwidth }" class="video-box col-div look-video-right"></div>
  10. </div>
  11. <div id="othediv" v-show="othedivshow" :style="{ transform: transform, height: otheheight, width: vwidth, padding: othepadding, position: 'absolute' }">
  12. <div :style="{ height: otheheight, width: vwidth, background: background_ }">
  13. <div id="othe-video-1" :style="{ height: otheheight, width: othewidth }" class="video-box col-div othe-video-left"></div>
  14. <div id="othe-video-2" :style="{ height: otheheight, width: othewidth }" class="video-box col-div othe-video-left"></div>
  15. <div id="othe-video-3" :style="{ height: otheheight, width: othewidth }" class="video-box col-div othe-video-left"></div>
  16. <div id="othe-video-4" :style="{ height: otheheight, width: othewidth }" class="video-box col-div othe-video-left"></div>
  17. <div id="othe-video-5" :style="{ height: otheheight, width: othewidth }" class="video-box col-div othe-video-left"></div>
  18. </div>
  19. </div>
  20. <div class="videoBtn" id="videobtnid" :style="{ top: btop, right: bright }">
  21. <el-button type="warning" round @click="full()" size="mini"><i class="el-icon-rank"></i></el-button>
  22. </div>
  23. </van-overlay>
  24. <el-row class="chatrow">
  25. <el-col :span="24" class="info">
  26. <el-col :span="12" class="num">
  27. <span>观看:{{ total }}</span>
  28. </el-col>
  29. <el-col :span="12" class="meetBtn">
  30. <el-button v-show="switchbtn" type="warning" round size="small" @click="roomMeetBtn()">小程序<i class="el-icon-camera el-icon--right"></i></el-button>
  31. </el-col>
  32. </el-col>
  33. </el-row>
  34. <van-tabs type="card" @click="tabsClick">
  35. <van-tab title="会议简介">
  36. <van-col :span="24">
  37. <van-col class="content">{{ roomInfos.content }}</van-col>
  38. </van-col>
  39. <van-col :span="24">
  40. <van-swipe :autoplay="3000">
  41. <van-swipe-item v-for="(advert, index) in roomInfos.adverts" :key="index">
  42. <img width="100%" height="100px" v-lazy="advert.imgdir" @click="imgclick(advert.imgurl)" />
  43. </van-swipe-item>
  44. </van-swipe>
  45. </van-col>
  46. </van-tab>
  47. <van-tab title="互动留言">
  48. <el-row>
  49. <el-col :span="24" class="info">
  50. <el-col :span="24" class="chat">
  51. <el-col :span="24" class="chatInfo" id="chatSell">
  52. <el-col :span="24" class="list" v-for="(item, index) in dataList" :key="index">
  53. <p>
  54. <span :class="item.sendname == user.name ? 'selfColor' : ''">{{ item.sendname }}:</span>
  55. <span>{{ item.content }}</span>
  56. </p>
  57. </el-col>
  58. </el-col>
  59. </el-col>
  60. <el-col :span="24" class="submit">
  61. <el-col :span="19" class="input">
  62. <el-input type="textarea" maxlength="5000" show-word-limit v-model="content"></el-input>
  63. </el-col>
  64. <el-col :span="5" class="btn">
  65. <el-button type="primary" size="mini" @click="chatCreate">发送</el-button>
  66. </el-col>
  67. </el-col>
  68. </el-col>
  69. </el-row>
  70. </van-tab>
  71. <van-tab title="参与成员">
  72. <van-col :span="24" class="userList">
  73. <van-grid :column-num="3">
  74. <van-grid-item v-for="(item, index) in userList" :key="index" icon="manager" :text="item.username" />
  75. </van-grid>
  76. </van-col>
  77. </van-tab>
  78. <van-tab title="申请评分">
  79. <van-col :span="24">
  80. <van-field v-model="isxf" name="isxf" left-icon="star-o" label="学分" type="number" placeholder="请填写需要授予学分" />
  81. </van-col>
  82. <van-col :span="24" style="text-align:center">
  83. <van-button icon="star-o" type="primary" @click="sqClick">
  84. 申请
  85. </van-button>
  86. </van-col>
  87. </van-tab>
  88. </van-tabs>
  89. <van-popup v-model="showQuest" position="bottom">
  90. <van-col :span="24" class="questtitle">
  91. <span>{{ questInfo.name }}</span>
  92. </van-col>
  93. <van-col class="questpopup" :span="24" v-for="(item, index) in questInfo.question" :key="index">
  94. <p style="margin:5px 0;">
  95. {{ index + 1 }}({{ item.type == '0' ? '单选' : item.type == '1' ? '多选' : item.type == '2' ? '问答' : '未识别' }})、{{ item.topic }}
  96. </p>
  97. <span v-if="item.type == '0'">
  98. <van-radio-group v-model="item.answer">
  99. <van-radio v-for="(i, ri) in item.option" :key="`${index}-${ri}`" :name="i.opname">{{ i.opname }}</van-radio>
  100. </van-radio-group>
  101. </span>
  102. <span v-if="item.type == '1'">
  103. <van-checkbox-group v-model="item.answer">
  104. <van-checkbox shape="square" v-for="(i, ci) in item.option" :key="`${index}-${ci}`" :name="i.opname">{{ i.opname }}</van-checkbox>
  105. </van-checkbox-group>
  106. </span>
  107. <span v-if="item.type == '2'">
  108. <van-field v-model="item.answer" type="textarea" rows="2" autosize placeholder="请输入" maxlength="200" show-word-limit />
  109. </span>
  110. </van-col>
  111. <van-col :span="24" class="questbtn">
  112. <van-button color="linear-gradient(to right, #4bb0ff, #6149f6)" @click="submitQuest">提交</van-button>
  113. </van-col>
  114. </van-popup>
  115. </div>
  116. </template>
  117. <script>
  118. import TRTC from 'trtc-js-sdk';
  119. import { mapState, createNamespacedHelpers } from 'vuex';
  120. import Vue from 'vue';
  121. import { Swipe, SwipeItem, Lazyload } from 'vant';
  122. import { Image as VanImage } from 'vant';
  123. import wx from 'weixin-js-sdk';
  124. Vue.use(Swipe);
  125. Vue.use(SwipeItem);
  126. Vue.use(VanImage);
  127. Vue.use(Lazyload);
  128. const { mapActions: uploadquestion } = createNamespacedHelpers('uploadquestion');
  129. const { mapActions: gensign } = createNamespacedHelpers('gensign');
  130. const { mapActions: room } = createNamespacedHelpers('room');
  131. const { mapActions: quest } = createNamespacedHelpers('quest');
  132. const { mapActions: chat } = createNamespacedHelpers('chat');
  133. export default {
  134. name: 'roomsDetail',
  135. props: {},
  136. components: {},
  137. data: function() {
  138. return {
  139. client_: null,
  140. localStream_: null,
  141. sdkAppId_: '1400380125',
  142. userId_: '',
  143. roomInfos: {},
  144. sendmemo: '',
  145. total: 0,
  146. transform: 'rotate(0)',
  147. oheight: '200px',
  148. vwidth: '100%',
  149. vheight: '200px',
  150. rheight: '200px',
  151. rwidth: '30%',
  152. lheight: '200px',
  153. lwidth: '70%',
  154. show: true,
  155. vpadding: '0',
  156. othepadding: '200px 0px 0px 0px',
  157. othetop: '200px',
  158. btop: '167px',
  159. bright: '10px',
  160. isscreen: false,
  161. content: '',
  162. dataList: [],
  163. lvideoid_: '',
  164. rvideoid_: '',
  165. userList: [],
  166. isxf: '',
  167. showQuest: false,
  168. queid: '',
  169. questInfo: {},
  170. switchbtn: false,
  171. switchmeetbtn: false,
  172. iscamera: false,
  173. otheheight: '10px',
  174. othewidth: '20%',
  175. bcolor: '#000',
  176. index_: 0,
  177. userindex_: 1,
  178. background_: '#000',
  179. swichusers: [],
  180. sbuser: '',
  181. othedivshow: false,
  182. };
  183. },
  184. created() {
  185. this.initclient();
  186. this.lookuserSearch();
  187. this.lookusercountsel();
  188. this.chatSearch();
  189. this.userswichrole();
  190. },
  191. mounted() {
  192. this.channel();
  193. },
  194. destroyed() {
  195. const that = this;
  196. window.addEventListener('pagehide', function() {
  197. console.log('页面要关闭了');
  198. that.recordSave();
  199. });
  200. },
  201. methods: {
  202. ...gensign(['gensignFetch']),
  203. ...room(['lookuserFetch', 'fetch', 'lookusercount', 'lookquery', 'lookupdate', 'lookrecord', 'lookuserswichrole']),
  204. ...chat(['query', 'create']),
  205. ...quest(['questfetch']),
  206. ...uploadquestion({ upcreate: 'create', upquery: 'query' }),
  207. zbfullbtn() {
  208. const width = document.documentElement.clientWidth;
  209. const lvr_ = document.getElementById('look-video-right');
  210. let style = 'width:' + width + 'px;';
  211. style += 'height:200px;';
  212. style += 'position:absolute;top:0;left:0;';
  213. style += 'z-index:1;';
  214. lvr_.style.cssText = style;
  215. },
  216. swichposition(objid) {
  217. console.log('in swichposition---' + objid);
  218. if (objid) {
  219. console.log(this.swichusers);
  220. const width = document.documentElement.clientWidth;
  221. for (const elm of this.swichusers) {
  222. if (elm.swichuserid === objid) {
  223. const id_ = 'othe-video-' + elm.swichindex;
  224. const thr_ = document.getElementById(id_);
  225. let style = 'width:70%;';
  226. style += 'height:200px;';
  227. //style += 'background: blue;';
  228. style += 'position:absolute;top:0;left:0;';
  229. style += 'z-index:1;';
  230. thr_.style.cssText = style;
  231. } else {
  232. const id_ = 'othe-video-' + elm.swichindex;
  233. const thr_ = document.getElementById(id_);
  234. const left_ = (width / 5) * (elm.swichindex - 1);
  235. let style = 'width:20%;';
  236. style += 'height:70px;';
  237. style += 'background: blue;';
  238. style += 'position:absolute;top:200;';
  239. style = 'left:' + left_ + 'px;';
  240. thr_.style.cssText = style;
  241. }
  242. }
  243. } else {
  244. if (this.othedivshow) {
  245. for (const i = 1; i < 6; i++) {
  246. const id_ = 'othe-video-' + i;
  247. const thr_ = document.getElementById(id_);
  248. const left_ = (width / 5) * (i - 1);
  249. let style = 'width:20%;';
  250. style += 'height:70px;';
  251. style += 'background: blue;';
  252. style += 'position:absolute;top:200;';
  253. style = 'left:' + left_ + 'px;';
  254. thr_.style.cssText = style;
  255. }
  256. }
  257. }
  258. const lvr_ = document.getElementById('look-video-right');
  259. let stylel = 'width:30%;';
  260. stylel += 'height:200px;';
  261. lvr_.style.cssText = stylel;
  262. },
  263. async recordSave() {
  264. console.log(2121);
  265. let data = {};
  266. data.type = '1';
  267. data.roomid = this.id;
  268. data.roomname = this.roomname;
  269. data.userid = this.user.uid;
  270. data.username = this.user.name;
  271. const res = await this.lookrecord(data);
  272. },
  273. async sqClick() {
  274. let data = {};
  275. data.roomid = this.id;
  276. data.isxf = this.isxf;
  277. data.userid = this.user.uid;
  278. const res = await this.lookupdate(data);
  279. if (this.$checkRes(res)) {
  280. console.log(res.data);
  281. this.$message({
  282. message: '操作成功',
  283. type: 'success',
  284. });
  285. }
  286. },
  287. async tabsClick(name, title) {
  288. if (title === '参与成员') {
  289. this.lookuserQuery();
  290. }
  291. },
  292. async lookuserQuery({ skip = 0, limit = 1000 } = {}) {
  293. const info = { roomid: this.id };
  294. let res = await this.lookquery({ skip, limit, ...info });
  295. this.$set(this, `userList`, res.data);
  296. },
  297. async chatSearch({ skip = 0, limit = 1000 } = {}) {
  298. const info = { roomid: this.id };
  299. let res = await this.query({ skip, limit, ...info });
  300. this.$set(this, `dataList`, res.data);
  301. },
  302. async chatCreate() {
  303. let data = {};
  304. data.roomid = this.id;
  305. data.type = '0';
  306. data.content = this.content;
  307. data.sendid = this.user.uid;
  308. data.sendname = this.user.name;
  309. const res = await this.create(data);
  310. if (this.$checkRes(res)) {
  311. //this.$message('发送成功');
  312. this.content = '';
  313. }
  314. },
  315. channel() {
  316. console.log('in function:');
  317. console.log(`/exchange/switch_shmai_` + this.id);
  318. this.$stomp({
  319. [`/exchange/public_chat_` + this.id]: this.onMessage,
  320. });
  321. this.$stomp({
  322. [`/exchange/switch_role_` + this.user.uid]: this.onSwichMessage,
  323. });
  324. this.$stomp({
  325. [`/exchange/switch_shmai_` + this.id]: this.onSwichShmaiMessage,
  326. });
  327. this.$stomp({
  328. [`/exchange/quest_publish_` + this.id]: this.onQueMessage,
  329. });
  330. // this.$stomp({
  331. // [`/exchange/othe_publish_` + this.id]: this.onOtheMessage,
  332. // });
  333. },
  334. onMessage(message) {
  335. // console.log('receive a message: ', message.body);
  336. let body = _.get(message, 'body');
  337. if (body) {
  338. body = JSON.parse(body);
  339. this.dataList.push(body);
  340. this.content = '';
  341. }
  342. this.$nextTick(() => {
  343. document.getElementById('chatSell').scrollTop = document.getElementById('chatSell').scrollHeight + 275;
  344. });
  345. },
  346. onQueMessage(message) {
  347. // console.log('receive a message: ', message.body);
  348. this.showQuest = true;
  349. let body = _.get(message, 'body');
  350. if (body) {
  351. body = JSON.parse(body);
  352. this.queid = body.queid;
  353. this.questSearch();
  354. }
  355. },
  356. onSwichMessage(message) {
  357. // console.log('receive a message: ', message.body);
  358. let body = _.get(message, 'body');
  359. if (body) {
  360. body = JSON.parse(body);
  361. if (body.switchrole === 'anchor' && body.userid === this.user.uid) {
  362. this.switchbtn = true;
  363. this.switchmeetbtn = true;
  364. this.roomMeetSwich();
  365. } else {
  366. this.switchbtn = false;
  367. this.switchmeetbtn = false;
  368. const videoTrack = this.localStream_.getVideoTrack();
  369. if (videoTrack) {
  370. this.localStream_.removeTrack(videoTrack).then(() => {
  371. console.log('remove video call success');
  372. // 关闭摄像头
  373. videoTrack.stop();
  374. this.client_.unpublish(this.localStream_).then(() => {
  375. // 取消发布本地流成功
  376. });
  377. });
  378. }
  379. }
  380. }
  381. },
  382. onSwichShmaiMessage(message) {
  383. let body = _.get(message, 'body');
  384. console.log(body);
  385. console.log(this.user.uid);
  386. if (body) {
  387. body = JSON.parse(body);
  388. this.swichposition(body.shmaiid);
  389. }
  390. },
  391. onOtheMessage(message) {
  392. let body = _.get(message, 'body');
  393. if (body) {
  394. body = JSON.parse(body);
  395. if (body.otheid) {
  396. this.switchbtn = true;
  397. this.roomMeetBtn();
  398. } else {
  399. this.switchbtn = false;
  400. }
  401. }
  402. },
  403. async userswichrole() {
  404. // 根据房间id查询房间详细信息
  405. let result = await this.lookuserswichrole({ roomid: this.id, userid: this.user.uid });
  406. if (this.$checkRes(result)) {
  407. if (result.data && result.data.switchrole === 'anchor') {
  408. this.switchbtn = true;
  409. }
  410. }
  411. },
  412. roomMeetBtn() {
  413. const url = '/pages/meeting/meeting?uid=' + this.user.uid + '&username=' + this.user.name + '&rid=' + this.id + '&roomname=' + this.roomname;
  414. console.log(url);
  415. wx.miniProgram.navigateTo({ url });
  416. },
  417. async roomMeetSwich() {
  418. this.othedivshow = true;
  419. this.oheight = '270px';
  420. this.otheheight = '70px';
  421. if (this.iscamera) {
  422. const videoTrack = this.localStream_.getVideoTrack();
  423. if (videoTrack) {
  424. this.localStream_.removeTrack(videoTrack).then(() => {
  425. console.log('remove video call success');
  426. // 关闭摄像头
  427. videoTrack.stop();
  428. this.client_.unpublish(this.localStream_).then(() => {
  429. // 取消发布本地流成功
  430. if (this.index_ > 0) {
  431. this.index_ = this.index_ - 1;
  432. }
  433. });
  434. });
  435. }
  436. this.iscamera = false;
  437. } else {
  438. this.iscamera = true;
  439. const _userid = 'meetu-' + this.userId_;
  440. this.localStream_ = await TRTC.createStream({
  441. audio: true,
  442. video: true,
  443. // cameraId: this.cameraId,
  444. // microphoneId: this.microphoneId,
  445. userId: _userid,
  446. });
  447. this.localStream_.setVideoProfile('480p');
  448. await this.localStream_.initialize();
  449. console.log('initialize local stream success');
  450. // publish the local stream
  451. await this.client_.publish(this.localStream_);
  452. this.index_ = this.index_ + 1;
  453. if (this.index_ < 6) {
  454. const newdata = { swichuserid: this.userId_, swichindex: this.index_ };
  455. this.swichusers.push(newdata);
  456. const id_ = 'othe-video-' + this.index_;
  457. console.log(id_);
  458. this.localStream_.play(id_);
  459. }
  460. }
  461. },
  462. async questSearch() {
  463. if (this.queid) {
  464. const result = await this.questfetch(this.queid);
  465. if (this.$checkRes(result)) {
  466. console.log(result.data);
  467. this.$set(this, `questInfo`, result.data);
  468. }
  469. }
  470. },
  471. async submitQuest() {
  472. let form = { roomid: this.id, userid: this.user.uid, questionnaireid: this.queid };
  473. let answers = [];
  474. for (const question of this.questInfo.question) {
  475. answers.push({ questionid: question._id, answer: JSON.stringify(question.answer) });
  476. }
  477. form.answers = answers;
  478. console.log(form);
  479. let res = await this.upcreate(form);
  480. if (res.errcode == '0') {
  481. this.showQuest = false;
  482. }
  483. },
  484. async lookuserSearch() {
  485. if (this.user.uid) {
  486. let data = {};
  487. data.roomid = this.id;
  488. data.roomname = this.roomname;
  489. data.userid = this.user.uid;
  490. data.username = this.user.name;
  491. const res = await this.lookuserFetch(data);
  492. }
  493. // 根据房间id查询房间详细信息
  494. let result = await this.fetch(this.id);
  495. if (this.$checkRes(result)) {
  496. console.log(result.data);
  497. this.$set(this, `roomInfos`, result.data);
  498. // 根据房间信息判断是否回答问卷
  499. if (result.data.isque === '1') {
  500. const info = { roomid: this.id, userid: this.user.uid, questionnaireid: result.data.queid };
  501. const skip = 0;
  502. const limit = 10;
  503. const upres = await this.upquery({ skip, limit, ...info });
  504. if (this.$checkRes(upres)) {
  505. if (upres.data.length === 0) {
  506. this.showQuest = true;
  507. this.queid = result.data.queid;
  508. this.questSearch();
  509. }
  510. }
  511. }
  512. // 根据是否上麦进行上麦判断
  513. }
  514. },
  515. async lookusercountsel() {
  516. // 根据房间id查询房间详细信息
  517. let result = await this.lookusercount({ roomname: this.roomname });
  518. if (this.$checkRes(result)) {
  519. console.log(result.total);
  520. this.$set(this, `total`, result.total);
  521. }
  522. },
  523. onSubmit() {
  524. console.log(this.sendmemo);
  525. },
  526. async initclient() {
  527. this.userId_ = this.user.uid;
  528. const res = await this.gensignFetch({ userid: this.userId_ });
  529. if (this.$checkRes(res)) {
  530. this.client_ = TRTC.createClient({
  531. mode: 'live',
  532. sdkAppId: this.sdkAppId_,
  533. userId: this.userId_,
  534. userSig: res.data,
  535. });
  536. await this.client_.join({ roomId: this.roomname, role: 'anchor' });
  537. this.client_.on('stream-subscribed', event => {
  538. const remoteStream = event.stream;
  539. // 远端流订阅成功,播放远端音视频流
  540. console.log(remoteStream);
  541. this.show = true;
  542. console.log('111' + remoteStream.getType());
  543. console.log('111' + remoteStream.getUserId());
  544. console.log('111' + remoteStream.getId());
  545. const userid_ = remoteStream.getUserId();
  546. const res_ = userid_.indexOf('-');
  547. const useridsplit_ = userid_.substring(0, 5);
  548. console.log('222--->' + useridsplit_);
  549. if (useridsplit_ === 'share') {
  550. this.lvideoid_ = 'video_' + remoteStream.getId();
  551. this.swichposition();
  552. remoteStream
  553. .play('look-video-left')
  554. .then(() => {
  555. // autoplay success
  556. // 播放成功时调用css属性
  557. const _lvideoid_ = document.getElementById(this.lvideoid_);
  558. const style = 'width: 100%; height: 100%; position: absolute; transform: rotateY(0); object-fit: fill';
  559. _lvideoid_.style.cssText = style;
  560. })
  561. .catch(e => {
  562. const errorCode = e.getCode();
  563. if (errorCode === 0x4043) {
  564. // PLAY_NOT_ALLOWED,引导用户手势操作恢复音视频播放
  565. remoteStream.resume();
  566. }
  567. });
  568. } else if (useridsplit_ === 'mainr') {
  569. console.log('333');
  570. this.rvideoid_ = 'video_' + remoteStream.getId();
  571. remoteStream
  572. .play('look-video-right')
  573. .then(() => {
  574. // autoplay success
  575. })
  576. .catch(e => {
  577. const errorCode = e.getCode();
  578. if (errorCode === 0x4043) {
  579. // PLAY_NOT_ALLOWED,引导用户手势操作恢复音视频播放
  580. remoteStream.resume();
  581. }
  582. });
  583. } else if (useridsplit_ === 'other') {
  584. console.log('333');
  585. this.rvideoid_ = 'video_' + remoteStream.getId();
  586. remoteStream
  587. .play('look-video-right')
  588. .then(() => {
  589. // autoplay success
  590. })
  591. .catch(e => {
  592. const errorCode = e.getCode();
  593. if (errorCode === 0x4043) {
  594. // PLAY_NOT_ALLOWED,引导用户手势操作恢复音视频播放
  595. remoteStream.resume();
  596. }
  597. });
  598. } else if (useridsplit_ === 'meetu') {
  599. console.log('333');
  600. console.log('公众号进入画面' + this.index_);
  601. this.index_ = this.index_ + 1;
  602. if (this.index_ < 6) {
  603. const id_ = 'othe-video-' + this.index_;
  604. console.log(id_);
  605. const swichuserid = useridsplit_.substring(1);
  606. const newdata = { swichuserid: useridsplit_.substring(1), swichindex: this.index_ };
  607. this.swichusers.push(newdata);
  608. if (this.user.uid === useridsplit_.substring(1)) {
  609. this.userindex_ = this.index_;
  610. }
  611. remoteStream.play(id_);
  612. }
  613. } else if (useridsplit_ === 'wxxcx') {
  614. console.log('小程序进入画面' + this.index_);
  615. this.index_ = this.index_ + 1;
  616. if (this.index_ < 6) {
  617. const id_ = 'othe-video-' + this.index_;
  618. console.log(id_);
  619. remoteStream.play(id_);
  620. }
  621. }
  622. });
  623. // 监听远端流增加事件
  624. this.client_.on('stream-added', event => {
  625. const remoteStream = event.stream;
  626. console.log('222' + remoteStream.getType());
  627. // 订阅远端音频和视频流
  628. this.client_.subscribe(remoteStream, { audio: true, video: true }).catch(e => {
  629. console.error('failed to subscribe remoteStream');
  630. });
  631. });
  632. this.client_.on('stream-removed', event => {
  633. const remoteStream = event.stream;
  634. console.log('stop----');
  635. const userid_ = remoteStream.getUserId();
  636. const useridsplit_ = userid_.substring(0, 5);
  637. if (useridsplit_ === 'wxxcx' || useridsplit_ === 'meetu') {
  638. console.log('退出userid_' + useridsplit_);
  639. // 订阅远端音频和视频流
  640. if (this.index_ > 0) {
  641. this.index_ = this.index_ - 1;
  642. }
  643. }
  644. remoteStream.stop();
  645. });
  646. this.client_.on('mute-video', event => {
  647. const remoteStream = event.stream;
  648. console.log('退出');
  649. console.log('退出remoteStream' + remoteStream);
  650. const userid_ = remoteStream.getUserId();
  651. const useridsplit_ = userid_.substring(0, 5);
  652. console.log('退出userid_' + userid_);
  653. if (useridsplit_ === 'wxxcx' || useridsplit_ === 'meetu') {
  654. console.log('退出userid_' + useridsplit_);
  655. // 订阅远端音频和视频流
  656. if (this.index_ > 0) {
  657. this.index_ = this.index_ - 1;
  658. }
  659. }
  660. console.log('333--index---->' + this.index);
  661. });
  662. }
  663. },
  664. imgclick(url) {
  665. location.href = url;
  666. },
  667. full() {
  668. this.show = true;
  669. const width = document.documentElement.clientWidth;
  670. const height = document.documentElement.clientHeight;
  671. if (!this.isscreen) {
  672. console.log('全屏');
  673. this.isscreen = true;
  674. this.oheight = height;
  675. const transformid_ = document.getElementById('transformid');
  676. let style = 'width:' + height + 'px;';
  677. style += 'height:' + width + 'px;';
  678. style += '-webkit-transform: rotate(90deg); transform: rotate(90deg);';
  679. // 注意旋转中点的处理
  680. style += '-webkit-transform-origin: ' + width / 2 + 'px ' + width / 2 + 'px;';
  681. style += 'transform-origin: ' + width / 2 + 'px ' + width / 2 + 'px;';
  682. transformid_.style.cssText = style;
  683. this.transform = 'rotate(90deg)';
  684. // this.vwidth = height;
  685. console.log(height);
  686. if (this.othedivshow) {
  687. this.vheight = `${width - 70}px`;
  688. this.vwidth = `${height}px`;
  689. this.lheight = `${width - 70}px`;
  690. this.rheight = `${width - 70}px`;
  691. } else {
  692. this.vheight = `${width}px`;
  693. this.vwidth = `${height}px`;
  694. this.lheight = `${width}px`;
  695. this.rheight = `${width}px`;
  696. }
  697. this.btop = `${height - 40}px`;
  698. this.bright = `${width - 50}px`;
  699. if (this.othedivshow) {
  700. const othediv_ = document.getElementById('othediv');
  701. let styleothe = 'width:' + height + 'px;';
  702. styleothe += 'height:' + 70 + 'px;';
  703. styleothe += '-webkit-transform: rotate(90deg); transform: rotate(90deg);';
  704. // // 注意旋转中点的处理
  705. styleothe += '-webkit-transform-origin: ' + width / 2 + 'px ' + width / 2 + 'px;';
  706. styleothe += 'transform-origin: ' + width / 2 + 'px ' + width / 2 + 'px;';
  707. othediv_.style.cssText = styleothe;
  708. this.otheheight = '70px';
  709. this.othewidth = '20%';
  710. const ppp_ = `${width - 70}px`;
  711. this.othepadding = `${width - 70}px 0 0 0`;
  712. }
  713. } else {
  714. console.log('退出全屏');
  715. this.isscreen = false;
  716. if (this.othedivshow) {
  717. this.oheight = '270px';
  718. } else {
  719. this.oheight = '200px';
  720. }
  721. const transformid_ = document.getElementById('transformid');
  722. let style = 'width:' + width + 'px;';
  723. style += 'height: 200px;';
  724. transformid_.style.cssText = style;
  725. this.transform = 'rotate(0deg)';
  726. // this.vwidth = height;
  727. console.log(height);
  728. this.vheight = `200px`;
  729. this.vwidth = `${width}px`;
  730. this.lheight = `200px`;
  731. this.rheight = `200px`;
  732. this.btop = `167px`;
  733. this.bright = `10px`;
  734. if (this.othedivshow) {
  735. const othediv_ = document.getElementById('othediv');
  736. let styleothe = 'width:' + width + 'px;';
  737. styleothe += 'height:' + 70 + 'px;';
  738. // // 注意旋转中点的处理
  739. othediv_.style.cssText = styleothe;
  740. this.otheheight = '70px';
  741. this.othewidth = '20%';
  742. const ppp_ = `${width - 70}px`;
  743. this.othepadding = '200px 0 0 0';
  744. }
  745. }
  746. },
  747. },
  748. computed: {
  749. ...mapState(['user']),
  750. id() {
  751. return this.$route.query.id;
  752. },
  753. roomname() {
  754. return this.$route.query.roomname;
  755. },
  756. pageTitle() {
  757. return `${this.$route.meta.title}`;
  758. },
  759. },
  760. metaInfo() {
  761. return { title: this.$route.meta.title };
  762. },
  763. };
  764. </script>
  765. <style lang="less" scoped>
  766. .video {
  767. top: 0;
  768. left: 0;
  769. width: 100%;
  770. }
  771. .content {
  772. padding: 10px;
  773. }
  774. .info {
  775. .title {
  776. text-align: center;
  777. padding: 10px 0;
  778. font-size: 16px;
  779. font-weight: bold;
  780. }
  781. .num {
  782. padding: 10px 0;
  783. font-size: 16px;
  784. }
  785. .advert {
  786. background: #fff;
  787. padding: 10px;
  788. }
  789. .chat {
  790. min-height: 280px;
  791. max-height: 300px;
  792. overflow-y: auto;
  793. padding: 0 0 50px 0;
  794. .chatInfo {
  795. .list {
  796. margin: 10px 0 10px 0;
  797. span:first-child {
  798. float: left;
  799. width: 17%;
  800. text-align: center;
  801. overflow: hidden;
  802. text-overflow: ellipsis;
  803. white-space: nowrap;
  804. // font-weight: bold;
  805. }
  806. span:last-child {
  807. float: right;
  808. width: 82%;
  809. }
  810. }
  811. }
  812. }
  813. .submit {
  814. width: 100%;
  815. position: absolute;
  816. bottom: 0px;
  817. .el-button {
  818. width: 100%;
  819. padding: 20px 0;
  820. }
  821. }
  822. }
  823. .my-swipe .van-swipe-item {
  824. color: #fff;
  825. font-size: 20px;
  826. line-height: 120px;
  827. text-align: center;
  828. background-color: #39a9ed;
  829. }
  830. /deep/.video-js {
  831. height: 190px !important;
  832. border-radius: 10px;
  833. }
  834. .look-video-left {
  835. float: left;
  836. background: #000;
  837. grid-area: 1/1/3/4;
  838. justify-content: flex-end;
  839. }
  840. .look-video-right {
  841. float: right;
  842. background: #000;
  843. grid-area: 1/1/3/4;
  844. justify-content: flex-end;
  845. }
  846. .othe-video-left {
  847. float: left;
  848. background: #000;
  849. grid-area: 1/1/3/4;
  850. justify-content: flex-end;
  851. }
  852. .wrapper {
  853. background: #000;
  854. position: absolute;
  855. width: 100%;
  856. }
  857. .van-overlay {
  858. position: fixed;
  859. top: 0;
  860. left: 0;
  861. z-index: 1;
  862. width: 100%;
  863. height: 200px;
  864. background-color: rgba(0, 0, 0, 0.7);
  865. }
  866. .videoBtn {
  867. z-index: 999;
  868. position: absolute;
  869. }
  870. .userList {
  871. height: 300px;
  872. min-height: 300px;
  873. overflow-y: auto;
  874. padding: 0 10px;
  875. margin: 0 0 10px 0;
  876. }
  877. .questpopup {
  878. padding: 10px 10px;
  879. }
  880. .questpopup div {
  881. padding: 8px 0 0 5px;
  882. }
  883. .questtitle {
  884. padding: 8px 0 0 5px;
  885. text-align: center;
  886. font-size: 18px;
  887. font-weight: bold;
  888. }
  889. .questbtn {
  890. text-align: center;
  891. padding: 10px 0 15px 0;
  892. }
  893. /deep/.van-cell {
  894. padding: 25px 16px;
  895. font-size: 16px;
  896. }
  897. </style>