吉安感知网项目-前端
shuishen
2026-02-03 89380e6260a75d1d3b94de687ebcc2f50d50659d
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
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { NAME } from './constants.js';
import { TRTCRoleType, TRTCAudioQuality, TRTCVideoRotation, TRTCVideoFillMode, TRTCVideoMirrorType, TRTCVideoStreamType, TRTCAppScene, TRTCAudioRoute, TRTCBeautyStyle, } from './TrtcDefines.js';
import TrtcError, { TXLiteJSError, generateError_ } from './TrtcCode.js';
const TrtcNativeTrtcCloudModule = uni.requireNativePlugin('TRTCCloudUniPlugin-TRTCCloudImpl');
const TXAudioEffectManagerModule = uni.requireNativePlugin('TRTCCloudUniPlugin-TRTCCloudImpl-TXAudioEffectManagerModule');
const TrtcEvent = uni.requireNativePlugin('globalEvent');
let trtcCloud = null; // trtcCloud 单例
export default class TrtcCloudImpl {
    constructor() {
        this.listenersMap_ = new Map();
    }
    static _createInstance() {
        try {
            if (trtcCloud) {
                return trtcCloud;
            }
            TrtcNativeTrtcCloudModule.sharedInstance();
            trtcCloud = new TrtcCloudImpl();
            return trtcCloud;
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    static _getInstance() {
        if (trtcCloud) {
            return trtcCloud;
        }
        throw new TrtcError({
            code: TXLiteJSError.INVALID_OPERATION,
            message: 'get trtcCloud failed, please create trtcCloud first',
        });
    }
    static _destroyInstance() {
        try {
            trtcCloud = null;
            TrtcNativeTrtcCloudModule.destroySharedInstance();
        }
        catch (error) {
            throw new TrtcError({
                code: error.code || TXLiteJSError.UNKNOWN,
                message: error.message,
                name: error.name,
            });
        }
    }
    // 截图保存
    // async saveImage_(base64Data) {
    //   return new Promise((resolve, reject) => {
    //     let bitmap = new plus.nativeObj.Bitmap();
    //     bitmap.loadBase64Data(base64Data, () => {
    //       const url = "_doc/" + new Date().getTime() + ".png";  // url为时间戳命名方式
    //       console.log('saveHeadImgFile', url);
    //       bitmap.save(url, { overwrite: true }, (i) => {
    //         uni.saveImageToPhotosAlbum({
    //           filePath: url,
    //           success: function() {
    //             uni.showToast({
    //               title: '图片保存成功',
    //               icon: 'none'
    //             })
    //             bitmap.clear();
    //             resolve({ code: 0, message: '图片保存成功' });
    //           }
    //         });
    //       }, (e) => {
    //         uni.showToast({
    //           title: '图片保存失败, 请重新截图',
    //           icon: 'none'
    //         })
    //         bitmap.clear();
    //         resolve({ code: -1, message: '图片保存失败, 请重新截图' });
    //       });
    //     });
    //   });
    // }
    on(event, callback) {
        if (typeof event !== NAME.STRING || typeof callback !== NAME.FUNCTION) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the on method parameter types. event type is a ${typeof event}; callback type is a ${typeof callback}`,
            });
        }
        const nativeListener = (res) => __awaiter(this, void 0, void 0, function* () {
            const { data = [] } = res;
            const code = data[0];
            const message = data[1];
            const extraInfo = data[2];
            switch (event) {
                case 'onEnterRoom': {
                    const result = code;
                    callback(result);
                    break;
                }
                case 'onExitRoom': {
                    const reason = code;
                    callback(reason);
                    break;
                }
                case 'onFirstVideoFrame': {
                    const userId = code;
                    const streamType = data[1];
                    const width = data[2];
                    const height = data[3];
                    callback({ userId, streamType, width, height });
                    break;
                }
                case 'onFirstAudioFrame': {
                    const userId = code;
                    callback(userId);
                    break;
                }
                case 'onMicDidReady': {
                    callback();
                    break;
                }
                case 'onCameraDidReady': {
                    callback();
                    break;
                }
                case 'onNetworkQuality': {
                    const localQuality = data[0];
                    const remoteQuality = data[1];
                    callback({ localQuality, remoteQuality });
                    break;
                }
                case 'onRemoteUserEnterRoom': {
                    const userId = code;
                    callback(userId);
                    break;
                }
                case 'onRemoteUserLeaveRoom': {
                    const userId = code;
                    const reason = message;
                    callback({ userId, reason });
                    break;
                }
                case 'onSendFirstLocalAudioFrame': {
                    callback();
                    break;
                }
                case 'onSendFirstLocalVideoFrame': {
                    const streamType = code;
                    callback(streamType);
                    break;
                }
                case 'onStatistics': {
                    const statics = data[0];
                    callback(statics);
                    break;
                }
                case 'onUserAudioAvailable': {
                    const userId = code;
                    const available = message;
                    callback({ userId, available });
                    break;
                }
                case 'onUserVideoAvailable': {
                    const userId = code;
                    const available = message;
                    callback({ userId, available });
                    break;
                }
                case 'onUserVoiceVolume': {
                    const userVolumes = data[0];
                    const totalVolume = data[1];
                    callback({ userVolumes, totalVolume });
                    break;
                }
                case 'onSwitchRole': {
                    callback({ code, message });
                    break;
                }
                case 'onScreenCaptureStarted': {
                    callback({ code, message });
                    break;
                }
                case 'onScreenCapturePaused': {
                    callback({ code, message });
                    break;
                }
                case 'onScreenCaptureResumed': {
                    callback({ code, message });
                    break;
                }
                case 'onScreenCaptureStopped': {
                    callback({ code, message });
                    break;
                }
                case 'onUserSubStreamAvailable': {
                    const userId = code;
                    const available = message;
                    callback({ userId, available });
                    break;
                }
                case 'onSnapshotComplete': {
                    // base64 直接保存到本地图库
                    // const { code: snapShotCode, message: msg } = await this.saveImage_(code);
                    // callback({ snapShotCode, message: msg });
                    callback({ base64Data: code, message });
                    break;
                }
                case 'onUserVideoSizeChanged': {
                    callback(data);
                    break;
                }
                case 'onStart': {
                    callback({ id: code, errCode: message });
                    break;
                }
                case 'onPlayProgress': {
                    callback({ id: code, curPtsMS: message, durationMS: extraInfo });
                    break;
                }
                case 'onComplete': {
                    callback({ id: code, errCode: message });
                    break;
                }
                case 'onConnectOtherRoom': {
                    // 拿不到 userid, 为了和 native 参数保持一致,所以空字符串代替
                    callback({ userId: '', errCode: code, errMsg: message });
                    break;
                }
                case 'onDisconnectOtherRoom': {
                    callback({ errCode: code, errMsg: message });
                    break;
                }
                case 'onError': {
                    console.error(`onError: ${code}, ${message}, ${extraInfo}`);
                    callback(generateError_({ message }, code, extraInfo));
                    break;
                }
                case 'onRecvCustomCmdMsg': {
                    const userId = code;
                    const cmdID = data[1] || 0;
                    const seq = data[2] || 0;
                    const message = data[3] || "";
                    console.error(`onRecvCustomCmdMsg: ${userId}, ${cmdID}, ${seq}, ${message}`);
                    callback({ userId, cmdID, seq, message });
                    break;
                }
                default: {
                    callback({ code, message, extraInfo });
                }
            }
        });
        this.listenersMap_.set(event, nativeListener); // 多次设置同一个事件时,后面的 callback 覆盖前面
        TrtcEvent.addEventListener(event, nativeListener);
    }
    off(event) {
        if (typeof event !== NAME.STRING) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the off method parameter types. event type is a ${typeof event} not a ${NAME.STRING}`,
            });
        }
        try {
            if (event === '*') {
                this.listenersMap_.forEach((value, key) => {
                    TrtcEvent.removeEventListener(key, value);
                });
                this.listenersMap_.clear();
            }
            else {
                TrtcEvent.removeEventListener(event, this.listenersMap_.get(event));
                this.listenersMap_.delete(event);
            }
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    enterRoom(params, scene) {
        if (scene !== TRTCAppScene.TRTCAppSceneVideoCall && scene !== TRTCAppScene.TRTCAppSceneLIVE && scene !== TRTCAppScene.TRTCAppSceneAudioCall && scene !== TRTCAppScene.TRTCAppSceneVoiceChatRoom) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the enterRoom method parameters. scene is not of TRTCAppScene`,
            });
        }
        try {
            const enterRoomParams = Object.assign(Object.assign({}, params), { role: params.role || TRTCRoleType.TRTCRoleAnchor, appScene: scene });
            TrtcNativeTrtcCloudModule.enterRoom(enterRoomParams);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    exitRoom() {
        try {
            TrtcNativeTrtcCloudModule.exitRoom();
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    connectOtherRoom(params) {
        try {
            TrtcNativeTrtcCloudModule.connectOtherRoom(params);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    disconnectOtherRoom() {
        try {
            TrtcNativeTrtcCloudModule.disconnectOtherRoom();
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    switchRole(role) {
        if (role !== TRTCRoleType.TRTCRoleAnchor && role !== TRTCRoleType.TRTCRoleAudience) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the switchRole method parameter. role is not of TRTCRoleType`,
            });
        }
        try {
            role && TrtcNativeTrtcCloudModule.switchRole(role);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    startLocalPreview(isFrontCamera = true, viewId) {
        if (typeof isFrontCamera !== NAME.BOOLEAN || !viewId || typeof viewId !== NAME.STRING) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the startLocalPreview method parameters`,
            });
        }
        try {
            let param = { isFrontCamera: !!isFrontCamera };
            param = viewId ? Object.assign(Object.assign({}, param), { userId: viewId }) : param;
            TrtcNativeTrtcCloudModule.startLocalPreview(param);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    setVideoEncoderParam(param) {
        try {
            TrtcNativeTrtcCloudModule.setVideoEncoderParam(param);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    stopLocalPreview() {
        try {
            TrtcNativeTrtcCloudModule.stopLocalPreview();
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    switchCamera(isFrontCamera) {
        if (typeof isFrontCamera !== NAME.BOOLEAN) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the switchCamera method parameter`,
            });
        }
        try {
            TrtcNativeTrtcCloudModule.switchCamera(isFrontCamera);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    setLocalRenderParams(params) {
        try {
            const { rotation = TRTCVideoRotation.TRTCVideoRotation_0, fillMode = TRTCVideoFillMode.TRTCVideoFillMode_Fill, mirrorType = TRTCVideoMirrorType.TRTCVideoMirrorType_Auto } = params;
            TrtcNativeTrtcCloudModule.setLocalRenderParams({
                rotation,
                fillMode,
                mirrorType,
            });
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    muteLocalVideo(streamType, mute) {
        if (streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeBig && streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeSub || typeof mute !== NAME.BOOLEAN) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the muteLocalVideo method parameters`,
            });
        }
        try {
            TrtcNativeTrtcCloudModule.muteLocalVideo({ streamType, mute: !!mute });
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    startRemoteView(userId, streamType, viewId) {
        if (!userId || streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeBig && streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeSmall && streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeSub || !viewId) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the startRemoteView method parameters`,
            });
        }
        try {
            TrtcNativeTrtcCloudModule.startRemoteView({ userId, streamType, viewId });
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    stopRemoteView(userId, streamType) {
        if (!userId || streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeBig && streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeSmall && streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeSub) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the stopRemoteView method parameters`,
            });
        }
        try {
            TrtcNativeTrtcCloudModule.stopRemoteView({ userId, streamType });
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    // 远端渲染设置
    setRemoteRenderParams(userId, streamType, params) {
        try {
            if (!userId || (streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeBig && streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeSub)) {
                throw new TrtcError({
                    code: TXLiteJSError.INVALID_PARAMETER,
                    message: `${NAME.LOG_PREFIX} please check the snapshotVideo method parameters`,
                });
            }
            const { rotation = TRTCVideoRotation.TRTCVideoRotation_0, fillMode = TRTCVideoFillMode.TRTCVideoFillMode_Fill, mirrorType = TRTCVideoMirrorType.TRTCVideoMirrorType_Auto } = params;
            TrtcNativeTrtcCloudModule.setRemoteRenderParams({
                userId,
                streamType,
                rotation,
                fillMode,
                mirrorType
            });
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    // 设置视频编码器输出的画面方向
    setVideoEncoderRotation(rotation) {
        if (typeof rotation !== NAME.NUMBER) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the setVideoEncoderRotation method parameter`,
            });
        }
        try {
            TrtcNativeTrtcCloudModule.setVideoEncoderRotation(rotation);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    // 设置编码器输出的画面镜像模式
    setVideoEncoderMirror(mirror) {
        if (typeof mirror !== NAME.BOOLEAN) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the setVideoEncoderMirror method parameter`,
            });
        }
        try {
            TrtcNativeTrtcCloudModule.setVideoEncoderMirror(mirror);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    // 设置重力感应的适配模式
    setGSensorMode(mode) {
        if (typeof mode !== NAME.NUMBER) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the setGSensorMode method parameter`,
            });
        }
        try {
            TrtcNativeTrtcCloudModule.setGSensorMode(mode);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    // 截图
    snapshotVideo(userId, streamType, sourceType) {
        if (streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeBig && streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeSub) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the snapshotVideo method parameters`,
            });
        }
        try {
            TrtcNativeTrtcCloudModule.snapshotVideo({ userId: userId || null, streamType, sourceType });
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    startLocalAudio(quality = TRTCAudioQuality.TRTCAudioQualityDefault) {
        if (quality !== TRTCAudioQuality.TRTCAudioQualitySpeech && quality !== TRTCAudioQuality.TRTCAudioQualityDefault && quality !== TRTCAudioQuality.TRTCAudioQualityMusic) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the startLocalAudio method parameters`,
            });
        }
        try {
            TrtcNativeTrtcCloudModule.startLocalAudio(quality);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    stopLocalAudio() {
        try {
            TrtcNativeTrtcCloudModule.stopLocalAudio();
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    muteLocalAudio(mute) {
        if (typeof mute !== NAME.BOOLEAN) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the muteLocalAudio method parameters, mute type is a ${typeof mute} not a ${NAME.BOOLEAN}`,
            });
        }
        try {
            TrtcNativeTrtcCloudModule.muteLocalAudio(!!mute);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    muteRemoteAudio(userId, mute) {
        if (typeof mute !== NAME.BOOLEAN || !userId) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the muteRemoteAudio method parameters`,
            });
        }
        try {
            TrtcNativeTrtcCloudModule.muteRemoteAudio({ userId, mute: !!mute });
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    muteAllRemoteAudio(mute) {
        if (typeof mute !== NAME.BOOLEAN) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the muteAllRemoteAudio method parameters, mute type is a ${typeof mute} not a ${NAME.BOOLEAN}`,
            });
        }
        try {
            TrtcNativeTrtcCloudModule.muteAllRemoteAudio(!!mute);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    setAudioRoute(route) {
        if (route !== TRTCAudioRoute.TRTCAudioRouteSpeaker && route !== TRTCAudioRoute.TRTCAudioRouteEarpiece) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the setAudioRoute method parameter, route is not of TRTCAudioRoute`,
            });
        }
        try {
            TrtcNativeTrtcCloudModule.setAudioRoute(route);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    enableAudioVolumeEvaluation(interval) {
        if (typeof interval !== NAME.NUMBER) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the enableAudioVolumeEvaluation method parameter, interval type is a ${typeof interval} not a ${NAME.NUMBER}`,
            });
        }
        try {
            interval > 0 && TrtcNativeTrtcCloudModule.enableAudioVolumeEvaluation(interval);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    // ///////////////////////////////////////////////////////////////////////////////
    //
    //                      美颜 + 水印
    //
    // ///////////////////////////////////////////////////////////////////////////////
    setBeautyStyle(beautyStyle) {
        if (beautyStyle !== TRTCBeautyStyle.TRTCBeautyStyleSmooth && beautyStyle !== TRTCBeautyStyle.TRTCBeautyStyleNature && beautyStyle !== TRTCBeautyStyle.TRTCBeautyStylePitu) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the setBeautyStyle method parameter, beautyStyle is not of TRTCBeautyStyle`,
            });
        }
        try {
            TrtcNativeTrtcCloudModule.setBeautyStyle(beautyStyle);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    setBeautyLevel(beautyLevel) {
        if (typeof beautyLevel !== NAME.NUMBER || (beautyLevel < 0 || beautyLevel > 9)) {
            throw new TrtcError({
                code: TXLiteJSError.INVALID_PARAMETER,
                message: `${NAME.LOG_PREFIX} please check the setBeautyLevel method parameter, beautyLevel should in the range 0-9`,
            });
        }
        try {
            TrtcNativeTrtcCloudModule.setBeautyLevel(beautyLevel);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    // ///////////////////////////////////////////////////////////////////////////////
    //
    //                      背景音效
    //
    // ///////////////////////////////////////////////////////////////////////////////
    startPlayMusic(musicParam) {
        try {
            const { id = 0 } = musicParam || {};
            TXAudioEffectManagerModule.startPlayMusic(Object.assign(Object.assign({}, musicParam), { ID: id })); // v1.2.0 的 iOS 解析的是 ID, v1.2.1 插件进行了修复
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    stopPlayMusic(id) {
        try {
            TXAudioEffectManagerModule.stopPlayMusic(id);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    pausePlayMusic(id) {
        try {
            TXAudioEffectManagerModule.pausePlayMusic(id);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    resumePlayMusic(id) {
        try {
            TXAudioEffectManagerModule.resumePlayMusic(id);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    // ///////////////////////////////////////////////////////////////////////////////
    //
    //                      屏幕分享
    //
    // ///////////////////////////////////////////////////////////////////////////////
    setSubStreamEncoderParam(param) {
        try {
            TrtcNativeTrtcCloudModule.setSubStreamEncoderParam(param);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    startScreenCapture(streamType = TRTCVideoStreamType.TRTCVideoStreamTypeSub, encParams = {}, shareParams = {}) {
        try {
            let platform = uni.getSystemInfoSync().platform;
            if ((streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeSub && streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeBig)) {
                streamType = TRTCVideoStreamType.TRTCVideoStreamTypeSub;
            }
            const { enableForegroundService = true, appGroup } = shareParams; // 默认开启前台服务, 避免退后台后进程被杀
            const screenCaptureParams = Object.assign({ streamType }, encParams);
            if (platform === NAME.ANDROID) {
                TrtcNativeTrtcCloudModule.startScreenCapture(Object.assign(Object.assign({}, screenCaptureParams), { enableForegroundService }));
            }
            if (platform === NAME.IOS) {
                if (typeof appGroup === 'string' && appGroup.length) {
                    // 开始全系统的屏幕分享(仅支持 iOS 11.0 及以上系统)
                    const params = { streamType, encParams, appGroup };
                    TrtcNativeTrtcCloudModule.startScreenCaptureByReplaykit(params);
                }
                else {
                    // 开始应用内的屏幕分享(仅支持 iOS 13.0 及以上系统)
                    TrtcNativeTrtcCloudModule.startScreenCaptureInApp(screenCaptureParams);
                }
            }
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    stopScreenCapture() {
        try {
            TrtcNativeTrtcCloudModule.stopScreenCapture();
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    pauseScreenCapture() {
        try {
            TrtcNativeTrtcCloudModule.pauseScreenCapture();
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    resumeScreenCapture() {
        try {
            TrtcNativeTrtcCloudModule.resumeScreenCapture();
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    callExperimentalAPI(params) {
        try {
            TrtcNativeTrtcCloudModule.callExperimentalAPI(params);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    setSystemVolumeType(type) {
        try {
            TrtcNativeTrtcCloudModule.setSystemVolumeType(type);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    setVideoMuteImage(fps, image) {
        const params = {
            fps,
            filePath: image,
        };
        try {
            TrtcNativeTrtcCloudModule.setVideoMuteImage(params);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    enableEncSmallVideoStream(enable, smallVideoEncParam) {
        const params = Object.assign({ enable }, smallVideoEncParam);
        try {
            TrtcNativeTrtcCloudModule.enableEncSmallVideoStream(params);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
    sendCustomCmdMsg(params) {
        try {
            TrtcNativeTrtcCloudModule.sendCustomCmdMsg(params);
        }
        catch (error) {
            throw generateError_(error);
        }
    }
}