roomDetail.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  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 id="otheplaydiv" :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. zbfpbtn() {
  217. const width = document.documentElement.clientWidth;
  218. const lvr_ = document.getElementById('look-video-right');
  219. let stylel = 'width:30%;';
  220. stylel += 'height:200px;';
  221. lvr_.style.cssText = style;
  222. const lvl_ = document.getElementById('look-video-left');
  223. let stylell = 'width:70%;';
  224. stylell += 'height:200px;';
  225. lvl_.style.cssText = stylell;
  226. },
  227. swichposition(objid) {
  228. console.log('in swichposition---' + objid);
  229. if (objid) {
  230. console.log(this.swichusers);
  231. const width = document.documentElement.clientWidth;
  232. for (const elm of this.swichusers) {
  233. if (elm.swichuserid === objid) {
  234. const id_ = 'othe-video-' + elm.swichindex;
  235. const thr_ = document.getElementById(id_);
  236. let style = 'width:70%;';
  237. style += 'height:200px;';
  238. style += 'position:absolute;top:0;left:0;';
  239. style += 'z-index:1;';
  240. thr_.style.cssText = style;
  241. } else {
  242. const id_ = 'othe-video-' + elm.swichindex;
  243. const thr_ = document.getElementById(id_);
  244. const left_ = (width / 5) * (elm.swichindex - 1);
  245. let style = 'width:20%;';
  246. style += 'height:70px;';
  247. style += 'position:absolute;top:200;';
  248. style = 'left:' + left_ + 'px;';
  249. thr_.style.cssText = style;
  250. }
  251. }
  252. } else {
  253. console.log('share--' + this.othedivshow);
  254. if (this.othedivshow) {
  255. for (const i = 1; i < 6; i++) {
  256. const id_ = 'othe-video-' + i;
  257. const thr_ = document.getElementById(id_);
  258. const left_ = (width / 5) * (i - 1);
  259. let style = 'width:20%;';
  260. style += 'height:70px;';
  261. style += 'background: blue;';
  262. style += 'position:absolute;top:200px;';
  263. style = 'left:' + left_ + 'px;';
  264. thr_.style.cssText = style;
  265. }
  266. }
  267. console.log('share设置大小--');
  268. const lvl_ = document.getElementById('look-video-left');
  269. let stylell = 'width:70%;';
  270. stylell += 'height:200px;';
  271. lvl_.style.cssText = stylell;
  272. }
  273. const lvr_ = document.getElementById('look-video-right');
  274. let stylel = 'width:30%;';
  275. stylel += 'height:200px;';
  276. lvr_.style.cssText = stylel;
  277. },
  278. async recordSave() {
  279. console.log(2121);
  280. let data = {};
  281. data.type = '1';
  282. data.roomid = this.id;
  283. data.roomname = this.roomname;
  284. data.userid = this.user.uid;
  285. data.username = this.user.name;
  286. const res = await this.lookrecord(data);
  287. },
  288. async sqClick() {
  289. let data = {};
  290. data.roomid = this.id;
  291. data.isxf = this.isxf;
  292. data.userid = this.user.uid;
  293. const res = await this.lookupdate(data);
  294. if (this.$checkRes(res)) {
  295. console.log(res.data);
  296. this.$message({
  297. message: '操作成功',
  298. type: 'success',
  299. });
  300. }
  301. },
  302. async tabsClick(name, title) {
  303. if (title === '参与成员') {
  304. this.lookuserQuery();
  305. }
  306. },
  307. async lookuserQuery({ skip = 0, limit = 1000 } = {}) {
  308. const info = { roomid: this.id };
  309. let res = await this.lookquery({ skip, limit, ...info });
  310. this.$set(this, `userList`, res.data);
  311. },
  312. async chatSearch({ skip = 0, limit = 1000 } = {}) {
  313. const info = { roomid: this.id };
  314. let res = await this.query({ skip, limit, ...info });
  315. this.$set(this, `dataList`, res.data);
  316. },
  317. async chatCreate() {
  318. let data = {};
  319. data.roomid = this.id;
  320. data.type = '0';
  321. data.content = this.content;
  322. data.sendid = this.user.uid;
  323. data.sendname = this.user.name;
  324. const res = await this.create(data);
  325. if (this.$checkRes(res)) {
  326. //this.$message('发送成功');
  327. this.content = '';
  328. }
  329. },
  330. channel() {
  331. console.log('in function:');
  332. console.log(`/exchange/switch_shmai_` + this.id);
  333. this.$stomp({
  334. [`/exchange/public_chat_` + this.id]: this.onMessage,
  335. });
  336. this.$stomp({
  337. [`/exchange/switch_role_` + this.user.uid]: this.onSwichMessage,
  338. });
  339. this.$stomp({
  340. [`/exchange/switch_shmai_` + this.id]: this.onSwichShmaiMessage,
  341. });
  342. this.$stomp({
  343. [`/exchange/quest_publish_` + this.id]: this.onQueMessage,
  344. });
  345. // this.$stomp({
  346. // [`/exchange/othe_publish_` + this.id]: this.onOtheMessage,
  347. // });
  348. },
  349. onMessage(message) {
  350. // console.log('receive a message: ', message.body);
  351. let body = _.get(message, 'body');
  352. if (body) {
  353. body = JSON.parse(body);
  354. this.dataList.push(body);
  355. this.content = '';
  356. }
  357. this.$nextTick(() => {
  358. document.getElementById('chatSell').scrollTop = document.getElementById('chatSell').scrollHeight + 275;
  359. });
  360. },
  361. onQueMessage(message) {
  362. // console.log('receive a message: ', message.body);
  363. this.showQuest = true;
  364. let body = _.get(message, 'body');
  365. if (body) {
  366. body = JSON.parse(body);
  367. this.queid = body.queid;
  368. this.questSearch();
  369. }
  370. },
  371. onSwichMessage(message) {
  372. // console.log('receive a message: ', message.body);
  373. let body = _.get(message, 'body');
  374. if (body) {
  375. body = JSON.parse(body);
  376. if (body.switchrole === 'anchor' && body.userid === this.user.uid) {
  377. this.switchbtn = true;
  378. this.switchmeetbtn = true;
  379. this.roomMeetSwich();
  380. } else {
  381. this.switchbtn = false;
  382. this.switchmeetbtn = false;
  383. }
  384. if (body.switchrole !== 'anchor' && body.userid === this.user.uid) {
  385. const videoTrack = this.localStream_.getVideoTrack();
  386. if (videoTrack) {
  387. this.localStream_.removeTrack(videoTrack).then(() => {
  388. console.log('remove video call success');
  389. // 关闭摄像头
  390. videoTrack.stop();
  391. // this.client_.unpublish(this.localStream_).then(() => {
  392. // // 取消发布本地流成功
  393. // });
  394. });
  395. }
  396. }
  397. }
  398. },
  399. onSwichShmaiMessage(message) {
  400. let body = _.get(message, 'body');
  401. console.log(body);
  402. console.log(this.user.uid);
  403. if (body) {
  404. body = JSON.parse(body);
  405. this.swichposition(body.shmaiid);
  406. }
  407. },
  408. onOtheMessage(message) {
  409. let body = _.get(message, 'body');
  410. if (body) {
  411. body = JSON.parse(body);
  412. if (body.otheid) {
  413. this.switchbtn = true;
  414. this.roomMeetBtn();
  415. } else {
  416. this.switchbtn = false;
  417. }
  418. }
  419. },
  420. async userswichrole() {
  421. // 根据房间id查询房间详细信息
  422. let result = await this.lookuserswichrole({ roomid: this.id, userid: this.user.uid });
  423. if (this.$checkRes(result)) {
  424. if (result.data && result.data.switchrole === 'anchor') {
  425. this.switchbtn = true;
  426. }
  427. }
  428. },
  429. roomMeetBtn() {
  430. const url = '/pages/meeting/meeting?uid=' + this.user.uid + '&username=' + this.user.name + '&rid=' + this.id + '&roomname=' + this.roomname;
  431. console.log(url);
  432. wx.miniProgram.navigateTo({ url });
  433. },
  434. async roomMeetSwich() {
  435. this.othedivshow = true;
  436. this.oheight = '270px';
  437. this.otheheight = '70px';
  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 otheplaydiv = document.getElementById('otheplaydiv');
  455. const id_ = 'othe-video-' + this.index_;
  456. // const newdiv = '<div id="' + id_ + '" style="height: 70px, width: 20%" class="video-box col-div othe-video-left"></div>';
  457. // otheplaydiv.appendChild(newdiv);
  458. const newdata = { swichuserid: this.userId_, swichindex: this.index_ };
  459. this.swichusers.push(newdata);
  460. console.log('将用户push到列表里' + this.swichusers);
  461. this.localStream_.play(id_);
  462. }
  463. },
  464. async questSearch() {
  465. if (this.queid) {
  466. const result = await this.questfetch(this.queid);
  467. if (this.$checkRes(result)) {
  468. console.log(result.data);
  469. this.$set(this, `questInfo`, result.data);
  470. }
  471. }
  472. },
  473. async submitQuest() {
  474. let form = { roomid: this.id, userid: this.user.uid, questionnaireid: this.queid };
  475. let answers = [];
  476. for (const question of this.questInfo.question) {
  477. answers.push({ questionid: question._id, answer: JSON.stringify(question.answer) });
  478. }
  479. form.answers = answers;
  480. console.log(form);
  481. let res = await this.upcreate(form);
  482. if (res.errcode == '0') {
  483. this.showQuest = false;
  484. }
  485. },
  486. async lookuserSearch() {
  487. if (this.user.uid) {
  488. let data = {};
  489. data.roomid = this.id;
  490. data.roomname = this.roomname;
  491. data.userid = this.user.uid;
  492. data.username = this.user.name;
  493. const res = await this.lookuserFetch(data);
  494. }
  495. // 根据房间id查询房间详细信息
  496. let result = await this.fetch(this.id);
  497. if (this.$checkRes(result)) {
  498. console.log(result.data);
  499. this.$set(this, `roomInfos`, result.data);
  500. // 根据房间信息判断是否回答问卷
  501. if (result.data.isque === '1') {
  502. const info = { roomid: this.id, userid: this.user.uid, questionnaireid: result.data.queid };
  503. const skip = 0;
  504. const limit = 10;
  505. const upres = await this.upquery({ skip, limit, ...info });
  506. if (this.$checkRes(upres)) {
  507. if (upres.data.length === 0) {
  508. this.showQuest = true;
  509. this.queid = result.data.queid;
  510. this.questSearch();
  511. }
  512. }
  513. }
  514. // 根据是否上麦进行上麦判断
  515. }
  516. },
  517. async lookusercountsel() {
  518. // 根据房间id查询房间详细信息
  519. let result = await this.lookusercount({ roomname: this.roomname });
  520. if (this.$checkRes(result)) {
  521. console.log(result.total);
  522. this.$set(this, `total`, result.total);
  523. }
  524. },
  525. onSubmit() {
  526. console.log(this.sendmemo);
  527. },
  528. async initclient() {
  529. this.userId_ = this.user.uid;
  530. const res = await this.gensignFetch({ userid: this.userId_ });
  531. if (this.$checkRes(res)) {
  532. this.client_ = TRTC.createClient({
  533. mode: 'live',
  534. sdkAppId: this.sdkAppId_,
  535. userId: this.userId_,
  536. userSig: res.data,
  537. });
  538. await this.client_.join({ roomId: this.roomname, role: 'anchor' });
  539. this.client_.on('stream-subscribed', event => {
  540. const remoteStream = event.stream;
  541. // 远端流订阅成功,播放远端音视频流
  542. console.log(remoteStream);
  543. this.show = true;
  544. console.log('111' + remoteStream.getType());
  545. console.log('111' + remoteStream.getUserId());
  546. console.log('111' + remoteStream.getId());
  547. const userid_ = remoteStream.getUserId();
  548. const res_ = userid_.indexOf('-');
  549. const useridsplit_ = userid_.substring(0, 5);
  550. const userid_zs = userid_.substring(5);
  551. console.log('222--->' + useridsplit_);
  552. console.log('555--->' + userid_zs);
  553. if (useridsplit_ === 'share') {
  554. console.log('进入分享模式' + useridsplit_);
  555. this.lvideoid_ = 'video_' + remoteStream.getId();
  556. //this.zbfpbtn();
  557. this.swichposition();
  558. this.othedivshow = false;
  559. this.oheight = '200px';
  560. this.otheheight = '1px';
  561. console.log('进入分享模式' + this.lvideoid_);
  562. remoteStream
  563. .play('look-video-left')
  564. .then(() => {
  565. // autoplay success
  566. // 播放成功时调用css属性
  567. const _lvideoid_ = document.getElementById(this.lvideoid_);
  568. const style = 'width: 100%; height: 200px; position: absolute; transform: rotateY(0); object-fit: fill';
  569. _lvideoid_.style.cssText = style;
  570. })
  571. .catch(e => {
  572. const errorCode = e.getCode();
  573. if (errorCode === 0x4043) {
  574. // PLAY_NOT_ALLOWED,引导用户手势操作恢复音视频播放
  575. remoteStream.resume();
  576. }
  577. });
  578. } else if (useridsplit_ === 'mainr') {
  579. console.log('333');
  580. this.rvideoid_ = 'video_' + remoteStream.getId();
  581. // this.zbfullbtn();
  582. remoteStream
  583. .play('look-video-right')
  584. .then(() => {
  585. // autoplay success
  586. })
  587. .catch(e => {
  588. const errorCode = e.getCode();
  589. if (errorCode === 0x4043) {
  590. // PLAY_NOT_ALLOWED,引导用户手势操作恢复音视频播放
  591. remoteStream.resume();
  592. }
  593. });
  594. } else if (useridsplit_ === 'other') {
  595. console.log('333');
  596. this.rvideoid_ = 'video_' + remoteStream.getId();
  597. remoteStream
  598. .play('look-video-right')
  599. .then(() => {
  600. // autoplay success
  601. })
  602. .catch(e => {
  603. const errorCode = e.getCode();
  604. if (errorCode === 0x4043) {
  605. // PLAY_NOT_ALLOWED,引导用户手势操作恢复音视频播放
  606. remoteStream.resume();
  607. }
  608. });
  609. } else if (useridsplit_ === 'meetu') {
  610. console.log('333');
  611. console.log('公众号进入画面' + this.index_);
  612. this.othedivshow = true;
  613. this.oheight = '270px';
  614. this.otheheight = '70px';
  615. this.iscamera = true;
  616. this.index_ = this.index_ + 1;
  617. if (this.index_ < 6) {
  618. const id_ = 'othe-video-' + this.index_;
  619. console.log(id_);
  620. const newdata = { swichuserid: this.userid_zs, swichindex: this.index_ };
  621. this.swichusers.push(newdata);
  622. console.log('将用户push到列表里' + this.swichusers);
  623. if (this.user.uid === this.userid_zs) {
  624. this.userindex_ = this.index_;
  625. }
  626. remoteStream.play(id_);
  627. }
  628. } else if (useridsplit_ === 'wxxcx') {
  629. console.log('小程序进入画面' + this.index_);
  630. this.index_ = this.index_ + 1;
  631. if (this.index_ < 6) {
  632. const id_ = 'othe-video-' + this.index_;
  633. console.log(id_);
  634. remoteStream.play(id_);
  635. }
  636. }
  637. });
  638. // 监听远端流增加事件
  639. this.client_.on('stream-added', event => {
  640. const remoteStream = event.stream;
  641. console.log('222' + remoteStream.getType());
  642. // 订阅远端音频和视频流
  643. this.client_.subscribe(remoteStream, { audio: true, video: true }).catch(e => {
  644. console.error('failed to subscribe remoteStream');
  645. });
  646. });
  647. this.client_.on('stream-removed', event => {
  648. const remoteStream = event.stream;
  649. console.log('stop----');
  650. if (remoteStream) {
  651. const userid_ = remoteStream.getUserId();
  652. const useridsplit_ = userid_.substring(0, 5);
  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. }
  661. remoteStream.stop();
  662. });
  663. this.client_.on('mute-video', event => {
  664. const remoteStream = event.stream;
  665. console.log('退出');
  666. console.log('退出remoteStream' + remoteStream);
  667. if (remoteStream) {
  668. const userid_ = remoteStream.getUserId();
  669. const useridsplit_ = userid_.substring(0, 5);
  670. console.log('退出userid_' + userid_);
  671. if (useridsplit_ === 'wxxcx' || useridsplit_ === 'meetu') {
  672. console.log('退出userid_' + useridsplit_);
  673. // 订阅远端音频和视频流
  674. if (this.index_ > 0) {
  675. this.index_ = this.index_ - 1;
  676. }
  677. }
  678. }
  679. console.log('333--index---->' + this.index);
  680. });
  681. }
  682. },
  683. imgclick(url) {
  684. location.href = url;
  685. },
  686. full() {
  687. this.show = true;
  688. const width = document.documentElement.clientWidth;
  689. const height = document.documentElement.clientHeight;
  690. if (!this.isscreen) {
  691. console.log('全屏');
  692. this.isscreen = true;
  693. this.oheight = height;
  694. const transformid_ = document.getElementById('transformid');
  695. let style = 'width:' + height + 'px;';
  696. style += 'height:' + width + 'px;';
  697. style += '-webkit-transform: rotate(90deg); transform: rotate(90deg);';
  698. // 注意旋转中点的处理
  699. style += '-webkit-transform-origin: ' + width / 2 + 'px ' + width / 2 + 'px;';
  700. style += 'transform-origin: ' + width / 2 + 'px ' + width / 2 + 'px;';
  701. transformid_.style.cssText = style;
  702. this.transform = 'rotate(90deg)';
  703. // this.vwidth = height;
  704. console.log(height);
  705. if (this.othedivshow) {
  706. this.vheight = `${width - 70}px`;
  707. this.vwidth = `${height}px`;
  708. this.lheight = `${width - 70}px`;
  709. this.rheight = `${width - 70}px`;
  710. } else {
  711. this.vheight = `${width}px`;
  712. this.vwidth = `${height}px`;
  713. this.lheight = `${width}px`;
  714. this.rheight = `${width}px`;
  715. }
  716. this.btop = `${height - 40}px`;
  717. this.bright = `${width - 50}px`;
  718. if (this.othedivshow) {
  719. const othediv_ = document.getElementById('othediv');
  720. let styleothe = 'width:' + height + 'px;';
  721. styleothe += 'height:' + 70 + 'px;';
  722. styleothe += '-webkit-transform: rotate(90deg); transform: rotate(90deg);';
  723. // // 注意旋转中点的处理
  724. styleothe += '-webkit-transform-origin: ' + width / 2 + 'px ' + width / 2 + 'px;';
  725. styleothe += 'transform-origin: ' + width / 2 + 'px ' + width / 2 + 'px;';
  726. othediv_.style.cssText = styleothe;
  727. this.otheheight = '70px';
  728. this.othewidth = '20%';
  729. const ppp_ = `${width - 70}px`;
  730. this.othepadding = `${width - 70}px 0 0 0`;
  731. }
  732. } else {
  733. console.log('退出全屏');
  734. this.isscreen = false;
  735. if (this.othedivshow) {
  736. this.oheight = '270px';
  737. } else {
  738. this.oheight = '200px';
  739. }
  740. const transformid_ = document.getElementById('transformid');
  741. let style = 'width:' + width + 'px;';
  742. style += 'height: 200px;';
  743. transformid_.style.cssText = style;
  744. this.transform = 'rotate(0deg)';
  745. // this.vwidth = height;
  746. console.log(height);
  747. this.vheight = `200px`;
  748. this.vwidth = `${width}px`;
  749. this.lheight = `200px`;
  750. this.rheight = `200px`;
  751. this.btop = `167px`;
  752. this.bright = `10px`;
  753. if (this.othedivshow) {
  754. const othediv_ = document.getElementById('othediv');
  755. let styleothe = 'width:' + width + 'px;';
  756. styleothe += 'height:' + 70 + 'px;';
  757. // // 注意旋转中点的处理
  758. othediv_.style.cssText = styleothe;
  759. this.otheheight = '70px';
  760. this.othewidth = '20%';
  761. const ppp_ = `${width - 70}px`;
  762. this.othepadding = '200px 0 0 0';
  763. }
  764. }
  765. },
  766. },
  767. computed: {
  768. ...mapState(['user']),
  769. id() {
  770. return this.$route.query.id;
  771. },
  772. roomname() {
  773. return this.$route.query.roomname;
  774. },
  775. pageTitle() {
  776. return `${this.$route.meta.title}`;
  777. },
  778. },
  779. metaInfo() {
  780. return { title: this.$route.meta.title };
  781. },
  782. };
  783. </script>
  784. <style lang="less" scoped>
  785. .video {
  786. top: 0;
  787. left: 0;
  788. width: 100%;
  789. }
  790. .content {
  791. padding: 10px;
  792. }
  793. .info {
  794. .title {
  795. text-align: center;
  796. padding: 10px 0;
  797. font-size: 16px;
  798. font-weight: bold;
  799. }
  800. .num {
  801. padding: 10px 0;
  802. font-size: 16px;
  803. }
  804. .advert {
  805. background: #fff;
  806. padding: 10px;
  807. }
  808. .chat {
  809. min-height: 280px;
  810. max-height: 300px;
  811. overflow-y: auto;
  812. padding: 0 0 50px 0;
  813. .chatInfo {
  814. .list {
  815. margin: 10px 0 10px 0;
  816. span:first-child {
  817. float: left;
  818. width: 17%;
  819. text-align: center;
  820. overflow: hidden;
  821. text-overflow: ellipsis;
  822. white-space: nowrap;
  823. // font-weight: bold;
  824. }
  825. span:last-child {
  826. float: right;
  827. width: 82%;
  828. }
  829. }
  830. }
  831. }
  832. .submit {
  833. width: 100%;
  834. position: absolute;
  835. bottom: 0px;
  836. .el-button {
  837. width: 100%;
  838. padding: 20px 0;
  839. }
  840. }
  841. }
  842. .my-swipe .van-swipe-item {
  843. color: #fff;
  844. font-size: 20px;
  845. line-height: 120px;
  846. text-align: center;
  847. background-color: #39a9ed;
  848. }
  849. /deep/.video-js {
  850. height: 190px !important;
  851. border-radius: 10px;
  852. }
  853. .look-video-left {
  854. float: left;
  855. background: #000;
  856. grid-area: 1/1/3/4;
  857. justify-content: flex-end;
  858. }
  859. .look-video-right {
  860. float: right;
  861. background: #000;
  862. grid-area: 1/1/3/4;
  863. justify-content: flex-end;
  864. }
  865. .othe-video-left {
  866. float: left;
  867. background: #000;
  868. grid-area: 1/1/3/4;
  869. justify-content: flex-end;
  870. }
  871. .wrapper {
  872. background: #000;
  873. position: absolute;
  874. width: 100%;
  875. }
  876. .van-overlay {
  877. position: fixed;
  878. top: 0;
  879. left: 0;
  880. z-index: 1;
  881. width: 100%;
  882. height: 200px;
  883. background-color: rgba(0, 0, 0, 0.7);
  884. }
  885. .videoBtn {
  886. z-index: 999;
  887. position: absolute;
  888. }
  889. .userList {
  890. height: 300px;
  891. min-height: 300px;
  892. overflow-y: auto;
  893. padding: 0 10px;
  894. margin: 0 0 10px 0;
  895. }
  896. .questpopup {
  897. padding: 10px 10px;
  898. }
  899. .questpopup div {
  900. padding: 8px 0 0 5px;
  901. }
  902. .questtitle {
  903. padding: 8px 0 0 5px;
  904. text-align: center;
  905. font-size: 18px;
  906. font-weight: bold;
  907. }
  908. .questbtn {
  909. text-align: center;
  910. padding: 10px 0 15px 0;
  911. }
  912. /deep/.van-cell {
  913. padding: 25px 16px;
  914. font-size: 16px;
  915. }
  916. </style>