roomMeet.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <div id="roomsDetail">
  3. <el-row>
  4. <el-col :span="24" class="info">
  5. <el-col :span="24" class="video">
  6. <el-col :span="24" class="videoMeet">
  7. <el-col :span="18" class="one">
  8. <div id="look-video-1" class="video-box col-div lookvideomain" style="justify-content: flex-end"></div>
  9. </el-col>
  10. <el-col :span="6" class="two">
  11. <el-col :span="24" class="twoOne">
  12. <div id="look-video-2" class="video-box col-div lookvideo" style="justify-content: flex-end"></div>
  13. </el-col>
  14. <el-col :span="24" class="twoOne">
  15. <div id="look-video-3" class="video-box col-div lookvideo" style="justify-content: flex-end"></div>
  16. </el-col>
  17. <el-col :span="24" class="twoOne">
  18. <div id="look-video-4" class="video-box col-div lookvideo" style="justify-content: flex-end"></div>
  19. </el-col>
  20. </el-col>
  21. <el-col :span="6" class="three">
  22. <div id="look-video-5" class="video-box col-div lookvideo" style="justify-content: flex-end"></div>
  23. </el-col>
  24. <el-col :span="6" class="three">
  25. <div id="look-video-6" class="video-box col-div lookvideo" style="justify-content: flex-end"></div>
  26. </el-col>
  27. <el-col :span="6" class="three">
  28. <div id="look-video-7" class="video-box col-div lookvideo" style="justify-content: flex-end"></div>
  29. </el-col>
  30. <el-col :span="6" class="three">
  31. <div id="look-video-8" class="video-box col-div lookvideo" style="justify-content: flex-end"></div>
  32. </el-col>
  33. </el-col>
  34. <el-col :span="24" class="videoBtn">
  35. <el-button :type="typevalue" round @click="liveon()" size="mini"><i class="el-icon-camera-solid"></i></el-button>
  36. </el-col>
  37. </el-col>
  38. <el-col :span="24" class="down">
  39. <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
  40. <el-tab-pane label="互动" name="first">
  41. <el-col :span="24" class="chat">
  42. <el-col :span="24" class="chatInfo">
  43. <el-col :span="24" class="list" v-for="(item, index) in dataList" :key="index">
  44. <p>
  45. <span :class="item.sendname == user.name ? 'selfColor' : ''">{{ item.sendname }}</span>
  46. <span>{{ item.content }}</span>
  47. </p>
  48. </el-col>
  49. </el-col>
  50. <el-col :span="24" class="submit">
  51. <el-col :span="19" class="input">
  52. <el-input type="textarea" maxlength="5000" show-word-limit v-model="content"></el-input>
  53. </el-col>
  54. <el-col :span="5" class="btn">
  55. <el-button type="primary" size="mini" @click="chatCreate">发送</el-button>
  56. </el-col>
  57. </el-col>
  58. </el-col>
  59. </el-tab-pane>
  60. </el-tabs>
  61. </el-col>
  62. </el-col>
  63. </el-row>
  64. </div>
  65. </template>
  66. <script>
  67. import TRTC from 'trtc-js-sdk';
  68. import { mapState, createNamespacedHelpers } from 'vuex';
  69. import Vue from 'vue';
  70. import { Swipe, SwipeItem, Lazyload } from 'vant';
  71. import { Image as VanImage } from 'vant';
  72. Vue.use(Swipe);
  73. Vue.use(SwipeItem);
  74. Vue.use(VanImage);
  75. Vue.use(Lazyload);
  76. const { mapActions: gensign } = createNamespacedHelpers('gensign');
  77. const { mapActions: room } = createNamespacedHelpers('room');
  78. const { mapActions: chat } = createNamespacedHelpers('chat');
  79. export default {
  80. name: 'roomsDetail',
  81. props: {},
  82. components: {},
  83. data: function() {
  84. return {
  85. client_: null,
  86. localStream_: null,
  87. sdkAppId_: '1400380125',
  88. userId_: '',
  89. userSig_: '',
  90. roomInfos: {},
  91. sendmemo: '',
  92. total: 0,
  93. content: '',
  94. dataList: [],
  95. activeName: 'first',
  96. iscamera: false,
  97. typevalue: 'warning',
  98. };
  99. },
  100. created() {
  101. this.initclient();
  102. this.lookuserSearch();
  103. this.lookusercountsel();
  104. this.chatSearch();
  105. },
  106. mounted() {
  107. this.channel();
  108. },
  109. methods: {
  110. ...gensign(['gensignFetch']),
  111. ...room(['lookuserFetch', 'fetch', 'lookusercount']),
  112. ...chat(['query', 'create']),
  113. async chatSearch({ skip = 0, limit = 1000 } = {}) {
  114. const info = { roomid: this.id };
  115. let res = await this.query({ skip, limit, ...info });
  116. this.$set(this, `dataList`, res.data);
  117. },
  118. async chatCreate() {
  119. let data = {};
  120. data.roomid = this.id;
  121. data.type = '1';
  122. data.content = this.content;
  123. data.sendid = this.user.uid;
  124. data.sendname = this.user.name;
  125. const res = await this.create(data);
  126. if (this.$checkRes(res)) {
  127. console.log(res.data);
  128. }
  129. },
  130. channel() {
  131. console.log('in function:');
  132. this.$stomp({
  133. [`/exchange/public_chat_` + this.id]: this.onMessage,
  134. });
  135. },
  136. onMessage(message) {
  137. // console.log('receive a message: ', message.body);
  138. let body = _.get(message, 'body');
  139. if (body) {
  140. body = JSON.parse(body);
  141. this.dataList.push(body);
  142. this.content = '';
  143. }
  144. // const { content, contenttype, sendid, sendname, icon, groupid, sendtime, type } = message.headers;
  145. // let object = { content, contenttype, sendid, sendname, icon, groupid, sendtime, type };
  146. // this.list.push(object);
  147. },
  148. async lookuserSearch() {
  149. let data = {};
  150. data.roomid = this.id;
  151. data.roomname = this.roomname;
  152. data.userid = this.user.userid;
  153. data.username = this.user.name;
  154. const res = await this.lookuserFetch(data);
  155. // 根据房间id查询房间详细信息
  156. let result = await this.fetch(this.id);
  157. if (this.$checkRes(result)) {
  158. console.log(result.data);
  159. this.$set(this, `roomInfos`, result.data);
  160. }
  161. },
  162. async lookusercountsel() {
  163. // 根据房间id查询房间详细信息
  164. let result = await this.lookusercount({ roomname: this.roomname });
  165. if (this.$checkRes(result)) {
  166. console.log(result.total);
  167. this.$set(this, `total`, result.total);
  168. }
  169. },
  170. async initclient() {
  171. this.userId_ = this.user.uid;
  172. const res = await this.gensignFetch({ userid: this.userId_ });
  173. if (this.$checkRes(res)) {
  174. this.userSig_ = res.data;
  175. this.client_ = TRTC.createClient({
  176. mode: 'live',
  177. sdkAppId: this.sdkAppId_,
  178. userId: this.userId_,
  179. userSig: res.data,
  180. });
  181. await this.client_.join({ roomId: this.roomname, role: 'anchor' });
  182. let i = 0;
  183. this.client_.on('stream-subscribed', event => {
  184. const remoteStream = event.stream;
  185. // 远端流订阅成功,播放远端音视频流
  186. console.log('111' + remoteStream.getType());
  187. i = i + 1;
  188. if (i < 8) {
  189. const id_ = 'look-video-' + i;
  190. remoteStream.play(id_);
  191. }
  192. });
  193. // 监听远端流增加事件
  194. this.client_.on('stream-added', event => {
  195. const remoteStream = event.stream;
  196. console.log('222' + remoteStream.getType());
  197. // 订阅远端音频和视频流
  198. this.client_.subscribe(remoteStream, { audio: true, video: true }).catch(e => {
  199. console.error('failed to subscribe remoteStream');
  200. });
  201. });
  202. }
  203. },
  204. async liveon() {
  205. if (this.iscamera) {
  206. const videoTrack = this.localStream_.getVideoTrack();
  207. if (videoTrack) {
  208. this.localStream_.removeTrack(videoTrack).then(() => {
  209. console.log('remove video call success');
  210. // 关闭摄像头
  211. videoTrack.stop();
  212. this.client_.unpublish(this.localStream_).then(() => {
  213. // 取消发布本地流成功
  214. });
  215. });
  216. }
  217. this.iscamera = false;
  218. this.typevalue = 'warning';
  219. } else {
  220. this.iscamera = true;
  221. this.typevalue = 'success';
  222. this.localStream_ = await TRTC.createStream({
  223. audio: true,
  224. video: true,
  225. // cameraId: this.cameraId,
  226. // microphoneId: this.microphoneId,
  227. userId: this.userId_,
  228. });
  229. this.localStream_.setVideoProfile('480p');
  230. await this.localStream_.initialize();
  231. console.log('initialize local stream success');
  232. // publish the local stream
  233. await this.client_.publish(this.localStream_);
  234. this.localStream_.play('look-video-8');
  235. }
  236. },
  237. imgclick(url) {
  238. location.href = url;
  239. },
  240. handleClick(tab, event) {
  241. console.log(tab, event);
  242. },
  243. },
  244. computed: {
  245. ...mapState(['user']),
  246. id() {
  247. return this.$route.query.id;
  248. },
  249. roomname() {
  250. return this.$route.query.roomname;
  251. },
  252. pageTitle() {
  253. return `${this.$route.meta.title}`;
  254. },
  255. },
  256. metaInfo() {
  257. return { title: this.$route.meta.title };
  258. },
  259. };
  260. </script>
  261. <style lang="less" scoped>
  262. .info {
  263. .video {
  264. position: relative;
  265. background: #000;
  266. height: 280px;
  267. overflow: hidden;
  268. .videoMeet {
  269. .one {
  270. height: 210px;
  271. overflow: hidden;
  272. }
  273. .two {
  274. height: 210px;
  275. overflow: hidden;
  276. .twoOne {
  277. height: 70px;
  278. overflow: hidden;
  279. }
  280. }
  281. .three {
  282. height: 70px;
  283. overflow: hidden;
  284. }
  285. }
  286. .videoBtn {
  287. position: absolute;
  288. top: 10px;
  289. left: 10px;
  290. }
  291. }
  292. .down {
  293. border-top: 1px solid #ccc;
  294. min-height: 290px;
  295. background: #fff;
  296. .chat {
  297. height: 330px;
  298. .chatInfo {
  299. height: 275px;
  300. overflow-y: auto;
  301. padding: 0 10px;
  302. margin: 0 0 10px 0;
  303. .list {
  304. margin: 0 0 10px 0;
  305. span:first-child {
  306. float: left;
  307. width: 17%;
  308. text-align: center;
  309. overflow: hidden;
  310. text-overflow: ellipsis;
  311. white-space: nowrap;
  312. // font-weight: bold;
  313. }
  314. span:last-child {
  315. float: right;
  316. width: 82%;
  317. }
  318. }
  319. }
  320. .submit {
  321. position: absolute;
  322. bottom: 0;
  323. .el-button {
  324. width: 100%;
  325. padding: 13px 0;
  326. }
  327. }
  328. }
  329. }
  330. }
  331. /deep/.el-button--mini,
  332. .el-button--mini.is-round {
  333. padding: 12px 15px;
  334. border-radius: 0;
  335. }
  336. .my-swipe .van-swipe-item {
  337. color: #fff;
  338. font-size: 20px;
  339. line-height: 150px;
  340. text-align: center;
  341. background-color: #39a9ed;
  342. }
  343. /deep/.video-js {
  344. height: 190px !important;
  345. border-radius: 10px;
  346. }
  347. .lookvideomain {
  348. width: 100%;
  349. height: 210px;
  350. grid-area: 1/1/3/4;
  351. }
  352. .lookvideo {
  353. width: 100%;
  354. height: 70px;
  355. grid-area: 1/1/3/4;
  356. }
  357. /deep/.el-textarea__inner {
  358. padding: 0 15px;
  359. line-height: 20px;
  360. border-radius: 0;
  361. }
  362. .selfColor {
  363. color: #ff0000;
  364. }
  365. </style>