智慧保安互联网APP
zengh
2022-06-21 4efeb31d5b4921d7e851c256009486ad86bc70e2
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
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
<template>
    <view class="content">
        <!-- 加入频道 -->
        <view class="index" v-if="!videoShow">
            <view class="Mains" v-if="isMain">
                <view class="Mains-t">
                    <text class="activetext">正在呼叫{{callname}}</text>
                    <u-loading size="36" mode="flower"></u-loading>
                </view>
                <!-- 挂断 -->
                <view class="i-open" @click="phoneFnMain">
                    <image class="i-video_bg_img" src="../../static/over.png" mode=""></image>
                    <text class="open_text">取消呼叫</text>
                </view>
            </view>
            <view class="Receiver" v-if="!isMain">
                <view class="Mains-t">
                    <text class="activetext">是否接收来自{{callname}}的{{Otype == 'video'? '视频': '音频'}}邀请</text>
                    <!-- <text class="activetext">接受进入{{channel}}</text> -->
                    <u-loading size="36" mode="flower"></u-loading>
                </view>
                <view class="i-control">
                    <view class="i-c-open" @click="joinit">
                        <image class="i-video_bg_img" src="../../static/phone.png" mode=""></image>
                        <text class="open_text">接受</text>
 
                    </view>
                    <view class="i-c-open" @click="comeBack">
                        <image class="i-video_bg_img" src="../../static/over.png" mode=""></image>
                        <text class="open_text">挂断</text>
 
                    </view>
                </view>
            </view>
        </view>
 
        <!-- 视频 -->
        <view class="vedioWatch" v-if="videoShow && Otype == 'video'">
 
            <view class="video_bg">
                <image class="video_bg_img" src="../../static/BG.png" mode=""></image>
                <!-- <text class="activetext" v-if="videoShowBg"></text> -->
                <!--     <view class="video_bg video_bg_text">
            
                    <text class="activetext">{{promptText}}</text>
                </view> -->
            </view>
 
            <view class="video_region">
                <!-- 渲染视频 -->
                <view v-for="(peervideo,index) in PeerVideoUser" :key="peervideo">
                    <view :class="PeerVideoUserStyle[index]" v-if="peervideo == uid && role == 2 ? false : true">
                        <AR-CanvasView :ref="`popup${peervideo}`" style="flex: 1;"></AR-CanvasView>
                    </view>
 
                </view>
 
                <!-- {{PeerVideoUser}} -->
            </view>
 
            <!-- 转换摄像头 -->
            <view class="camera position" @click="cameraSwitchFn" v-if="role == 1">
                <image class="video_bg_img" src="../../static/camera.png" mode=""></image>
 
            </view>
            <!-- 音视频基本开关 -->
            <view class="videoshow_control position">
                <!-- 音频开关 -->
                <view class="open" @click="audioSwitchFn" v-if="role == 1">
                    <image class="video_bg_img" src="../../static/au_in.png" mode="" v-if="audioSwitch == 'open'">
                    </image>
                    <image class="video_bg_img" src="../../static/au_on.png" mode="" v-else></image>
                    <text class="open_text">音频</text>
                </view>
 
                <!-- 挂断 -->
                <view class="open" @click="phoneFn">
                    <image class="video_bg_img" src="../../static/over.png" mode=""></image>
                    <text class="open_text">挂断</text>
 
                </view>
 
                <!-- 视频开关 -->
                <view class="open" @click="vedioSwitchFn" v-if="role == 1">
                    <image class="video_bg_img" src="../../static/vi_on.png" mode="" v-if="vedioSwitch == 'open'">
                    </image>
                    <image class="video_bg_img" src="../../static/vi_in.png" mode="" v-else></image>
                    <text class="open_text">视频</text>
                </view>
 
                <!--     <scroll-view scroll-y="true" style="height: 500px;padding: 20px;">
                    <view v-for="(item,value) in closeArray" :key='item+value'>{{item}}</view>
                </scroll-view> -->
            </view>
            <!-- 提示文字 -->
            <view class="video_bg video_bg_text" v-if="promptText">
                <!-- <view class="video_bg video_bg_text"> -->
                <text class="activetext">{{promptText}}</text>
                <!-- </view> -->
            </view>
        </view>
 
        <!-- 音频 -->
        <view class="vedioWatch" v-if="videoShow && Otype == 'audio'">
            <view class="video_bg">
                <image class="video_bg_img" src="../../static/BG.png" mode=""></image>
                <!-- <text class="activetext" v-if="videoShowBg"></text> -->
                <!--     <view class="video_bg video_bg_text">
            
                    <text class="activetext">{{promptText}}</text>
                </view> -->
            </view>
            <!-- 文字提示 -->
            <view class="Mains-t">
                <text class="activetext">语音通话中</text>
                <u-loading size="36" mode="flower"></u-loading>
            </view>
 
 
            <!-- 音视频基本开关 -->
            <view class="videoshow_control position">
                <!-- 音频开关 -->
                <view class="open" @click="audioSwitchFn" v-if="role == 1">
                    <image class="video_bg_img" src="../../static/au_in.png" mode="" v-if="audioSwitch == 'open'">
                    </image>
                    <image class="video_bg_img" src="../../static/au_on.png" mode="" v-else></image>
                    <text class="open_text">音频</text>
                </view>
 
                <!-- 挂断 -->
                <view class="open" @click="phoneFn">
                    <image class="video_bg_img" src="../../static/over.png" mode=""></image>
                    <text class="open_text">挂断</text>
 
                </view>
 
                <!-- 视频开关 -->
                <!-- <view class="open" @click="vedioSwitchFn" v-if="role == 1">
                    <image class="video_bg_img" src="../../static/vi_on.png" mode="" v-if="vedioSwitch == 'open'">
                    </image>
                    <image class="video_bg_img" src="../../static/vi_in.png" mode="" v-else></image>
                    <text class="open_text">视频</text>
                </view> -->
 
                <!--     <scroll-view scroll-y="true" style="height: 500px;padding: 20px;">
                    <view v-for="(item,value) in closeArray" :key='item+value'>{{item}}</view>
                </scroll-view> -->
            </view>
            <!-- 提示文字 -->
            <view class="video_bg video_bg_text" v-if="promptText">
                <!-- <view class="video_bg video_bg_text"> -->
                <text class="activetext">{{promptText}}</text>
                <!-- </view> -->
            </view>
 
        </view>
        <uni-popup ref="popup" type="center">
            <uni-popup-message :type="popupType" :message="popupMessage" :duration="2000"></uni-popup-message>
        </uni-popup>
    </view>
 
 
</template>
 
<script>
    const RtcModule = uni.requireNativePlugin('AR-RtcModule');
    import uniPopup from '@/components/uni-popup/uni-popup.vue'
    import uniPopupMessage from '@/components/uni-popup-message/uni-popup-message.vue'
    import uniPopupDialog from '@/components/uni-popup-dialog/uni-popup-dialog.vue'
    import permision from "@/js_sdk/wa-permission/permission.js"
    export default {
        components: {
            uniPopup,
            uniPopupMessage,
            uniPopupDialog
        },
        data() {
            return {
                appid: "d5a164cd8e0a8352ee108c561ba2e44e",
                channel: "",
                uid: "",
                role: 1, //角色 主播-游客
 
 
                videoShow: false, //视频展示
                // videoShowBg: true, //背景展示
                promptText: "loading...",
 
                PeerVideoUser: [], //用户视频加入存储
                PeerVideoUserStyle: [
                    'video_local_call', "video_local"
                ], //用户视频加入样式
 
                // 本地
                audioSwitch: "open", //音频开关 
                vedioSwitch: "open", //视频开关
 
                videoWidth: 0,
                videoHeight: 0,
                //提示
                popupType: "",
                popupMessage: "",
 
 
                isMain: true,
                userName: '111',
                toName: '',
                Otype: '',
 
                formName: '',
 
                callname: '',
 
 
 
                faqiid: '',
                jieshouid: ''
 
            }
        },
        // 页面初始加载(仅执行一次)
        onReady() {
            // 初始化
            // this.channel = 2554;
            // this.init();
        },
        onLoad(option) {
 
            var that = this;
            that.toName = option.toname;
            that.callname = option.callname;
            console.log(option)
            if (option.type) {
                that.Otype = option.type;
            } else {
                return
            }
            console.log(option.state);
            
        
 
            if (option.state == "Mains") {
 
                that.jieshouid = option.toname;
                that.faqiid = that.$store.state.puserID;
 
                that.isMain = true;
                var call = false;
                this.userName = 'faqiren';
                this.init();
                // setTimeout(res => {
                //发起请求  给后端双方姓名
 
                //得到返回值   开始视频  或者拒绝视频
                // console.log(that.$store.state);
                uni.request({
                    url: that.$store.state.api + '/pushMsg/inviteVideoCall',
                    data: {
                        userId: option.toname,
                        faqiid: that.$store.state.puserID,
                        name: that.$store.state.puserName,
                        type: 'video'
                    },
                    success(res) {
                        // if(res.data.res == 0){
 
                        // }
                        var d = res.data.data;
                        if (d.res == 0) {
                            console.log('对方不在线--退出');
                            uni.showToast({
                                title: '对方不在线',
                                duration: 2000,
                                icon: 'none'
                            });
                            setTimeout(res => {
                                
                                let routes = getCurrentPages();
                                
                                let curRoute = routes[routes.length - 1].route;
                                
                                if(curRoute.indexOf('/videoCall/videoCall') != -1) {
                                    
                                    uni.navigateBack();
                                    
                                }
                                
                            }, 2000)
 
                        } else if (d.res == 1) {
                            that.channel = d.roomId;
                            console.log('对方在线-- 等待对方接受', d);
                            // call = true;
                            setTimeout(res => {
                                // console.log(111)
                                that.join();
                                console.log('成功进入')
                            }, 2000)
                        }
                    }
                })
 
 
 
                // }, 5000)
            } else if (option.state == "Receiver") {
                that.userName = 'jieshouren';
                // that.formName = 'wo';
                that.callname = option.name;
                that.channel = option.room;
                that.faqiid = option.faqiid;
                that.jieshouid = that.$store.state.puserID;
                that.init();
                that.isMain = false;
 
 
 
 
            }
 
 
 
            uni.onSocketMessage(function(res) {
                console.log(res.data);
                var data = JSON.parse(res.data)
                // if (call && ) {
 
                // }
                // console.log(that,1111111111111)
 
 
                if (data.type == 'close') {
 
                    // await RtcModule.destroyRtc((res) => {});
                    that.videoShow = false; //视频展示
                    // this.videoShowBg = true; //背景展示
                    that.promptText = "loading...";
 
                    that.PeerVideoUser = []; //远端用户加入存储
                    // 本地
                    that.audioSwitch = "open"; //音频开关 
                    that.vedioSwitch = "open"; //视频开关
 
                    RtcModule.leaveChannel((res) => {
                    })
 
                    RtcModule.destroyRtc((res) => {
                    });
                    
                    let routes = getCurrentPages();
                    
                    let curRoute = routes[routes.length - 1].route;
                    
                    if(curRoute.indexOf('/videoCall/videoCall') != -1) {
                        
                        uni.navigateBack();
                        
                    }
 
                }
 
            });
 
 
 
        },
 
        watch: {
            PeerVideoUser: function(newName) {
                if (this.role == 2) {
                    newName = newName.filter((x) => x !== this.uid);
                }
 
                if (newName.length == 1) {
                    // this.PeerVideoUserStyle = [
                    //     'video_local', "video_local_call"
                    // ]
                    this.PeerVideoUserStyle = [
                        'video_local_call', "video_local"
                    ]
                } else if (newName.length == 2) {
                    this.PeerVideoUserStyle = [
                        'video_local_call', "video_local"
                    ]
                }
 
                //     // video_local
                //     if (newName.length == 1) {
                //         this.PeerVideoUserStyle = "video_local"
                //     } else if (newName.length > 1 && newName.length < 5) {
                //         this.PeerVideoUserStyle = "video_local_1"
                //     } else if (newName.length > 4 && newName.length < 10) {
                //         this.PeerVideoUserStyle = "video_local_2"
                //     } else if (newName.length > 9 && newName.length < 17) {
                //         this.PeerVideoUserStyle = "video_local_3"
                //     } else if (newName.length == 0) {
                //         this.role == 2 ? this.promptText = "暂无主播播放视频" : this.promptText = "loading..."
                //     }
            }
        },
        methods: {
            // 初始化
            async init() {
                // 查看权限
                console.log('开始初始化')
                this.uid = this.userName;
                console.log('初始化完成’', this.uid, '当前id码');
                // uni.showToast({
                //     title: this.uid,
                //     duration: 2000,
                //     // icon: 'none'
                // });
                if (uni.getSystemInfoSync().platform == 'ios') {
                    //查看相机权限
                    await this.requestAndroidPermission("camera", 'ios');
                    //查看录音权限
                    await this.requestAndroidPermission("record", 'ios');
 
                } else if (uni.getSystemInfoSync().platform === 'android') {
                    //查看相机权限
                    await this.requestAndroidPermission("android.permission.CAMERA", 'android');
                    //查看录音权限
                    await this.requestAndroidPermission("android.permission.RECORD_AUDIO", 'android');
                }
                // 初始化 setCallBack
                await this.callbackFn();
                // 初始化 create
 
                await RtcModule.create({
                    "appId": this.appid
                }, (res) => {
                    console.log(res, 11111111111111111111111111111111);
                });
                // this.uid = this.randomFn(6);
 
            },
            //设置角色
            setClientRole(num) {
                this.role = num;
                //设置直播场景下的用户角色
                RtcModule.setClientRole({
                    "role": num
                }, (ret) => {});
            },
 
 
            //加入频道 跳转到视频
            async join(val) {
                var that = this;
                // if (val == "Mains") { //视频发起人进入
                console.log('视频发起人进入');
                console.log(this.uid, '进入检测uid')
                // uni.showLoading({
                //     title: '加载中',
                //     mask: true
                // });
                //加入房间
                console.log('room', this.channel, 'useid', this.uid)
                await RtcModule.joinChannel({
                    "token": "",
                    "channelId": this.channel,
                    "uid": this.uid
                }, (res) => {
                    console.log(res, 'join break');
                    console.log('成功进入房间:' + that.channel);
                    that.videoShow = true;
                })
                // } else if (val == 'Receiver') { //视频接收人进入
                //     console.log('视频接收人进入');
                //     uni.showLoading({
                //         title: '加载中',
                //         mask: true
                //     });
                //     //加入房间
                //     await RtcModule.joinChannel({
                //         "token": "",
                //         "channelId": this.channel,
                //         "uid": this.uid
                //     }, (res) => {
                //         console.log(res, 'join break');
                //         console.log('成功进入房间:' + that.channel);
                //     })
                // }
 
            },
            // 等待时候挂断
            phoneFnMain() {
 
                var data = {
                    sentId: this.faqiid,
                    acceptId: this.jieshouid
                }
 
                uni.request({
                    url: this.$store.state.api + '/pushMsg/closeVideoCall',
                    data: data,
                    success: (res) => {
 
                        this.closeAll();
 
                    }
                })
 
            },
            joinit() { //接受进入视频
                // 传输接受的值
 
                // 开始进入视频通话
                this.join();
            },
            //拒绝进入视频
            comeBack() {
 
                var data = {
                    sentId: this.faqiid,
                    acceptId: this.jieshouid
                }
 
                uni.request({
                    url: this.$store.state.api + '/pushMsg/closeVideoCall',
                    data: data,
                    success: (res) => {
 
                        this.closeAll();
 
                    }
                })
 
            },
 
            // 挂断 离开
            phoneFn() {
 
                var data = {
                    sentId: this.faqiid,
                    acceptId: this.jieshouid
                }
 
                uni.request({
                    url: this.$store.state.api + '/pushMsg/closeVideoCall',
                    data: data,
                    success: (res) => {
 
                        this.closeAll();
 
                    }
                })
 
            },
 
            //添加本地视频到页面
            setupLocalVideoFn() {
                //视频 
                var that = this;
                RtcModule.enableVideo((res) => {});
                this.$refs[`popup${this.uid}`][0].setupLocalVideo({
                    "renderMode": 4,
                    "channelId": this.channel,
                    "uid": this.uid,
                    "mirrorMode": 0
                }, (res) => {});
                // 本地预览
                RtcModule.startPreview((res) => {});
            },
 
            // 视频
            vedioSwitchFn() {
                let open = true;
 
                if (this.vedioSwitch == "open") {
                    this.vedioSwitch = "colse";
                    open = false;
                } else {
                    this.vedioSwitch = "open";
                    open = true;
                }
                RtcModule.enableLocalVideo({
                    "enabled": open
                }, (res) => {
                    if (res.code == 0) {
                        open == false ? this.promptFn("warn", "关闭本地视频采集") : this.promptFn("info", "开启本地视频采集");
                    }
                });
            },
            // 音频
            audioSwitchFn() {
                let open = true;
                if (this.audioSwitch == "open") {
                    this.audioSwitch = "colse";
                    open = false;
                } else {
                    this.audioSwitch = "open";
                    open = true;
                }
 
                RtcModule.enableLocalAudio({
                    "enabled": open
                }, (res) => {
                    if (res.code == 0) {
                        open == false ? this.promptFn("warn", "关闭本地音频采集") : this.promptFn("info", "开启本地音频采集");
                    }
                });
            },
            //转化摄像头
            cameraSwitchFn() {
                RtcModule.switchCamera((res) => {
                    res.code == 0 ? this.promptFn("success", "切换摄像头成功") : this.promptFn("error", "切换摄像头失败");
                })
            },
 
            //callback 接收
            callbackFn() {
                RtcModule.setCallBack((res) => {
                    switch (res.engineEvent) {
                        case "onWarning":
                            this.promptFn("warn", res.warningCode);
                            break;
                        case "onError":
                            res.errorCode != 18 ? this.promptFn("error", res.errorCode) : '';
                            break;
                        case "onJoinChannelSuccess": //用户加入成功
                            uni.hideLoading();
                            this.role == 1 ? this.PeerVideoUser.push(res.uid) : "";
                            console.log(res.uid, 'uidsssss')
                            this.videoShow = true;
                            setTimeout(() => {
                                // this.videoShowBg = false;
                                this.promptText = ""
                                //扬声器
                                RtcModule.setEnableSpeakerphone({
                                    "enabled": true
                                }, (res) => {})
                                setTimeout(() => {
                                    console.log(this.PeerVideoUser, 'this.PeerVideoUser')
                                    // 启用视频模块。
                                    this.role == 1 ? this.setupLocalVideoFn() : RtcModule
                                        .enableVideo((res) => {});
                                }, 200)
                            }, 2000)
                            break;
                        case "onLeaveChannel": //离开频道回调
                            setTimeout(() => {
                                this.closeAll()
                            }, 500)
                            break;
                        case "onUserJoined": //远端用户加入当前频道回调。
                            // this.promptFn("info", "远端用户加入当前频道回调");
                            this.PeerVideoUser.push(res.uid);
                            break;
                        case "onUserOffline": //远端用户离开当前频道回调。
                            this.PeerVideoUser = this.PeerVideoUser.filter((x) => x !== res.uid);
                            break;
 
                        case "onFirstLocalAudioFrame": //已发送本地音频首帧的回调。(页面上添加音频)
                            break;
                        case "onFirstLocalVideoFrame": //已显示本地视频首帧的回调。(页面添加本地视频)
                            // this.promptFn("error", "已显示本地视频首帧的回调");
                            break;
                        case "onFirstRemoteVideoDecoded": //已完成远端视频首帧解码回调。(页面添加远端视频)
                            // this.promptFn("info", "已完成远端视频首帧解码回调");
                            this.promptText = "请稍等。。。"
                            let uid = []
                            uid.push(res.uid)
                            setTimeout(() => {
                                this.promptText = "";
                                // this.videoShowBg = false; //设置背景开关
                                setTimeout(() => {
                                    uid.map(item => {
                                        this.$refs[`popup${item}`][0].setupRemoteVideo({
                                            "renderMode": 1,
                                            "channelId": this.chanel,
                                            "uid": item,
                                            "mirrorMode": 0
                                        }, (res) => {})
                                        //预览
                                        RtcModule.startPreview((res) => {});
                                    })
                                }, 500)
 
                            }, 2000)
                            break;
                    }
 
                })
            },
            //提示
            promptFn(type, content) {
                this.popupType = type;
                this.popupMessage = content;
                this.$refs.popup.open()
            },
            //支持自定义字符长度和特征字符集合
            randomFn(len, charSet) {
                charSet = charSet || 'abcdefghijklmnopqrstuvwxyz0123456789';
                let randomString = '';
                for (let i = 0; i < len; i++) {
                    let randomPoz = Math.floor(Math.random() * charSet.length);
                    randomString += charSet.substring(randomPoz, randomPoz + 1);
                }
                // return randomString;
                return this.userName;
            },
            // 离开清空
            closeAll() {
                this.videoShow = false; //视频展示
                // this.videoShowBg = true; //背景展示
                this.promptText = "loading...";
 
                this.PeerVideoUser = []; //远端用户加入存储
                // 本地
                this.audioSwitch = "open"; //音频开关 
                this.vedioSwitch = "open"; //视频开关
                
 
                RtcModule.leaveChannel((res) => {
                })
 
                RtcModule.destroyRtc((res) => {
                    console.log("页面销毁", res.code);
                    console.log('成功关闭')
                });
                
                
                let routes = getCurrentPages();
                
                let curRoute = routes[routes.length - 1].route;
                
                if(curRoute.indexOf('/videoCall/videoCall') != -1) {
                    
                    uni.navigateBack();
                    
                }
 
            },
            //查看授权
            async requestAndroidPermission(permisionID, type) {
                let result = 0;
                let strStatus = "";
                type == 'ios' ? result = await permision.judgeIosPermission(permisionID) : result = await permision
                    .requestAndroidPermission(
                        permisionID);
                if (result == 1) {
                    strStatus = "已获得授权"
                } else if (result == 0) {
                    strStatus = "未获得授权"
                } else {
                    strStatus = "被永久拒绝权限"
                }
            },
 
        },
        destroyed() {
            // console.log('this.closeAll();');
            // this.closeAll();
            var that = this;
            uni.hideLoading();
            // uni.onSocketMessage(function(res) {
            //     console.log(res.data);
            //     var data = JSON.parse(res.data)
            //     // if (call && ) {
 
            //     // }
            //     if (data.type == 'close') {
 
            //         console.log('对方已挂断');
            //         // RtcModule.leaveChannel((res) => {});
            //         that.closeAll();
            //     }
            // });
            uni.onSocketMessage(function(res) {
                console.log(res.data);
                var data = JSON.parse(res.data)
                if (data.type == 'video') {
                    // this.receiveVideo('Receiver', );
                    console.log('进入接受 跳转', data.type)
                    uni.navigateTo({
                        url: '../videoCall/videoCall?state=Receiver&type=' + data.type + '&room=' + data
                            .roomId + '&name=' + data.name + '&faqiid=' + data.faqiid
                    });
                }
                // console.log('收到服务器内容:' + res.data);
            });
        }
 
    }
</script>
 
<style>
    .content {
        flex: 1;
        width: 750rpx;
 
    }
 
    /* 加入频道 */
    .index {
        flex: 1;
        background-color: #0A1621;
        width: 750rpx;
        height: 1080rpx;
 
    }
 
    .Mains {
        flex: 1;
        width: 750rpx;
    }
 
    .Mains-t {
        padding-top: 500rpx;
        flex-direction: row;
        justify-content: center;
    }
 
    .i-open {
        width: 750rpx;
        position: fixed;
        bottom: 20rpx;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        background-color: transparent;
    }
 
    .i-video_bg_img {
        width: 50rpx;
        height: 50rpx;
    }
 
    /* 是否接受 */
    .Receiver {
        flex: 1;
        width: 750rpx;
    }
 
    .i-control {
        width: 750rpx;
        bottom: 20rpx;
        position: fixed;
        /* bottom: 20px; */
        /* width: 600px; */
        flex-direction: row;
        justify-content: center;
    }
 
    .i-c-open {
        width: 325rpx;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        /* padding: 350px 150px 0 0; */
    }
 
 
    .chanel {
        padding: 120px 70px 40px;
    }
 
    .uni-input {
        height: 120rpx;
        padding: 0 20px;
        background-color: #2F3041;
        border-radius: 6px;
    }
 
    .setrole {
        padding: 60px 20px;
        flex-direction: row;
        justify-content: space-between;
    }
 
    .button {
        padding: 10px 70rpx;
        background-color: #2F3041;
        border-radius: 6px;
        border-width: 2px;
        border-color: #2f3041;
    }
 
    .text {
        color: #B4B5BE;
    }
 
 
 
    .activetext {
        color: #fff;
    }
 
    .active {
        padding: 10px 70rpx;
        border-radius: 6px;
        border-width: 2px;
        border-color: #40a3fb;
        background-color: #0A1621;
    }
 
    .join {
        padding: 20px;
    }
 
    .jion_bg {
        background-color: #40A3FB;
        border-width: 0;
    }
 
 
    /* 视频 */
    .vedioWatch {
        flex: 1;
        position: relative;
        width: 750rpx;
        height: 1080rpx;
    }
 
    /* 初始背景 */
    .video_bg {
        flex: 1;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: transparent;
    }
 
    .video_bg_img {
        flex: 1;
    }
 
    .video_bg_text {
        justify-content: center;
        align-items: center;
    }
 
    /* 转换摄像头 */
    .camera {
        width: 44px;
        height: 37px;
        /* position: absolute; */
        left: 20px;
        top: 40px;
        z-index: 10;
    }
 
    /* 视频区域 */
 
    .video_region {
        /* position: fixed;
        top: 0;
        left: 0; */
        flex: 1;
        /* position: absolute; */
        /* width: 750rpx;
        height: 1334rpx; */
        /* border: 1px solid red; */
        flex-wrap: wrap;
        flex-direction: row;
        background-color: transparent;
    }
 
    /* 1个视频 */
    .video_local {
        flex: 1;
        width: 750rpx;
        height: 1344rpx;
        /* border: 2px solid green; */
        background-color: transparent;
        z-index: 5;
    }
 
    .video_local_call {
        position: fixed;
        top: 60rpx;
        right: 30rpx;
        width: 300rpx;
        /* border: 2px solid yellow; */
        height: 400rpx;
        background-color: transparent;
        z-index: 6;
    }
 
    .video_none {
        width: 0;
        height: 0;
    }
 
    .video_region_padding {
        margin-top: 20px;
        padding: 200rpx 0 260rpx;
        width: 750rpx;
        height: 1080rpx;
    }
 
    /* 4个视频 */
    /* .video_local_1 {
        width: 375rpx;
        height: 420rpx;
    } */
 
    /* 9个视频 */
    /* .video_local_2 {
        width: 250rpx;
        height: 280rpx;
    } */
 
    /* 16个视频 */
    /* .video_local_3 {
        width: 187.5rpx;
        height: 210rpx;
    } */
 
    /* 音视频基本开关 */
    .videoshow_control {
        /* position: absolute; */
        bottom: 20rpx;
        left: 0;
        width: 750rpx;
        /* background-color: #007AFF; */
        /* height: 250rpx; */
        padding: 20px;
        background-color: transparent;
        color: #fff;
        flex-direction: row;
        justify-content: space-around;
        z-index: 10;
    }
 
    .open {
        height: 205rpx;
        width: 128rpx;
        justify-content: center;
    }
 
    .open_text {
        padding: 15px 0 0;
        text-align: center;
        color: #fff;
    }
 
    .position {
        position: absolute;
    }
</style>