calling-index.vue
33.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
<template>
<div class="call-container" v-show="dialling || calling || isDialled">
<div class="choose" v-show="isDialled">
<div class="title">
{{ sponsor }}来通话啦
</div>
<div class="buttons">
<div class="accept" @click="handleDebounce(accept,500)"></div>
<div class="refuse" @click="handleDebounce(refuse,500)"></div>
</div>
</div>
<div class="call" v-show="dialling || calling">
<div class="title" v-if="dialling && currentConversationType==='C2C'">
正在呼叫{{toAccount}}...
</div>
<div class="title" v-if="dialling && currentConversationType==='GROUP'">
正在呼叫...
</div>
<!-- <div v-show="this.callingUserList.length < 2 && callType === TRTCCalling.CALL_TYPE.VIDEO_CALL && calling">-->
<!-- <div id="local" @click="changeMainVideo" :class="isLocalMain ? 'small' : 'big'" ></div>-->
<!-- <div v-for="userId in callingUserList" :id="`video-${userId}`" :key="`video-${userId}`" :class="isLocalMain ? 'big' : 'small'" @click="changeMainVideo"></div>-->
<!-- </div>-->
<div v-show=" callType === TRTCCalling.CALL_TYPE.VIDEO_CALL && calling">
<div class="small-group" id="small-group">
<div class="video-box" id="local" ></div>
<div class="video-box" v-for="userId in callingUserList" :id="`video-${userId}`" :key="`video-${userId}`">
</div>
</div>
</div>
<div v-show="callType === TRTCCalling.CALL_TYPE.AUDIO_CALL && calling" class="audio-box">
<div v-show="calling" class="aduio-call">
<img :src="myAvatar" class="audio-img">
<p style="text-align: center">
<span class="nick-text">{{myNick}}</span>
<i v-if="isMicOn" class="el-icon-microphone micr-icon" style="color: #006FFF;"></i>
<i v-else class="el-icon-turn-off-microphone micr-icon" ></i>
</p>
</div>
<div v-for="item in invitedUserInfo " class="aduio-call" :key="`video-${item.userID}`" >
<img :src="item.avatar || defaultAvatar" class="audio-img">
<p style="text-align: center">
<span class="nick-text">{{item.nick || item.userID}}</span>
<i v-if="item.isInvitedMicOn === true || item.isInvitedMicOn == undefined" class="el-icon-microphone micr-icon" style="color: #006FFF;"></i>
<i v-else class="el-icon-turn-off-microphone micr-icon" ></i>
</p>
</div>
</div>
<div class="duration" v-show="calling">
{{ formatDurationStr }}
</div>
<div class="buttons" v-if="callType === TRTCCalling.CALL_TYPE.VIDEO_CALL">
<div :class="isCamOn ? 'videoOn' : 'videoOff'" @click="videoHandler"></div>
<div class="refuse" @click="handleDebounce(leave,500)"></div>
<div :class="isMicOn ? 'micOn' : 'micOff'" @click="micHandler"></div>
</div>
<div class="buttons" v-else>
<!-- <div :class="isCamOn ? 'videoOn' : 'videoOff'" @click="videoHandler"></div>-->
<div class="refuse" @click="handleDebounce(leave,500)"></div>
<div :class="isMicOn ? 'micOn' : 'micOff'" @click="micHandler"></div>
</div>
<!-- <div class="mask" v-show="maskShow" :class="isLocalMain ? 'small' : 'big'" @click="changeMainVideo">-->
<!-- <div>-->
<!-- <img class="image" src="../../../assets/image/camera-max.png"/>-->
<!-- <p class="notice">摄像头未打开</p>-->
<!-- </div>-->
<!-- </div>-->
</div>
</div>
</template>
<script>
import {mapGetters, mapState} from 'vuex'
import { formatDuration } from '../../../utils/formatDuration'
const LOG_PREFIX = 'calling-index'
export default {
name: 'CallLayer',
data() {
return {
timeout:null,
callType:1, //1:audio,2:video
Trtc: undefined,
isCamOn: true,
isMicOn: true,
isInvitedMicOn:true,
maskShow: false,
isLocalMain: true, // 本地视频是否是主屏幕显示
start: 0,
end: 0,
duration: 0,
hangUpTimer: 0, // 通话计时id
ready: false,
dialling: false, // 是否拨打电话中
calling: false, // 是否通话中
isDialled: false, // 是否被呼叫
inviteID:'',
inviteData:{},
sponsor:'', //发起者
invitedUserID:[], //被邀请者
invitedNick:'',
invitedUserInfo:[],
defaultAvatar:'https://imgcache.qq.com/open/qcloud/video/act/webim-avatar/avatar-3.png',
viewLocalDomID:'',
callingUserList:[], // 参加通话的人 ,不包括自己
callingType:'C2C', //区分多人和C2C通话的UI样式
isStartLocalView:false, //本地是否开启
callingTips:{
callEnd:1, //通话结束
callTimeout:5
}
}
},
computed: {
...mapGetters(['toAccount', 'currentConversationType']),
...mapState({
currentConversation: state => state.conversation.currentConversation,
currentUserProfile: state => state.user.currentUserProfile,
callingInfo: state => state.conversation.callingInfo,
userID: state => state.user.userID,
userSig: state => state.user.userSig,
videoRoom: state => state.video.videoRoom,
sdkAppID: state => state.user.sdkAppID
}),
formatDurationStr() {
return formatDuration(this.duration)
},
myAvatar() {
return this.currentUserProfile.avatar || this.defaultAvatar
},
myNick() {
return this.currentUserProfile.nick || this.userID
}
},
created() {
this.initListener()
},
watch: {
callingUserList: {
handler(newValue) {
if(newValue.length < 2 && this.calling) { //单人通话
this.$nextTick(() => {
let elementId = `video-${newValue[0]}`
let element = window.document.getElementById(elementId)
let local = window.document.getElementById('local')
let group_element = window.document.getElementById('small-group')
// element.addEventListener('click', this.changeMainVideo)
// local.addEventListener('click', this.changeMainVideo)
if (!element || !element.classList) {
return
}
if (!local || !local.classList) {
return
}
element && element.classList.remove('video-box')
local && local.classList.remove('video-box')
group_element && group_element.classList.add('small-group_box')
this.isLocalMain ? element.classList.add('big') : element.classList.add('small')
this.isLocalMain ? local.classList.add('small') : element.classList.add('big')
})
return
}
if (newValue.length >= 2 && this.calling) {
let group_element = window.document.getElementById('small-group')
group_element && group_element.classList.remove('small-group_box')
let elements = window.document.getElementById('small-group').childNodes
elements.forEach((item,index) => {
if(index === 0) {
item.classList.remove('small')
}
item.classList.remove('big')
item.classList.add('video-box')
})
}
},
deep: true,
immediate: true
}
},
destroyed() {
this.removeListener()
window.addEventListener('beforeunload', () => {
this.videoCallLogOut()
})
window.addEventListener('leave', () => {
this.videoCallLogOut()
})
},
mounted() {
this.$bus.$on('video-call', this.videoCalling) // 发起通话
this.$bus.$on('audio-call', this.audioCalling) // 发起通话
},
beforeDestroy() {
this.$bus.$off('video-call', this.videoCalling)
this.$bus.$off('audio-call', this.audioCalling) // 发起通话
},
methods: {
videoCallLogOut() { // 针对,刷新页面,关闭Tab,登出情况下,通话断开的逻辑
if (this.dialling || this.calling) {
this.leave()
}
if (this.isDialled) {
this.refuse()
}
},
initListener() {
// sdk内部发生了错误
this.trtcCalling.on(this.TRTCCalling.EVENT.ERROR, this.handleError)
// 被邀请进行通话
this.trtcCalling.on(this.TRTCCalling.EVENT.INVITED, this.handleNewInvitationReceived)
// 有用户同意进入通话,那么会收到此回调
this.trtcCalling.on(this.TRTCCalling.EVENT.USER_ENTER, this.handleUserEnter)
// 如果有用户同意离开通话,那么会收到此回调
this.trtcCalling.on(this.TRTCCalling.EVENT.USER_LEAVE, this.handleUserLeave)
// 用户拒绝通话
this.trtcCalling.on(this.TRTCCalling.EVENT.REJECT, this.handleInviteeReject)
//邀请方忙线
this.trtcCalling.on(this.TRTCCalling.EVENT.LINE_BUSY, this.handleInviteeLineBusy)
// 作为被邀请方会收到,收到该回调说明本次通话被取消了
this.trtcCalling.on(this.TRTCCalling.EVENT.CALLING_CANCEL, this.handleInviterCancel)
// 重复登陆,收到该回调说明被踢出房间
this.trtcCalling.on(this.TRTCCalling.EVENT.KICKED_OUT, this.handleKickedOut)
// 作为邀请方会收到,收到该回调说明本次通话超时未应答
this.trtcCalling.on(this.TRTCCalling.EVENT.CALLING_TIMEOUT, this.handleCallTimeout)
// 邀请用户无应答
this.trtcCalling.on(this.TRTCCalling.EVENT.NO_RESP, this.handleNoResponse)
// 收到该回调说明本次通话结束了
this.trtcCalling.on(this.TRTCCalling.EVENT.CALLING_END, this.handleCallEnd)
// 远端用户开启/关闭了摄像头, 会收到该回调
this.trtcCalling.on(this.TRTCCalling.EVENT.USER_VIDEO_AVAILABLE, this.handleUserVideoChange)
// 远端用户开启/关闭了麦克风, 会收到该回调
this.trtcCalling.on(this.TRTCCalling.EVENT.USER_AUDIO_AVAILABLE, this.handleUserAudioChange)
},
removeListener() {
this.trtcCalling.off(this.TRTCCalling.EVENT.ERROR, this.handleError)
this.trtcCalling.off(this.TRTCCalling.EVENT.INVITED, this.handleNewInvitationReceived)
this.trtcCalling.off(this.TRTCCalling.EVENT.USER_ENTER, this.handleUserEnter)
this.trtcCalling.off(this.TRTCCalling.EVENT.USER_LEAVE, this.handleUserLeave)
this.trtcCalling.off(this.TRTCCalling.EVENT.REJECT, this.handleInviteeReject)
this.trtcCalling.off(this.TRTCCalling.EVENT.LINE_BUSY, this.handleInviteeLineBusy)
this.trtcCalling.off(this.TRTCCalling.EVENT.CALLING_CANCEL, this.handleInviterCancel)
this.trtcCalling.off(this.TRTCCalling.EVENT.KICKED_OUT, this.handleKickedOut)
this.trtcCalling.off(this.TRTCCalling.EVENT.CALLING_TIMEOUT, this.handleCallTimeout)
this.trtcCalling.off(this.TRTCCalling.EVENT.NO_RESP, this.handleNoResponse)
this.trtcCalling.off(this.TRTCCalling.EVENT.CALLING_END, this.handleCallEnd)
this.trtcCalling.off(this.TRTCCalling.EVENT.USER_VIDEO_AVAILABLE, this.handleUserVideoChange)
this.trtcCalling.off(this.TRTCCalling.EVENT.USER_AUDIO_AVAILABLE, this.handleUserAudioChange)
},
handleError() {},
// 被呼叫 接听方
async handleNewInvitationReceived (payload) {
const { inviteID, sponsor, inviteData, userIDList, isGroupCall } = payload
this.inviteID = inviteID
this.inviteData = inviteData
this.callType = inviteData.callType
this.sponsor = sponsor
this.invitedUserID = JSON.parse(JSON.stringify(userIDList))//被邀请者
this.callingInfo.type = isGroupCall ? this.TIM.TYPES.CONV_GROUP : this.TIM.TYPES.CONV_C2C
this.changeState('isDialled', true)
},
accept() {
this.trtcCalling.accept({
inviteID: this.inviteID,
roomID: this.inviteData.roomID,
callType: this.inviteData.callType
}).then((res) => {
// this.callType = this.inviteData.callType
this.changeState('calling', true)
res.data.message.nick = this.currentUserProfile.nick
this.$store.commit('pushCurrentMessageList', res.data.message)
})
},
reject() {
const { callType } = this.inviteData
this.trtcCalling.reject({
inviteID: this.inviteID,
isBusy: false,
callType
}).then((res) =>{
res.data.message.nick = this.currentUserProfile.nick
this.$store.commit('pushCurrentMessageList', res.data.message)
})
},
handleDebounce (func, wait) {
let context = this
let args = arguments
if (this.timeout) clearTimeout(this.timeout)
this.timeout = setTimeout(() => {
func.apply(context, args)
}, wait)
},
// 双方建立连接
handleUserEnter({ userID }) {
this.changeState('dialling', true)
this.isAccept()
// 判断是否为多人通话
if (this.callingUserList.length >= 2) {
this.callingType = this.TIM.TYPES.CONV_GROUP
}
if (this.callingUserList.indexOf(userID) === -1) {
if (this.callType === this.TRTCCalling.CALL_TYPE.AUDIO_CALL ) {
this.getUserAvatar(userID)
} else {
this.callingUserList.push(userID)
}
}
if (this.callType === this.TRTCCalling.CALL_TYPE.VIDEO_CALL ) {
this.$nextTick(() => {
if (!this.isStartLocalView) {
this.startLocalView() //本地只开启一次
}
this.startRemoteView(userID) //远端多次拉流
})
}
},
// 通话已建立
handleUserLeave({ userID }) {
if( this.callType === this.TRTCCalling.CALL_TYPE.AUDIO_CALL ) {
// 语音通话
const _index = this.invitedUserInfo.findIndex(item => item.userID === userID)
if (_index >= 0) {
this.invitedUserInfo.splice(_index, 1)
}
return
}
const index = this.callingUserList.findIndex(item => item === userID)
if (index >= 0) {
this.callingUserList.splice(index, 1)
}
},
// 通知呼叫方,未接通
//userID:invitee(被邀请者)
handleInviteeReject({ userID }) {
if (this.userID === this.sponsor) {
// 发起者
this.setCallingstatus(userID)
this.$store.commit('showMessage', {
message: `${userID}拒绝通话`
})
}
},
setCallingstatus(userID) {
const _index = this.invitedUserID.indexOf(userID)
if (_index >= 0) {
this.invitedUserID.splice(_index, 1)
}
if ( this.invitedUserID.length ===0 ) {
this.changeState('isDialled', false)
this.changeState('dialling', false)
}
},
// 通知呼叫方,对方在忙碌,未接通
handleInviteeLineBusy({ sponsor, userID }) {
// A call B,C call A, A在忙线, 拒绝通话,对于呼叫者C收到通知,XXX在忙线
if( sponsor === this.userID ) {
this.setCallingstatus(userID)
this.$store.commit('showMessage', {
message: `${userID}忙线`
})
}
},
// 通知被呼叫方,邀请被取消,未接通
handleInviterCancel() {
// 邀请被取消
this.changeState('isDialled', false)
this.$store.commit('showMessage', {
message: '通话已取消'
})
},
handleKickedOut() {
// //重复登陆,被踢出房间
// this.trtcCalling.logout();
// this.$store.commit("userLogoutSuccess");
},
// 当自己收到对端超时的信令时,或者当我是被邀请者但自己超时了,通知上层通话超时
// case: A呼叫B,B在线,B超时未响应,B会触发该事件,A也会触发该事件
handleCallTimeout({ userIDList }) {
if(this.calling) {
return
}
if (this.userID === this.sponsor) { // 该用户是邀请者
userIDList.forEach((userID) =>{
this.setCallingstatus(userID) //超时未接听
})
return
}
//用户是被邀请者
if(userIDList.indexOf(this.userID) > -1) { //当超时者是自己时,添加消息
//会话列表切换后发消息
this.toAccount && this.sendMessage(this.userID,'',this.callingTips.callTimeout)
}
this.changeState('isDialled', false)
},
// 双方,通话已建立, 通话结束
handleCallEnd({userID, callEnd}) {
// 自己挂断的要补充消息 被邀请者都无应答时结束
// 历史消息中没有通话结束
if(userID === this.userID && this.invitedUserID.length === 0 || this.callingUserList === 0) {
this.sendMessage(userID,callEnd,this.callingTips.callEnd)
}
// this.changeState('isDialled', false)
// this.changeState('calling', false)
this.changeState('dialling', false)
this.isMicOn = true
this.isCamOn = true
this.maskShow = false
this.isStartLocalView = false
// this.$store.commit('showMessage', {
// message: '通话已结束'
// })
},
// 自己超时且是邀请发起者,需主动挂断,并通知上层对端无应答
handleNoResponse({ sponsor, userIDList }) { //邀请者
if(sponsor === this.userID) {
userIDList.forEach((userID) =>{
this.setCallingstatus(userID)
})
if(userIDList.indexOf(this.userID) === -1) { //当超时者是自己时,添加消息
this.sendMessage(userIDList,'',this.callingTips.callTimeout)
}
}
},
handleUserVideoChange() {
},
handleUserAudioChange(payload) {
const _index = this.invitedUserInfo.findIndex(item => item.userID === payload.userID)
if (_index >= 0) {
this.invitedUserInfo[_index].isInvitedMicOn = payload.isAudioAvailable
}
// this.isInvitedMicOn = payload.isAudioAvailable
},
// 播放本地流
startLocalView() {
this.trtcCalling.startLocalView({
userID: this.userID,
videoViewDomID: 'local'
}).then(()=>{
this.isStartLocalView = true
})
},
// 没有用到
stopLocalView() {
this.trtcCalling.stopLocalView({
userID: this.userID,
videoViewDomID: this.viewLocalDomID
})
},
// 播放远端流
startRemoteView(userID) {
this.trtcCalling.startRemoteView({
userID: userID,
videoViewDomID: `video-${userID}`
}).then(()=>{
})
},
//没有用到
stopRemoteView(userID) {
this.trtcCalling.stopRemoteView({
userID: this.userID,
videoViewDomID: `video-${userID}`
})
},
//获取被呼叫者信息
getUserAvatar(userID) {
const _index = this.invitedUserInfo.findIndex(item => item.userID === userID)
if (_index >= 0) {
return
}
let _userIDList = [userID]
let promise = this.tim.getUserProfile({
userIDList:_userIDList // 请注意:即使只拉取一个用户的资料,也需要用数组类型,例如:userIDList: ['user1']
})
promise.then((imResponse)=> {
if (imResponse.data[0]) {
this.invitedUserInfo.push(imResponse.data[0])
}
}).catch(()=> {
})
},
changeState(state, boolean) {
let stateList = ['dialling', 'isDialled', 'calling']
stateList.forEach(item => {
this[item] = item === state ? boolean : false
})
this.$store.commit('UPDATE_ISBUSY', stateList.some(item => this[item])) // 若stateList 中存在 true , isBusy 为 true
},
videoCalling() { // 发起通话
// 初始化被邀请者
this.invitedUserID =JSON.parse(JSON.stringify(this.callingInfo.memberList))
this.sponsor = this.userID
if (this.calling) { // 避免通话按钮多次快速的点击
return
}
this.callType = this.TRTCCalling.CALL_TYPE.VIDEO_CALL
this.isLocalMain = true
// 可设置超时
if(this.callingInfo.type === this.TIM.TYPES.CONV_C2C) {
this.trtcCalling.call({
userID: this.callingInfo.memberList[0],
type: this.callType,
timeout: 30
}).then((res)=>{
res.data.message.nick = this.currentUserProfile.nick
this.$store.commit('pushCurrentMessageList', res.data.message)
this.changeState('dialling', true)
})
} else {
this.trtcCalling.groupCall({
userIDList: this.callingInfo.memberList,
type: this.callType,
groupID: this.currentConversation.groupProfile.groupID,
timeout: 30
}).then((res)=>{
res.data.message.nick = this.currentUserProfile.nick
this.$store.commit('pushCurrentMessageList', res.data.message)
this.changeState('dialling', true)
})
}
},
audioCalling() { // 发起通话
// 初始化被邀请者
this.invitedUserID = this.callingInfo.memberList
this.sponsor = this.userID
if (this.calling) { // 避免通话按钮多次快速的点击
return
}
// // 发起者获取被邀约人信息
// this.getUserAvatar()
// 可设置超时
this.callType = this.TRTCCalling.CALL_TYPE.AUDIO_CALL
if(this.callingInfo.type === 'C2C') {
this.trtcCalling.call({
userID: this.callingInfo.memberList[0],
type: this.callType,
timeout: 30
}).then((res)=>{
this.changeState('dialling', true)
res.data.message.nick = this.currentUserProfile.nick
this.$store.commit('pushCurrentMessageList', res.data.message)
})
} else {
this.trtcCalling.groupCall({
userIDList: this.callingInfo.memberList,
type: this.callType,
groupID: this.currentConversation.groupProfile.groupID,
timeout: 30
}).then((res)=>{
this.changeState('dialling', true)
res.data.message.nick = this.currentUserProfile.nick
this.$store.commit('pushCurrentMessageList', res.data.message)
})
}
},
leave() { // 离开房间,发起方挂断
this.isMicOn = true
this.isCamOn = true
this.maskShow = false
this.isStartLocalView = false
if (!this.calling) { // 还没有通话,单方面挂断
this.trtcCalling.hangup().then((res) => {
res.data.message.nick = this.currentUserProfile.nick
this.$store.commit('pushCurrentMessageList', res.data.message)
this.changeState('dialling', false)
clearTimeout(this.timer)
})
return
}
this.hangUp() // 通话一段时间之后,某一方面结束通话
},
refuse() { // 拒绝电话
this.changeState('isDialled', false)
this.reject()
},
resetDuration(duration) {
this.duration = duration
this.hangUpTimer = setTimeout(() => {
let now = new Date()
this.resetDuration(parseInt((now - this.start) / 1000))
}, 1000)
},
isAccept() { // 对方接听自己发起的电话
clearTimeout(this.timer)
this.changeState('calling', true)
clearTimeout(this.hangUpTimer)
this.resetDuration(0)
this.start = new Date()
},
hangUp() { // 通话一段时间之后,某一方挂断电话
this.changeState('calling', false)
this.trtcCalling.hangup()
this.$store.commit('showMessage', {
message: '已挂断'
})
},
videoHandler() { // 是否打开摄像头
if (this.isCamOn) {
this.isCamOn = false
this.maskShow = true
this.trtcCalling.closeCamera()
} else {
this.isCamOn = true
this.maskShow = false
this.trtcCalling.openCamera()
}
},
micHandler() { // 是否打开麦克风
if (this.isMicOn) {
this.trtcCalling.setMicMute(true)
this.isMicOn = false
} else {
this.trtcCalling.setMicMute(false)
this.isMicOn = true
}
},
changeMainVideo() {
if (!this.calling) {
return
}
this.isLocalMain = !this.isLocalMain
},
async sendMessage(userId,callEnd,callText) {
let call_text= ''
userId = Array.isArray(userId) ? userId.join(',') : userId
let messageData = {
to: this.toAccount,
from:userId,
conversationType: this.currentConversationType,
payload: {
data: '',
description: '',
extension: ''
}
}
const message = await this.tim.createCustomMessage(messageData)
switch (callText) {
case this.callingTips.callEnd:
if (this.currentConversationType === this.TIM.TYPES.CONV_GROUP) {
call_text = '结束群聊'
break
} else {
call_text = callEnd === 0 ?'取消通话' : `结束通话,通话时长:${formatDuration(callEnd || this.duration)}`
break
}
case this.callingTips.callTimeout:
call_text = '无应答'
break
default:
call_text = ''
break
}
if (this.currentConversationType === this.TIM.TYPES.CONV_GROUP) {
message.groupID = this.toAccount
let customData = {
operationType:256,
text:call_text,
userIDList:[]
}
message.payload = customData
}
if (this.currentConversationType === this.TIM.TYPES.CONV_C2C) {
let customData = {
text:call_text
}
message.payload = customData
}
if (this.currentConversationType === this.TIM.TYPES.CONV_GROUP) {
message.type = this.TIM.TYPES.MSG_GRP_TIP
}
message.callType = 'callingTips'
this.$store.commit('pushCurrentMessageList', message)
},
}
}
</script>
<style lang="stylus" scoped>
.call-container
background center url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEEAAABACAYAAAEyrCp2AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAkqSURBVGhD7Zp7cFxVHcedwTTNPrK77RQUplKQPqAdcAZ1mMGOMtOKDAoK8hABUR5FsSiPWvpEW0atY6XwB8gI7VgoraQC6oC0SSi2naalrRSqttkkTSL0IZKGbV7No3z9fu+5t7m7uXd3sxsTB+9nZufunnvub7/3e8895/zuuR9BHuRf6RO19daPyQ9bG8R/bLYOVqWJGZUSPzFbhwGRRt8KlC4EYndbRRYDKkVnmUoT51pFFlalaXUN1o9zV1gblC0y2/LLzdaqlIuclfKrcEFVIyLXWL9R+mWzdbAqfKbaVBi92FRILLD2WaRFCNNZVTh7qbXPYsBfRK4029iNZmtVmL6pGbFrrd+IftVsp37fbK0K2chZIR+GNsjnDjTh8q1vW9914k6zEpaFbF5L/mwXZHAyiFqSnBNOEFksFCTM65Fg67ruMVPmJmuQp3fR/jvNpVDzFGrHF95rvjtkDSKe3ZweROi6nm5fQjG0xhZD0UE+LAFWtR3FqdvrrIJHfsse8QfWV4umd3gJvwc8XmMXZGAFWN+ewqf3NFkFfgESD9kFGVgBVlPB+B3ZFSjA7LV2oYuspxC+rz/A5OUMMseUu8kaIMGu+tBhE8D6zQAzXP2ZyBogzgCR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uQy4i/lGLkbUBNHBfZfwREu1IlWgCWLhs/z/b6aboFglTM3vWAr09tgVPfA1YSVNOIsmnEETTt1Tj7E1dYhWJTGt0tuEFTRhFP8wzCta/h2K0dDF8XwSZ3vZTBAptQgOex/9Am8PNuMoT6Rc9zk7z1EcSfIxQSxeQ9NoQJgjTZj9gmLp3VTFvYqzS3gkfsLXhHf7erG7qwt/7ezE7vZO7DrWhV3vd+Gt1uPo+2BgtOaDQOUujvecvVXtBar3ccsprV4Z6O1/sccX5mnYwpOt3M3jOEOs/gc/PF5J16Es7z5nspP1KxnH0qFY+lDXhu1AMuMlHgdfE/6fCEwggQkkMIEEJpDABBKYAOA/AsZRNa1jRE0AAAAASUVORK5CYII=")
background-size cover
position absolute
z-index 999
.accept, .refuse, .videoOn, .videoOff, .micOn, .micOff
height 50px
width 50px
box-sizing border-box
border-radius 50%
cursor: pointer
.accept
background center no-repeat url("../../../assets/image/call.png")
background-size 60%
background-color $success
.refuse
background center no-repeat url("../../../assets/image/close.png")
background-size 70%
background-color $danger
.videoOn
background center no-repeat url("../../../assets/image/big-camera-on.png")
.videoOff
background center no-repeat url("../../../assets/image/big-camera-off.png")
.micOn
background center no-repeat url("../../../assets/image/big-mic-on.png")
.micOff
background center no-repeat url("../../../assets/image/big-mic-off.png")
.buttons
position absolute
z-index 20
width 70%
top 75%
display flex
justify-content space-around
margin 0 15% 0 15%
.audio-box
position absolute
z-index 20
width 70%
top 200px
display flex
justify-content center
margin 0 15% 0 15%
.aduio-call
box-sizing border-box
width 140px
height 100px
.audio-img
display block
width 60px
height 60px
border-radius 50%
margin 0 auto 13px
.micr-icon
cursor pointer
font-size 28px
/*display block*/
/*text-align center*/
.nick-text
color #dddddd
font-size 12px
margin-right 5px
vertical-align super
.duration
color #fff
position absolute
z-index 20
width 100%
top 70%
display flex
justify-content center
.mask
position absolute
z-index 10
background #D8D8D8
height 100%
width 100%
display flex
align-items center
justify-content center
space
.image
margin-left 15%
.notice
color #888888
.choose, .call
color #fff
background-color rgba(0, 0, 0, 0.8)
height 100%
width 100%
.title
margin 25% 0 0 0
text-align center
width 100%
position absolute
z-index 10
color #fff
font-size 40px
font-weight 700
.big
position absolute
height 100%
width 100%
.small
position absolute
margin-left 74.8%
z-index 999
border-style solid
border-width 1px
border-color #808080
height 44.8%
width 25.2%
.big-group
height 60vh
width 100%
.small-group
display flex
flex-wrap wrap
position absolute
/*z-index 999*/
/*border-style solid*/
/*border-width 1px*/
/*border-color #808080*/
/*height 30%*/
width 100%
/*height 100%*/
.small-group_box {
height 100%
}
.video-box
width 33.3%
height 25vh
</style>