@rongcloud/plugin-rtc 5.4.1 → 5.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  /*
2
- * RCRTC - v5.4.1
3
- * CommitId - 375b5722ca190c0b24531066c28782c0c7fd7aae
4
- * Tue Jun 14 2022 18:18:59 GMT+0800 (China Standard Time)
2
+ * RCRTC - v5.4.2
3
+ * CommitId - 70db3a426400ee9ed6b37015c553787be663f508
4
+ * Tue Jul 12 2022 15:10:18 GMT+0800 (China Standard Time)
5
5
  * ©2020 RongCloud, Inc. All rights reserved.
6
6
  */
7
- import { EventEmitter, IReceivedMessage, RTCPluginContext, IRuntime, ErrorCode, RTCMode, IJoinRTCRoomData, KVString, IServerRTCRoomEntry, LogLevel, RTCJoinType, IRTCUserData, IRTCJoinedInfo, IPluginGenerator } from '@rongcloud/engine';
7
+ import { EventEmitter, RTCMode, IRuntime, RTCPluginContext, IJoinRTCRoomData, IReceivedMessage, ErrorCode, RTCJoinType, IRTCUserData, KVString, IServerRTCRoomEntry, LogLevel, IRTCJoinedInfo, IPluginGenerator } from '@rongcloud/engine';
8
8
  export { RTCJoinType } from '@rongcloud/engine';
9
9
 
10
10
  /**
@@ -109,20 +109,6 @@ declare enum RCMediaType {
109
109
  AUDIO_VIDEO = 2
110
110
  }
111
111
 
112
- /**
113
- * 资源大小流标识枚举
114
- */
115
- declare enum RCStreamType {
116
- /**
117
- * 普通流(大流)
118
- */
119
- NORMAL = 1,
120
- /**
121
- * 小流
122
- */
123
- TINY = 2
124
- }
125
-
126
112
  declare enum RCFrameRate {
127
113
  FPS_10 = "FPS_10",
128
114
  FPS_15 = "FPS_15",
@@ -236,6 +222,12 @@ declare abstract class RCTrack extends EventEmitter {
236
222
  * 释放内存中的 video、audio 标签
237
223
  */
238
224
  __releaseMediaElement(): void;
225
+ /**
226
+ * 它检查元素是否是视频节点
227
+ * @param {any} element - 您要检查的元素是否为视频元素。
228
+ * @returns 一个布尔值。
229
+ */
230
+ private __validateVideoNodeName;
239
231
  }
240
232
 
241
233
  declare abstract class RCLocalTrack extends RCTrack {
@@ -365,6 +357,20 @@ declare class RCRemoteVideoTrack extends RCRemoteTrack {
365
357
  constructor(tag: string, userId: string, roomId?: string);
366
358
  }
367
359
 
360
+ /**
361
+ * 资源大小流标识枚举
362
+ */
363
+ declare enum RCStreamType {
364
+ /**
365
+ * 普通流(大流)
366
+ */
367
+ NORMAL = 1,
368
+ /**
369
+ * 小流
370
+ */
371
+ TINY = 2
372
+ }
373
+
368
374
  interface IStatParser {
369
375
  /**
370
376
  * 取消发布后,需把 _latestPacketsSent 中 key 为 resourceId 存储的数据清除掉
@@ -442,2491 +448,2636 @@ declare enum RCRTCLiveRole {
442
448
  }
443
449
 
444
450
  /**
445
- * 直播间类型
451
+ * RTC 消息类型常量
452
+ * @private
446
453
  */
447
- declare enum RCLivingType {
454
+ declare enum RCRTCMessageType {
448
455
  /**
449
- * 音视频直播
456
+ * 增量资源发布消息
457
+ * @deprecated
450
458
  */
451
- VIDEO = 0,
459
+ PUBLISH = "RCRTC:PublishResource",
452
460
  /**
453
- * 音频直播
461
+ * 增量资源取消发布消息
462
+ * @deprecated
454
463
  */
455
- AUDIO = 1
456
- }
457
-
458
- declare type IOnRecvPKMsg = (msg: IReceivedMessage) => void;
459
- interface IRoomPKEventListener {
464
+ UNPUBLISH = "RCRTC:UnpublishResource",
460
465
  /**
461
- * 收到连麦邀请
466
+ * 增量资源状态变更消息
467
+ * @deprecated
462
468
  */
463
- onRequestJoinOtherRoom: (info: IPKInviteInfo) => {};
469
+ MODIFY = "RCRTC:ModifyResource",
464
470
  /**
465
- * 收到取消连麦邀请
471
+ * 全量资源变更消息
466
472
  */
467
- onCancelRequestOtherRoom: (info: IPKInviteInfo) => {};
473
+ TOTAL_CONTENT_RESOURCE = "RCRTC:TotalContentResources",
468
474
  /**
469
- * 收到连麦 PK 请求响应结果
475
+ * 房间人员变更
470
476
  */
471
- onResponseJoinOtherRoom: (info: IPKInviteAnswerInfo) => {};
477
+ STATE = "RCRTC:state",
472
478
  /**
473
- * 收到 PK 结束
479
+ * 房间属性变更
474
480
  */
475
- onFinishOtherRoom: (info: IPKEndInfo) => {};
476
- }
477
- declare class RCLivingPKHandler {
478
- private _PKInfo;
479
- private readonly _context;
480
- private readonly _runtime;
481
- private readonly _service;
482
- private readonly _initOptions;
481
+ ROOM_NOTIFY = "RCRTC:RoomNtf",
483
482
  /**
484
- * 主直播房间
483
+ * 房间用户属性变更
485
484
  */
486
- private readonly _mainLivingRoom;
487
- private readonly _registerPKMsgListener;
485
+ USER_NOTIFY = "RCRTC:UserNtf",
488
486
  /**
489
- * 加入 PK 房间回调
487
+ * 被服务踢出房间
490
488
  */
491
- private readonly _onJoinedPKRoom;
489
+ KICK = "RCRTC:kick",
492
490
  /**
493
- * 退出 PK 房间回调
491
+ * 跨房间连麦 PK 请求消息
494
492
  */
495
- private readonly _onLeavePKRoom;
496
- protected readonly _clientSessionId?: string | undefined;
493
+ PK_INVITE = "RCRTC:invite",
497
494
  /**
498
- * PK 邀请超时时间,默认 30s
495
+ * 连麦请求超时
499
496
  */
500
- private readonly _inviteTimeout;
497
+ PK_INVITE_TIMEOUT = "RCRTC:inviteTimeout",
501
498
  /**
502
- * PK 房间信息
499
+ * 跨房间连麦 PK 取消请求消息
503
500
  */
504
- private _appListener;
505
- private _mainRoomId;
501
+ PK_CANCEL_INVITE = "RCRTC:cancelInvite",
506
502
  /**
507
- * 跨房间连麦加入的 PK 房间
503
+ * 跨房间连麦 PK 请求响应消息
508
504
  */
509
- private _joinedPKRooms;
510
- constructor(_PKInfo: IPKInfo, _context: RTCPluginContext, _runtime: IRuntime, _service: RCMediaService, _initOptions: IRCRTCInitOptions,
505
+ PK_INVITE_ANSWER = "RCRTC:answerInvite",
511
506
  /**
512
- * 主直播房间
507
+ * 结束跨房间连麦 PK 消息
513
508
  */
514
- _mainLivingRoom: RCLivingRoom, _registerPKMsgListener: (listener: IOnRecvPKMsg) => void,
509
+ PK_END = "RCRTC:endInvite",
515
510
  /**
516
- * 加入 PK 房间回调
511
+ * 连麦的房间不再了或离线了,主直播房间会收到的消息通知
517
512
  */
518
- _onJoinedPKRoom: (roomId: string, room: RCLivingRoom) => void,
513
+ OTHER_ROOM_OFFLINE = "RCRTC:otherRoomOffline"
514
+ }
515
+
516
+ declare enum RCInnerCDNPushMode {
517
+ AUTOMATIC = 0,
518
+ MANUAL = 1
519
+ }
520
+
521
+ declare enum RCInnerCDNBroadcast {
522
+ SPREAD = 0,
523
+ NO_SPREAD = -1
524
+ }
525
+
526
+ /**
527
+ * 与 MediaServer 交互所需的 Request Header 信息
528
+ */
529
+ interface IRTCReqHeader {
519
530
  /**
520
- * 退出 PK 房间回调
531
+ * RTC Token
532
+ * @todo 有效期问题处理
521
533
  */
522
- _onLeavePKRoom: (roomId: string) => void, _clientSessionId?: string | undefined);
523
- private _callAppListener;
534
+ Token: string;
524
535
  /**
525
- * 收到连麦邀请
536
+ * 房间 Id
526
537
  */
527
- private _onInvite;
538
+ RoomId: string;
528
539
  /**
529
- * 收到取消连麦
540
+ * 用户 Id
530
541
  */
531
- private _onCancelInvite;
532
- private _onInviteTimeout;
542
+ UserId: string;
533
543
  /**
534
- * 收到响应连麦
544
+ * 仅在直播模式下需要
535
545
  */
536
- private _onInviteAnswer;
546
+ RoomType?: RTCMode;
537
547
  /**
538
- * 收到连麦结束
548
+ * 开发者的 AppKey
539
549
  */
540
- private _onPKEnd;
550
+ 'App-Key': string;
541
551
  /**
542
- * 处理跨房间连麦相关消息
552
+ * signal 会话 session id
543
553
  */
544
- private _onRecvPKMsg;
554
+ 'Session-Id'?: string;
545
555
  /**
546
- * 注册跨房间连麦监听事件
556
+ * peerConnection Id
547
557
  */
548
- registerRoomPKEventListener(listener: IRoomPKEventListener): void;
558
+ 'Peer-Connection-Id'?: string;
549
559
  /**
550
- * 发起跨房间连麦请求
551
- * @param inviteeRoomId 被邀请者所处的房间 roomId
552
- * @param inviteeUserId 被邀请者 userId
553
- * @param options.autoMix 是否要把邀请者发布的资源,合并到被邀请者房间内的 MCU 流中
554
- * @param options.extra 拓展字段,可随邀请连麦消息透传给被邀请者
560
+ * client-session-id 标识一个端用户进入房间后的唯一标识
555
561
  */
556
- requestJoinOtherRoom(inviteeRoomId: string, inviteeUserId: string, options?: IReqResPKOptions): Promise<{
557
- code: RCRTCCode | ErrorCode;
558
- }>;
562
+ 'Client-Session-Id'?: string;
563
+ }
564
+ interface IMCUReqHeaders {
565
+ 'App-Key': string;
566
+ Token: string;
567
+ RoomId: string;
568
+ UserId: string;
569
+ SessionId: string;
570
+ }
571
+ /**
572
+ * exchange 接口中 pushOtherRooms 字段接口
573
+ */
574
+ interface IPushOtherRooms {
559
575
  /**
560
- * 取消跨房间连麦请求
561
- * @param inviteeRoomId 被邀请者所处的房间 roomId
562
- * @param inviteeUserId 被邀请者 userId
563
- * @param extra 附加信息,可随取消邀请连麦消息透传给被邀请者
576
+ * 房间 Id
564
577
  */
565
- cancelRequestJoinOtherRoom(inviteeRoomId: string, inviteeUserId: string, extra?: string): Promise<{
566
- code: RCRTCCode | ErrorCode;
567
- }>;
578
+ roomId: string;
568
579
  /**
569
- * 响应跨房间连麦请求
570
- * @param inviterRoomId 邀请者所处的房间 roomId
571
- * @param inviterUserId 邀请者 userId
572
- * @param agree 是否同意连麦
573
- * @param options.autoMix 是否要把被邀请者发布的资源,合并到邀请者房间内的 MCU 流中
574
- * @param options.extra 附加信息,可随响应连麦消息透传给邀请者
575
- */
576
- responseJoinOtherRoom(inviterRoomId: string, inviterUserId: string, agree: boolean, options?: IReqResPKOptions): Promise<{
577
- code: RCRTCCode | ErrorCode;
578
- }>;
580
+ * 是否默认合流
581
+ */
582
+ autoMix: boolean;
579
583
  /**
580
- * 结束跨房间连麦
581
- * @param roomId 需要结束连麦的房间 roomId
582
- */
583
- private _quitRoomPK;
584
- private _relaseCrtRoom;
584
+ * 房间 Id 对应的 SessionId
585
+ */
586
+ sessionId: string;
587
+ }
588
+ /**
589
+ * exchange 接口的请求体结构
590
+ */
591
+ interface IExchangeReqBody {
585
592
  /**
586
- * 加入副直播房间
587
- * @roomId 副房间的 roomId
593
+ * local description
588
594
  */
589
- joinOtherRoom(roomId: string): Promise<{
590
- code: RCRTCCode;
591
- room?: RCLivingRoom;
592
- userIds?: string[];
593
- tracks?: RCRemoteTrack[];
594
- CDNEnable?: boolean;
595
- }>;
595
+ sdp: IOfferInfo;
596
596
  /**
597
- * 退出副房间
598
- * @param room 要退出的副房间的 room 实例
599
- * @param isQuitPK 是否要结束连麦
597
+ * 订阅列表
600
598
  */
601
- leaveOtherRoom(room: RCLivingRoom, isQuitPK?: boolean): Promise<{
602
- code: RCRTCCode;
603
- }>;
604
- private _leaveOtherRoom;
599
+ subscribeList: {
600
+ /**
601
+ * 流资源 uri
602
+ */
603
+ uri: string;
604
+ /**
605
+ * 大小流订阅,`1` 为大流,`2` 为小流,默认使用大流
606
+ */
607
+ simulcast: RCStreamType;
608
+ /**
609
+ * 分辨率信息
610
+ */
611
+ resolution: string;
612
+ }[];
605
613
  /**
606
- * 获取连麦信息
607
- * @param roomId 连麦房间的 roomId
614
+ * 透传参数,一般用于传递参数给其他服务,如 MCU/Record 等,MediaServer 仅透传不处理
615
+ * @example `{"resolutionInfo":[{"trackId":"021ad6e8-a50c-479c-96c8-5f3f09d2352d","simulcast":1,"resolution":"640x480"}]}`
608
616
  */
609
- getPKInfo(roomId: string): {
610
- inviteSessionId: string;
611
- inviterRoomId: string;
612
- inviterUserId: string;
613
- inviterUserAutoMix?: boolean | undefined; /**
614
- * 加入副直播房间
615
- * @roomId 副房间的 roomId
616
- */
617
- inviteeRoomId: string;
618
- inviteeUserAutoMix?: boolean | undefined;
619
- };
617
+ extend: string;
620
618
  /**
621
- * 获取所有连麦信息
619
+ * 跨房间连麦时其他房间的推流信息
622
620
  */
623
- getAllPKInfo(): IPKInfo;
621
+ pushOtherRooms?: IPushOtherRooms[];
624
622
  /**
625
- * 获取已加入的副房间
623
+ * server 根据网络动态切换大小流开关,默认为 `false`
626
624
  */
627
- getJoinedPKRooms(): {
628
- [roomId: string]: RCLivingRoom;
629
- };
625
+ switchstream: boolean;
630
626
  }
631
-
632
- declare class RCRTCPeerCManager {
627
+ interface ILiveUrls {
633
628
  /**
634
- * 是否使用多 peerConnection
629
+ * MCU 服务地址,直播模式中用于向 MCU 服务提交 CDN 及合流配置
635
630
  */
636
- private readonly _useMutilPeerC;
631
+ configUrl: string;
637
632
  /**
638
- * roomId 或观众端 userId
633
+ * 观众端订阅地址,由业务层分发
639
634
  */
640
- private readonly _roomId;
635
+ liveUrl: string;
641
636
  /**
642
- * 断线重连每一条 peerConnection
637
+ * 自动推 CDN 模式下,发布资源后返回的 CDN 信息
643
638
  */
644
- private readonly _reTryExchange;
639
+ pull_url?: string;
640
+ }
641
+ interface IRTCResponse {
645
642
  /**
646
- * 北极星上报模块
643
+ * 请求响应码,只有在 resultCode 值为 `10000` 时才为正常响应
647
644
  */
648
- private readonly _polarisReport?;
645
+ resultCode: RCRTCCode;
649
646
  /**
650
- * 存储创建的所有 peerC,key 为 pcName,/exchange 请求中 request header 中的 Peer-Connection-Id 值
651
- */
652
- private _mutilPeerC;
653
- constructor(
647
+ * resultCode 相应的可读性文字信息
648
+ */
649
+ message: string;
654
650
  /**
655
- * 是否使用多 peerConnection
651
+ * 客户端发送的 Request-Id
656
652
  */
657
- _useMutilPeerC: boolean,
653
+ 'Request-Id': string;
654
+ }
655
+ /**
656
+ * /exchange 响应结果
657
+ */
658
+ interface IExchangeResponse extends IRTCResponse {
658
659
  /**
659
- * roomId 或观众端 userId
660
+ * 数据中心地址,当存在此值时,后续所有请求发送到该地址。该地址不携带协议头,故需要补全 `https://` 协议头
660
661
  */
661
- _roomId: string,
662
+ clusterId: string;
662
663
  /**
663
- * 断线重连每一条 peerConnection
664
+ * 发布的资源列表
664
665
  */
665
- _reTryExchange: Function,
666
+ publishList: IResource[];
666
667
  /**
667
- * 北极星上报模块
668
+ * @deprecated 目前并未使用,服务器返回值为 ''
668
669
  */
669
- _polarisReport?: PolarisReporter | undefined);
670
+ roomId: '';
670
671
  /**
671
- * 根据 track 判断是否为上行
672
+ * 远端 SDP 数据
672
673
  */
673
- private _isPub;
674
+ sdp: {
675
+ type: 'answer';
676
+ sdp: string;
677
+ };
674
678
  /**
675
- * 按 tag 分 tracks
679
+ * 直播模式推流数据,仅在直播模式有值
676
680
  */
677
- private _groupTracksByTag;
681
+ urls?: ILiveUrls;
678
682
  /**
679
- * 按规则生成 pcName
680
- * 单 peerC roomId_pub
681
- * 多 peerC 上行: roomId_tag、下行: roomId_sub
682
- * 观众加房间: roomId_sub
683
- * 观众不加房间: userId_sub
684
- * @param isPub 是否为上行、下行
685
- * @param tag 多 peerC 时,上行需资源标识
683
+ * 跨房间连麦响应数据
686
684
  */
687
- private _genPCName;
685
+ otherRoomsRes?: {
686
+ [roomId: string]: ILiveUrls;
687
+ };
688
688
  /**
689
- * 创建一个 peerC
690
- * @param pcName 使用的 peerConnection 名称
691
- * @param tracks 本次要操作的资源
689
+ * 直播 mcu 资源
690
+ * 主播发布为具体资源,会议模式为空数组
692
691
  */
693
- private _createOnePeerCItem;
692
+ mcuPublishList?: IResource[];
694
693
  /**
695
- * 创建一组 peerC
696
- * @param pcName
697
- * @returns
694
+ * 订阅成功的资源
698
695
  */
699
- createPeerCList(tracks: TrackParam[]): IMutilPeerC[];
696
+ subscribedList?: {
697
+ mediaType: RCMediaType.AUDIO_ONLY | RCMediaType.VIDEO_ONLY;
698
+ msid: string;
699
+ userId: string;
700
+ simulcast?: RCStreamType;
701
+ }[];
702
+ }
703
+ interface IBroadcastSubReqBody {
700
704
  /**
701
- * 移除所有 peerConnection 的上行资源
705
+ * 客户端 offer
702
706
  */
703
- private _removeAllLocalTrack;
707
+ sdp: {
708
+ type: 'offer';
709
+ sdp: string;
710
+ };
704
711
  /**
705
- * 销毁某一个 peerConnection
712
+ * 直播信息
706
713
  */
707
- destroyPeerC(pcName: string): void;
714
+ liveUrl?: string;
708
715
  /**
709
- * 销毁所有 peerConnection
716
+ * 订阅的资源类型,默认为 `RCMediaType.AUDIO_VIDEO`
710
717
  */
711
- private _destroyAllPeerC;
718
+ mediaType?: RCMediaType;
712
719
  /**
713
- * 获取某一个 peerC
720
+ * 订阅大/小流,默认订阅大流
714
721
  */
715
- getPCItemByPCName(pcName: string): {
716
- /**
717
- * RCRTCPeerConnection 对象
718
- */
719
- pc: RCRTCPeerConnection;
720
- /**
721
- * 存放 peerConnection 上本次要发布、取消发布、订阅、取消订阅的 track
722
- */
723
- tracks: TrackParam[];
722
+ simulcast?: RCStreamType;
723
+ /**
724
+ * 允许 server 根据网络状况动态切换大小流,默认为 false
725
+ */
726
+ switchstream: boolean;
727
+ /**
728
+ * 订阅列表
729
+ */
730
+ subscribeList?: {
724
731
  /**
725
- * 当前 peerC 是否为发上行的 peerConnection
732
+ * 流资源 uri
726
733
  */
727
- isPub: boolean;
734
+ uri: string;
728
735
  /**
729
- * peerConnection 上行资源,暂不需要
736
+ * 大小流订阅,`1` 为大流,`2` 为小流,默认使用大流
730
737
  */
731
- publishList?: IPublishedResource[] | undefined;
738
+ simulcast: RCStreamType;
732
739
  /**
733
- * peerConnection 下行资源,暂不需要
740
+ * 分辨率信息
734
741
  */
735
- subscribeList?: ISubscribeAttr[] | undefined;
736
- };
742
+ resolution: string;
743
+ }[];
737
744
  /**
738
- * 根据 trackId 获取 peerConnection 对象
745
+ * 是否采用新版本模式,加入房间
739
746
  */
740
- getPCByTrackId(trackId: string, isPub?: boolean): RCRTCPeerConnection;
747
+ newVersionFlag?: boolean;
748
+ }
749
+ interface IBroadcastSubRespBody extends IRTCResponse {
741
750
  /**
742
- * 获取所有的 peerConnection
751
+ * 已订阅的资源列表
743
752
  */
744
- getPCList(): RCRTCPeerConnection[];
753
+ subscribedList: IResource[];
745
754
  /**
746
- * 获取存储的多 peerConnection 数据
755
+ * 远端 SDP
747
756
  */
748
- getMutilPeerCData(): {
749
- [key: string]: {
750
- /**
751
- * RCRTCPeerConnection 对象
752
- */
753
- pc: RCRTCPeerConnection;
754
- /**
755
- * 存放 peerConnection 上本次要发布、取消发布、订阅、取消订阅的 track
756
- */
757
- tracks: TrackParam[];
758
- /**
759
- * 当前 peerC 是否为发上行的 peerConnection
760
- */
761
- isPub: boolean;
762
- /**
763
- * peerConnection 上行资源,暂不需要
764
- */
765
- publishList?: IPublishedResource[] | undefined;
766
- /**
767
- * peerConnection 下行资源,暂不需要
768
- */
769
- subscribeList?: ISubscribeAttr[] | undefined;
770
- };
757
+ sdp: {
758
+ type: 'answer';
759
+ sdp: string;
771
760
  };
772
- setPeerCData(pcName: string, key: string, value: any): void;
773
- /**
774
- * 销毁资源
775
- */
776
- clear(): void;
777
761
  }
778
-
779
- interface IPubSuccessRes {
780
- code: RCRTCCode;
781
- liveUrl?: string;
782
- failedTracks?: {
783
- code: RCRTCCode;
784
- tracks: RCLocalTrack[];
785
- }[];
762
+ /**
763
+ * 获取 CDN 资源拉流地址请求 headers
764
+ */
765
+ interface ICDNPlayUrlReqHeaders extends IMCUReqHeaders {
786
766
  }
787
767
  /**
788
- * 房间抽象基类
768
+ * 获取 CDN 资源拉流地址响应
789
769
  */
790
- declare abstract class RCAbstractRoom {
791
- protected readonly _context: RTCPluginContext;
792
- private readonly _runtime;
793
- readonly _roomId: string;
794
- protected readonly _roomMode: RTCMode;
795
- protected readonly _service: RCMediaService;
796
- protected readonly _initOptions: IRCRTCInitOptions;
797
- private readonly _ntfClearRoomItem;
798
- protected _isMainRoom?: boolean | undefined;
799
- /**
800
- * 是否使用多 peerConnection
801
- */
802
- protected readonly _useMutilPeerC?: boolean | undefined;
803
- protected readonly _clientSessionId?: string | undefined;
770
+ interface ICDNPlayUrlResponse extends IRTCResponse {
771
+ data: {
772
+ fps: number;
773
+ h: number;
774
+ 'pull_url': string;
775
+ w: number;
776
+ };
777
+ }
778
+ /**
779
+ * cdn_uris 里面包含的字段
780
+ */
781
+ interface ICDNUris {
804
782
  /**
805
- * 房间资源数据
783
+ * 是否扩散
806
784
  */
807
- protected readonly _roomResources: RoomData;
785
+ broadcast: RCInnerCDNBroadcast;
808
786
  /**
809
- * 远端 track
787
+ * 拉流资源的宽度
810
788
  */
811
- private _remoteTracks;
789
+ w?: number;
812
790
  /**
813
- * 已订阅参数
791
+ * 拉流资源的高度
814
792
  */
815
- protected readonly _subscribedList: ISubscribeAttr[];
793
+ h?: number;
816
794
  /**
817
- * 房间保活 rtcPing
818
- */
819
- private readonly _pinger;
795
+ * 帧率
796
+ */
797
+ fps?: number;
820
798
  /**
821
- * MediaServer 交互需要的 token 信息
799
+ * 获取拉流地址的 url
822
800
  */
823
- protected readonly _token: string;
801
+ url: string;
824
802
  /**
825
- * 每次加入房间后都会改变
803
+ * 开启、停用 CDN
826
804
  */
827
- private readonly _sessionId;
805
+ enableInnerCDN?: boolean;
828
806
  /**
829
- * PeerConnection 连接实例
807
+ * 推送模式,手动 or 自动
830
808
  */
831
- protected _destroyed: boolean;
809
+ 'push_mode': RCInnerCDNPushMode;
810
+ 'pull_safe': boolean;
811
+ }
812
+
813
+ /**
814
+ * 直播布局模式定义
815
+ */
816
+ declare enum MixLayoutMode {
832
817
  /**
833
- * 北极星上报实例
818
+ * 自定义布局
834
819
  */
835
- protected _polarisReport: PolarisReporter | null;
820
+ CUSTOMIZE = 1,
836
821
  /**
837
- * 音量上报实例
822
+ * 悬浮布局(默认)
838
823
  */
839
- private _audioLevelReport;
824
+ SUSPENSION = 2,
840
825
  /**
841
- * peerConnection 管理类
826
+ * 自适应布局
842
827
  */
843
- protected _peerCManager: RCRTCPeerCManager | null;
844
- constructor(_context: RTCPluginContext, _runtime: IRuntime, _roomId: string, data: IJoinRTCRoomData, _roomMode: RTCMode, _service: RCMediaService, _initOptions: IRCRTCInitOptions, _ntfClearRoomItem: Function, isUpgrade?: boolean, _isMainRoom?: boolean | undefined,
828
+ ADAPTATION = 3
829
+ }
830
+
831
+ /**
832
+ * 合流布局对视频的填充模式
833
+ */
834
+ declare enum MixVideoRenderMode {
845
835
  /**
846
- * 是否使用多 peerConnection
836
+ * 裁剪(默认)
847
837
  */
848
- _useMutilPeerC?: boolean | undefined, _clientSessionId?: string | undefined);
849
- private _initRemoteTracks;
850
- private _handlePingResult;
838
+ CROP = 1,
851
839
  /**
852
- * 设置房间上行资源的总码率配置
853
- * @description
854
- * * 自 v5.1.0 版本开始,推荐使用 `RCLocalTrack.setBitrate` 对不同流分别指定码率。
855
- * * 该方法仅在 SDP `plan-b` 协议下(Chrome 92 与 Safari 11 之前的版本)有效。
856
- * @param max 音视频发送码率上限,不可小于 200 且不可小于 `min`
857
- * @param min 音视频发送码率下限,默认值为 1,且不可小于 1,不可大于 `max`
858
- * @param start 起始码率,默认为码率上限的 70%
840
+ * 不裁剪
859
841
  */
860
- setBitrate(max: number, min: number, start?: number): void;
861
- private _onTrackReady;
862
- protected _callAppListener(eventType: keyof IRoomEventListener, ...attrs: any[]): void;
863
- private _onUserUnpublish;
864
- private _onTrackUnpublish;
865
- private _unpublishPrev;
866
- __parseInnerMessage(message: IReceivedMessage): boolean;
867
- private msgTaskQueue;
842
+ WHOLE = 2
843
+ }
844
+
845
+ declare enum RCInnerCDNModel {
846
+ OPEN = 1,
847
+ STOP = 2
848
+ }
849
+
850
+ declare enum RCMixInputFilterMode {
851
+ /** 全合流,后续加入房间的用户会自动合流 */
852
+ AUDIO_VIDEO_ALL = 0,
853
+ /** 全不合流,后续加入本房间的用户 */
854
+ AUDIO_VIDEO_NO = 1,
855
+ /** 音频全订阅, 视频全不订阅 */
856
+ AUDIO_ALL_VIDEO_NO = 2,
857
+ /** 视频全订阅, 音频全不订阅 */
858
+ AUDIO_NO_VIDEO_ALL = 3,
868
859
  /**
869
- * 被踢出房间通知
870
- * @param byServer
871
- * * 当值为 false 时,说明本端 rtcPing 超时
872
- * * 当值为 true 时,说明本端收到被踢出房间通知
860
+ * 根据设置的音频合流列表和视频合流列表合并媒体流
873
861
  */
874
- private _kickoff;
875
- private _rtcpeerClosed;
862
+ AUDIO_VIDEO_INPUT = 4,
863
+ /** 音频全订阅,视频根据设置的视频合流列表 */
864
+ AUDIO_ALL_VIDEO_INPUT = 5,
865
+ /** 音频全不订阅, 视频根据input里面的视频项订阅 */
866
+ AUDIO_NO_VIDEO_INPUT = 6,
867
+ /** 视频全订阅, 音频根据input里面的音频项订阅 */
868
+ AUDIO_INPUT_VIDEO_ALL = 7,
869
+ /** 视频全不订阅, 音频根据input里面的音频项订阅 */
870
+ AUDIO_INPUT_VIDEO_NO = 8,
871
+ /** 按房间列表订阅音视频(保留当前已经订阅的, 但没在房间列表里的音视频) */
872
+ ROOM_AUDIO_VIDEO_APPEND = 9,
873
+ /** 按房间列表订阅音视频(清理当前已经订阅的, 但没在房间列表里的音视频) */
874
+ ROOM_AUDIO_VIDEO_NOT_APPEND = 10,
875
+ /** 按房间列表订阅音频, 不订阅视频(保留当前已经订阅的, 但没在房间列表里的音频) */
876
+ ROOM_AUDIO_APPEND = 11,
877
+ /** 按房间列表订阅音视, 不订阅视频(清理当前已经订阅的, 但没在房间列表里的音频) */
878
+ ROOM_AUDIO_NOT_APPEND = 12,
879
+ /** 按房间列表订阅视频, 不订阅音频(保留当前已经订阅的, 但没在房间列表里的视频) */
880
+ ROOM_VIDEO_APPEND = 13,
881
+ /** 按房间列表订阅视频, 不订阅音频(清理当前已经订阅的, 但没在房间列表里的视频) */
882
+ ROOM_VIDEO_NOT_APPEND = 14
883
+ }
884
+
885
+ /**
886
+ * 合流后的 video 输出编码配置,包含分辨率、帧率、码率配置项
887
+ */
888
+ interface IMCUOutputVideoAttrs {
876
889
  /**
877
- * 处理资源变更事件
878
- * @param content
879
- * @param messageType 消息类型
880
- * @param userId 消息发送者
890
+ * 视频分辨率宽度
891
+ */
892
+ width?: number;
893
+ /**
894
+ * 视频分辨率高度
895
+ */
896
+ height?: number;
897
+ /**
898
+ * 帧率
899
+ */
900
+ fps?: number;
901
+ /**
902
+ * 码率
881
903
  */
882
- protected _resourceHandle(content: {
904
+ bitrate?: number;
905
+ }
906
+ /**
907
+ * 合并入 MCU 的音频流
908
+ */
909
+ interface IMCUInputAudio {
910
+ user_id: string;
911
+ stream_id: string;
912
+ }
913
+ /**
914
+ * 自定义布局中的单一视频流布局
915
+ */
916
+ interface IMCUInputVideoLayout {
917
+ user_id: string;
918
+ stream_id: string;
919
+ x: number;
920
+ y: number;
921
+ width: number;
922
+ height: number;
923
+ }
924
+ /**
925
+ * 图片配置,用于水印、视频流背景图
926
+ */
927
+ interface IPictureAttrs {
928
+ /**
929
+ * 资源下载地址,需包含协议
930
+ */
931
+ uri: string;
932
+ /**
933
+ * 相对于整体画布的起始位置 x 坐标
934
+ */
935
+ x: number;
936
+ /**
937
+ * 相对于整体画布的起始位置 y 坐标
938
+ */
939
+ y: number;
940
+ /**
941
+ * 相对于整体画布的宽(百分比),有效值 `0.0` - `1.0`
942
+ */
943
+ w: number;
944
+ /**
945
+ * 相对于整体画布的高(百分比),有效值 `0.0` - `1.0`
946
+ */
947
+ h: number;
948
+ }
949
+ /**
950
+ * 合流后的 Video 输出配置,包含背景图、背景色、大小流编码等配置项
951
+ */
952
+ interface IMCUOutputVideoConfig {
953
+ /**
954
+ * 标准流输出定义
955
+ */
956
+ normal?: IMCUOutputVideoAttrs;
957
+ /**
958
+ * 小流输出定义
959
+ */
960
+ tiny?: IMCUOutputVideoAttrs;
961
+ exparams?: {
962
+ /**
963
+ * 合流布局时,对视频流的填充方式
964
+ */
965
+ renderMode: MixVideoRenderMode;
966
+ };
967
+ /**
968
+ * 背景色,如 `'0xf1a2c3'`
969
+ */
970
+ backgroundColor?: string;
971
+ /**
972
+ * 背景图
973
+ */
974
+ backgroundPicture?: {
883
975
  /**
884
- * 旧版本兼容参数,当收到非 `RTCMessageName.TOTAL_CONTENT_RESOURCE` 时:
885
- * * ignore 值为 `true` 表示该消息由 signal server 向旧版本 RTCLib 提供的兼容消息,无需处理
886
- * * 否则认为该消息是由旧版本 RTCLib 主动发出的增量变更消息,需要处理
976
+ * 填充模式:
977
+ * 1. 按比例裁剪
978
+ * 2. 不裁剪,按比例压缩
887
979
  */
888
- ignore?: boolean;
980
+ fillMode: 1 | 2;
889
981
  /**
890
- * 发布到房间内的资源列表,`RTCMessageName.TOTAL_CONTENT_RESOURCE` 消息携带全量数据,否则为增量数据
982
+ * 资源列表
891
983
  */
892
- uris: IPublishedResource[];
893
- }, messageType: string, userId: string): Promise<void>;
894
- private _onTrackPublish;
984
+ picture: IPictureAttrs[];
985
+ };
986
+ }
987
+ /**
988
+ * 合流后的媒体输出定义
989
+ */
990
+ interface IMCUOutputConfig {
895
991
  /**
896
- * 处理 `RCRTCMessageType.STATE` 消息
897
- * @param content
992
+ * 输出视频配置
898
993
  */
899
- private _stateHandle;
994
+ video: IMCUOutputVideoConfig;
900
995
  /**
901
- * 获取房间 Id
996
+ * 输出音频配置
902
997
  */
903
- getRoomId(): string;
998
+ audio?: {
999
+ /**
1000
+ * 音频码率
1001
+ */
1002
+ bitrate: number;
1003
+ };
904
1004
  /**
905
- * 获取当前 userId
1005
+ * CDN 推流地址列表
906
1006
  */
907
- getCrtUserId(): string;
1007
+ cdn?: {
1008
+ /**
1009
+ * 推流地址,如:`'rtmp://xxxx'`
1010
+ */
1011
+ pushurl: string;
1012
+ }[];
1013
+ }
1014
+ /**
1015
+ * 时间戳参数,用于水印
1016
+ */
1017
+ interface ITimestampAttrs {
908
1018
  /**
909
- * 获取 _pc 实例
1019
+ * 时区
910
1020
  */
911
- __getPC(): RCRTCPeerConnection[];
1021
+ timezone: number;
912
1022
  /**
913
- * 获取远程用户列表,不包含当前用户
1023
+ * 字体像素大小
914
1024
  */
915
- getRemoteUserIds(): string[];
1025
+ fontSize: number;
916
1026
  /**
917
- * 获取所有房间已发布的远端资源列表
918
- * @returns
1027
+ * 字体颜色
919
1028
  */
920
- getRemoteTracks(): RCRemoteTrack[];
1029
+ color: 'black' | 'white';
921
1030
  /**
922
- * 获取远端用户的资源列表
923
- * @param userId
924
- * @returns
1031
+ * 透明度,有效值 `0.0` 至 `1.0`
925
1032
  */
926
- getRemoteTracksByUserId(userId: string): RCRemoteTrack[];
1033
+ alpha: number;
927
1034
  /**
928
- * 获取房间当前会话 Id,当房间内已无成员时房间会回收,重新加入时 sessionId 将更新
1035
+ * 相较于整体画布的 x 坐标(百分比),有效值 `0.0` 至 `1.0`
929
1036
  */
930
- getSessionId(): string;
1037
+ x: number;
931
1038
  /**
932
- * 向房间内发消息
933
- * @param name 消息名称
934
- * @param content 消息内容
1039
+ * 相较于整体画布的 y 坐标(百分比),有效值 `0.0` 至 `1.0`
935
1040
  */
936
- sendMessage(name: string, content: any): Promise<{
937
- code: RCRTCCode;
938
- }>;
1041
+ y: number;
1042
+ }
1043
+ /**
1044
+ * 文本参数,用于水印
1045
+ */
1046
+ interface ITextAttrs {
939
1047
  /**
940
- * 设置房间属性
941
- * @param key 属性名
942
- * @param value 属性值
943
- * @param message 是否在设置属性的时候携带消息内容,传空则不往房间中发送消息
944
- * @param isInner RTC 业务内部使用参数,用户忽略
1048
+ * 文字内容
945
1049
  */
946
- setRoomAttribute(key: string, value: string, message?: {
947
- name: string;
948
- content: string;
949
- }, isInner?: boolean): Promise<{
950
- code: RCRTCCode;
951
- }>;
1050
+ content: string;
952
1051
  /**
953
- * 删除房间属性
954
- * @param keys 待删除的属性名数组
955
- * @param message 是否在删除属性的时候携带消息内容,传空则不往房间中发送消息
956
- * @param isInner RTC 业务内部使用参数,用户忽略
1052
+ * 文字像素
957
1053
  */
958
- deleteRoomAttributes(keys: string[], message?: {
959
- name: string;
960
- content: string;
961
- }, isInner?: boolean): Promise<{
962
- code: RCRTCCode;
963
- }>;
1054
+ fontSize: number;
964
1055
  /**
965
- * 获取房间属性
966
- * @param keys 要查询的属性名数组,当数组长度为空时,取所有已设置的 kv 值
967
- * @param isInner RTC 业务内部使用参数,用户忽略
1056
+ * 文字颜色
968
1057
  */
969
- getRoomAttributes(keys?: string[], isInner?: boolean): Promise<{
970
- code: RCRTCCode;
971
- data?: KVString;
972
- }>;
1058
+ color: 'black' | 'white';
973
1059
  /**
974
- * 设置当前用户属性(暂不开放)
975
- * @param key 属性名
976
- * @param value 属性值
977
- * @param message 是否在设置属性的时候携带消息内容,传空则不往房间中发送消息
1060
+ * 透明度,有效值 `0.0` 至 `1.0`
978
1061
  */
979
- private _setUserAttributeValue;
1062
+ alpha: number;
980
1063
  /**
981
- * 删除当前用户属性(暂不开放)
982
- * @param keys 待删除的属性名数组
983
- * @param message 是否在删除属性的时候携带消息内容,传空则不往房间中发送消息
1064
+ * 相较于整体画布的 x 坐标(百分比),有效值 `0.0` 至 `1.0`
984
1065
  */
985
- private _deleteUserAttributes;
1066
+ x: number;
986
1067
  /**
987
- * 获取当前用户属性(暂不开放)
988
- * @param keys 要查询的属性名数组
1068
+ * 相较于整体画布的 y 坐标(百分比),有效值 `0.0` 至 `1.0`
989
1069
  */
990
- private _getUserAttributes;
1070
+ y: number;
1071
+ }
1072
+ /**
1073
+ * 屏幕水印配置
1074
+ */
1075
+ interface IWaterMarkConfig {
991
1076
  /**
992
- * 查询房间是否已销毁
1077
+ * 时间戳水印配置
993
1078
  */
994
- isDestroyed(): boolean;
1079
+ timestamp?: ITimestampAttrs;
995
1080
  /**
996
- * 退出并销毁当前房间实例,退出后该房间的所有方法将不可用
1081
+ * 图片水印配置
997
1082
  */
998
- __destroy(quitRoom: boolean): Promise<void>;
1083
+ picture?: IPictureAttrs[];
999
1084
  /**
1000
- * 退出房间之前禁用所有远端资源,避免退出动作耗时过长,
1001
- * 导致在未完全退出的过程中仍能听到房间内的声音问题
1085
+ * 文字水印配置
1002
1086
  */
1003
- private _muteRemoteTracksBeforeQuit;
1004
- private _leaveHandle;
1087
+ text: ITextAttrs[];
1088
+ }
1089
+ /**
1090
+ * 合流前的单一视频流水印配置
1091
+ */
1092
+ interface IMCUSignalScreenWaterMarkConfig extends IWaterMarkConfig {
1005
1093
  /**
1006
- * 释放 PCManager 上的资源
1094
+ * 媒体流的 msid
1007
1095
  */
1008
- private _releasePCManager;
1009
- private _onLocalTrackDestroied;
1096
+ streamId: string;
1097
+ }
1098
+ interface IMCUWaterMarkConfig {
1010
1099
  /**
1011
- * 本端流状态修改,需通知房间内其他成员
1012
- * @param localTrack
1100
+ * 合流后的屏幕水印配置
1013
1101
  */
1014
- private _onLocalTrackMuted;
1102
+ mixScreen: IWaterMarkConfig;
1015
1103
  /**
1016
- * 从 pc 移除当次发布失败的资源
1104
+ * 合流前的单人视频流水印配置
1017
1105
  */
1018
- private _removePubFailedTracks;
1106
+ signalScreen: IMCUSignalScreenWaterMarkConfig[];
1107
+ }
1108
+ /**
1109
+ * 发布到服务器的 MCU 配置数据
1110
+ */
1111
+ interface IMCUConfig {
1019
1112
  /**
1020
- * 增量发布资源,若发布的资源 tag 及媒体类型重复,后者将覆盖前者进行发布。
1021
- * @param tracks 待发布的 RCLocalTrack 实例
1022
- * @returns
1113
+ * 为向后兼容,当前为常量 1
1023
1114
  */
1024
- publish(tracks: (RCLocalTrack | IPublishAttrs)[]): Promise<IPubSuccessRes>;
1025
- private __publish;
1115
+ version: 1;
1026
1116
  /**
1027
- * 处理批量 /exhcange 的返回数据,作为一次 publish 接口返回
1028
- * @param pubResList 每一个 tag 的发布结果[]
1117
+ * 布局模式,在只配置推流 CDN 时,该值不存在
1029
1118
  */
1030
- private _mergePublishRes;
1119
+ mode: MixLayoutMode;
1031
1120
  /**
1032
- * 获取跨房间连麦需携带参数 pushOtherRooms 的值
1121
+ * 渲染到主位置上的流 Id,当该值为空时,输出到主位置的流按发布时间顺序优先选择最早发布的流
1033
1122
  */
1034
- protected _getPushOtherRoomsParams(): IPushOtherRooms[];
1123
+ host_stream_id?: string;
1035
1124
  /**
1036
- * ice 断线后,尝试重新走 exchange
1125
+ * 自定义布局输入定义,只有在 mode 值为 `MixLayoutMode.CUSTOMIZE` 时需传值
1037
1126
  */
1038
- protected _reTryExchange(pcName: string, isPub: boolean): Promise<void>;
1039
- protected _exchangeHandle(body: IExchangeReqBody, pcName: string): Promise<{
1040
- code: RCRTCCode;
1041
- data?: IExchangeResponse | undefined;
1042
- }>;
1043
- protected _getRTCReqestHeaders(pcName: string): IRTCReqHeader;
1127
+ input?: {
1128
+ video?: IMCUInputVideoLayout[];
1129
+ audio?: IMCUInputAudio[];
1130
+ };
1131
+ /**
1132
+ * 合流后的媒体输出配置
1133
+ */
1134
+ output?: IMCUOutputConfig;
1135
+ /**
1136
+ * 水印配置
1137
+ */
1138
+ waterMark?: IMCUWaterMarkConfig;
1139
+ /**
1140
+ * MCU 拉流配置,决定 MCU 从 MediaServer 拉流的方式
1141
+ */
1142
+ inputFilterMode?: RCMixInputFilterMode;
1143
+ /**
1144
+ * MCU 混入列表中房间内的资源
1145
+ */
1146
+ mixRooms?: string[];
1147
+ }
1148
+ /**
1149
+ * 设置开启、停用内置 CDN 数据
1150
+ */
1151
+ interface ISetEnableCDN {
1152
+ version: 2;
1153
+ output: {
1154
+ /**
1155
+ * 手动开启/停用内置 CDN
1156
+ */
1157
+ inCDNModel: RCInnerCDNModel;
1158
+ };
1159
+ }
1160
+
1161
+ declare class RCMediaService {
1162
+ private readonly _runtime;
1163
+ private readonly _context;
1044
1164
  /**
1045
- * 获取 exchange 接口的请求体数据
1046
- * @param subscribeList 订阅清单
1047
- * @param iceRestart
1165
+ * 自定义 MediaServer 地址,当有值时,不再使用导航内的地址
1048
1166
  */
1049
- protected _createExchangeParams(subscribeList: ISubscribeAttr[], iceRestart: boolean, pc: RCRTCPeerConnection): Promise<IExchangeReqBody>;
1167
+ private readonly _msUrl?;
1050
1168
  /**
1051
- * 获取已发布资源的 state 数据
1052
- * @param trackId
1169
+ * 请求超时时长
1053
1170
  */
1054
- private _getResourceState;
1171
+ private readonly _timeout;
1055
1172
  /**
1056
- * 增量取消资源发布,若相应资源中存在小流资源,则同时取消发布
1057
- * @param tracks 取消发布的 RCLocalTrack 列表
1173
+ * navi 中获取的媒体服务地址
1058
1174
  */
1059
- unpublish(tracks: RCLocalTrack[]): Promise<IPubSuccessRes>;
1060
- private __unpublish;
1061
- private _mergeUnpublishRes;
1175
+ private readonly _msInNavi;
1062
1176
  /**
1063
- * 根据资源 Id 获取资源数据
1064
- * @param resourceId
1177
+ * 已失败的请求地址
1065
1178
  */
1066
- private _getResourceById;
1179
+ private readonly _failedMs;
1067
1180
  /**
1068
- * resourceId 有效性验证
1069
- * @param resourceId
1181
+ * 服务器指纹数据,客户端不得修改,直接透传
1070
1182
  */
1071
- protected _isValidResourceId(resourceId: string): boolean;
1183
+ private _rtcFinger;
1072
1184
  /**
1073
- * 订阅资源
1074
- * @param tracks
1185
+ * 服务器接口返回的 clusterId 数据,当此数据有值时,后续所有请求向此服务发送
1075
1186
  */
1076
- subscribe(tracks: (RCRemoteTrack | ISubscribeAttr)[]): Promise<{
1077
- code: RCRTCCode;
1078
- failedList?: ISubscribeAttr[];
1079
- }>;
1080
- private __subscribe;
1187
+ private _clusterId;
1081
1188
  /**
1082
- * 取消订阅资源
1083
- * @param tracks 预取消远端资源
1189
+ * MCU 服务地址
1084
1190
  */
1085
- unsubscribe(tracks: RCRemoteTrack[]): Promise<{
1086
- code: RCRTCCode;
1087
- failedList?: ISubscribeAttr[];
1088
- }>;
1089
- private __unsubscribe;
1090
- protected _assertRoomDestroyed(): RCRTCCode | undefined;
1191
+ private _configUrl;
1192
+ constructor(_runtime: IRuntime, _context: RTCPluginContext,
1091
1193
  /**
1092
- * 获取已发布的本地资源
1093
- * @param trackId
1094
- * @returns
1194
+ * 自定义 MediaServer 地址,当有值时,不再使用导航内的地址
1095
1195
  */
1096
- getLocalTrack(trackId: string): RCLocalTrack | null;
1196
+ _msUrl?: string | undefined,
1097
1197
  /**
1098
- * 获取所有已发布的资源
1198
+ * 请求超时时长
1099
1199
  */
1100
- getLocalTracks(): RCLocalTrack[];
1200
+ _timeout?: number);
1201
+ getNaviMS(): string[];
1101
1202
  /**
1102
- * 根据 trackId 获取房间内的远端资源
1103
- * @param trackId
1104
- * @returns
1203
+ * 发送请求,请求发送若失败,会继续尝试使用后续可用地址直到无地址可用,此时认为请求失败
1204
+ * @param path
1205
+ * @param header
1206
+ * @param body
1105
1207
  */
1106
- getRemoteTrack(trackId: string): RCRemoteTrack | null;
1208
+ private _request;
1107
1209
  /**
1108
- * 强制修改订阅列表,仅订阅数组中的资源,取消订阅其他已订阅资源。
1109
- * 当参数为 `[]` 时,意味着不再订阅任何资源
1110
- * @param tracks 变更的资源列表
1210
+ * 资源协商接口,订阅、发布、变更资源均可以使用此接口。该接口通过 sdp 字段交换 SDP 信息,
1211
+ * 并通过 subscribeList 和 publishList 表明最终发布和订阅的资源。本端产出 offer,服务器产出 answer
1212
+ * 每次接口调用,都会全量覆盖发布和订阅的资源。
1213
+ * @param header
1214
+ * @param body
1111
1215
  */
1112
- updateSubList(tracks: (RCRemoteTrack | ISubscribeAttr)[]): Promise<{
1216
+ exchange(headers: IRTCReqHeader, body: IExchangeReqBody): Promise<{
1113
1217
  code: RCRTCCode;
1218
+ data?: IExchangeResponse | undefined;
1114
1219
  }>;
1115
- private _updateSubListHandle;
1116
- private _appListener;
1117
- /**
1118
- * 注册事件监听器,多次注册会导致后者覆盖前者,可以通过使用 `registerRoomEventListener(null)` 取消注册
1119
- * @param listener
1120
- */
1121
- registerRoomEventListener(listener: IRoomEventListener | null): void;
1122
- private _reportListener;
1123
- /**
1124
- * 注册房间数据监控
1125
- * @param listener
1126
- * @description 该方法暂仅支持 Chrome 浏览器
1127
- */
1128
- registerReportListener(listener: IRCRTCReportListener | null): void;
1129
1220
  /**
1130
- * 音量上报
1131
- * @param handler 业务端传入的音量上报事件
1132
- * @param gap 上报时间间隔
1221
+ * 退出房间
1133
1222
  */
1134
- onAudioLevelChange(handler: IAudioLevelChangeHandler | null, gap?: number): void;
1223
+ exit(headers: IRTCReqHeader): Promise<RCRTCCode>;
1135
1224
  /**
1136
- * 断线重连后尝试补发断线过程中的通知信息
1225
+ * 观众端订阅主播资源
1137
1226
  */
1138
- __onReconnected(livingType?: RCLivingType): Promise<{
1139
- data: IJoinRTCRoomData | undefined;
1140
- } | void>;
1141
- private _onAudioMuteChange;
1142
- private _onVideoMuteChange;
1227
+ broadcastSubscribe(headers: IRTCReqHeader, body: IBroadcastSubReqBody): Promise<{
1228
+ code: RCRTCCode;
1229
+ data?: IBroadcastSubRespBody | undefined;
1230
+ }>;
1143
1231
  /**
1144
- * 观众切换为主播后直接处理人员变更及资源变更
1232
+ * 观众端退出订阅
1145
1233
  */
1146
- protected _afterChangedRole(data: IJoinRTCRoomData): void;
1234
+ broadcastExit(headers: IRTCReqHeader): Promise<{
1235
+ code: RCRTCCode;
1236
+ }>;
1147
1237
  /**
1148
- * 销毁远端资源
1238
+ * 直播推流、自定义布局配置
1149
1239
  */
1150
- private _removeRemoteTracks;
1240
+ setMcuConfig(headers: IMCUReqHeaders, body: IMCUConfig | ISetEnableCDN): Promise<{
1241
+ code: RCRTCCode;
1242
+ res?: any;
1243
+ }>;
1151
1244
  /**
1152
- * 存储连麦监听事件
1245
+ * 房间内观众获取 CDN 资源信息、拉流地址
1153
1246
  */
1154
- private _onRecvPKMsg;
1247
+ getCDNResourceInfo(headers: ICDNPlayUrlReqHeaders, url: string): Promise<{
1248
+ code: RCRTCCode;
1249
+ res?: ICDNPlayUrlResponse;
1250
+ }>;
1251
+ }
1252
+
1253
+ /**
1254
+ * 直播间类型
1255
+ */
1256
+ declare enum RCLivingType {
1155
1257
  /**
1156
- * 注册 PK 业务监听方法
1258
+ * 音视频直播
1157
1259
  */
1158
- protected _registerPKMsgListener(listener: IOnRecvPKMsg | null): void;
1260
+ VIDEO = 0,
1159
1261
  /**
1160
- * 退出 PK 房间
1262
+ * 音频直播
1161
1263
  */
1162
- protected _quitAllPKRoom(): void;
1163
- getClientSessionId(): string | undefined;
1164
- }
1165
-
1166
- declare class RCLocalMediaStream {
1167
- readonly msid: string;
1168
- readonly mediaStream: MediaStream;
1169
- readonly tinyStream: MediaStream;
1170
- readonly tag: string;
1171
- constructor(msid: string);
1264
+ AUDIO = 1
1172
1265
  }
1173
1266
 
1174
- interface IAudienceRoomEventListener extends IRCRTCTrackEventListener {
1267
+ declare class RCRTCPeerCManager {
1175
1268
  /**
1176
- * 主播加入
1177
- * @param userIds 加入主播的 id 列表
1269
+ * 是否使用多 peerConnection
1178
1270
  */
1179
- onAnchorJoin?(userId: string[]): void;
1271
+ private readonly _useMutilPeerC;
1180
1272
  /**
1181
- * 主播退出
1182
- * @param userIds 退出主播的 id 列表
1273
+ * roomId 或观众端 userId
1183
1274
  */
1184
- onAnchorLeave?(userId: string[]): void;
1275
+ private readonly _roomId;
1185
1276
  /**
1186
- * 房间内合流发布资源
1187
- * @param tracks 新发布的合流音轨与视轨数据列表,包含新发布的 RCRemoteAudioTrack 与 RCRemoteVideoTrack 实例
1188
- * @description
1189
- * 当房间内某个主播第一次发布资源时触发
1277
+ * 断线重连每一条 peerConnection
1190
1278
  */
1191
- onTrackPublish?(tracks: RCRemoteTrack[]): void;
1279
+ private readonly _reTryExchange;
1192
1280
  /**
1193
- * 房间内取消合流发布资源
1194
- * @param tracks 被取消发布的合流音轨与视轨数据列表
1195
- * @description
1196
- * 当房间内全部主播退出房间时,SDK 内部会取消对资源的订阅,业务层仅需处理 UI 业务
1281
+ * 当前用户 id
1197
1282
  */
1198
- onTrackUnpublish?(tracks: RCRemoteTrack[]): void;
1283
+ private readonly _currentUserId;
1199
1284
  /**
1200
- * 房间内主播发布资源
1201
- * @param tracks 主播新发布的音轨与视轨数据列表,包含新发布的 RCRemoteAudioTrack 与 RCRemoteVideoTrack 实例
1285
+ * 北极星上报模块
1202
1286
  */
1203
- onAnchorTrackPublish?(tracks: RCRemoteTrack[]): void;
1287
+ private readonly _polarisReport?;
1204
1288
  /**
1205
- * 房间内主播取消发布资源
1206
- * @param tracks 被主播取消发布的音轨与视轨数据列表
1207
- * @description 当资源被取消发布时,SDK 内部会取消对相关资源的订阅,业务层仅需处理 UI 业务
1289
+ * 存储创建的所有 peerC,key 为 pcName,/exchange 请求中 request header 中的 Peer-Connection-Id 值
1208
1290
  */
1209
- onAnchorTrackUnpublish?(tracks: RCRemoteTrack[]): void;
1291
+ private _mutilPeerC;
1292
+ constructor(
1210
1293
  /**
1211
- * 房间主播禁用/启用音频
1212
- * @param audioTrack RCRemoteAudioTrack 类实例
1294
+ * 是否使用多 peerConnection
1213
1295
  */
1214
- onAudioMuteChange?(audioTrack: RCRemoteAudioTrack): void;
1296
+ _useMutilPeerC: boolean,
1215
1297
  /**
1216
- * 房间主播禁用/启用视频
1217
- * @param videoTrack RCRemoteVideoTrack 类实例对象
1218
- */
1219
- onVideoMuteChange?(videoTrack: RCRemoteVideoTrack): void;
1298
+ * roomId 或观众端 userId
1299
+ */
1300
+ _roomId: string,
1220
1301
  /**
1221
- * 房间内主播把发布的资源推至 CDN
1302
+ * 断线重连每一条 peerConnection
1222
1303
  */
1223
- onCDNInfoEnable?(CDNInfo: {
1224
- resolution: RCResolution;
1225
- fps: RCFrameRate;
1226
- }): void;
1304
+ _reTryExchange: Function,
1227
1305
  /**
1228
- * 主播停止推 CDN
1306
+ * 当前用户 id
1229
1307
  */
1230
- onCDNInfoDisable?(): void;
1308
+ _currentUserId: string,
1231
1309
  /**
1232
- * 主播改变推 CDN 的分辨率或帧率
1310
+ * 北极星上报模块
1233
1311
  */
1234
- onCDNInfoChange?(CDNInfo: {
1235
- resolution: RCResolution;
1236
- fps: RCFrameRate;
1237
- }): void;
1238
- }
1239
- /**
1240
- * 观众直播房间类
1241
- * 处理:
1242
- * 1、通知观众房间内 人员变更、资源变更
1243
- * 2、观众订阅、取消订阅资源
1244
- */
1245
- declare class RCAudienceLivingRoom {
1246
- private readonly _context;
1247
- private readonly _runtime;
1248
- private readonly _initOptions;
1249
- readonly _roomId: string;
1250
- private readonly _joinResData;
1251
- readonly _livingType: RCLivingType;
1252
- private _useMutilPeerC?;
1253
- protected readonly _clientSessionId?: string | undefined;
1254
- private readonly _service;
1312
+ _polarisReport?: PolarisReporter | undefined);
1313
+ get useMutilPeerC(): boolean;
1255
1314
  /**
1256
- * 主播列表
1315
+ * 根据 track 判断是否为上行
1257
1316
  */
1258
- private _roomAnchorList;
1317
+ private _isPub;
1259
1318
  /**
1260
- * 合流、分流资源
1319
+ * 按 tag 分 tracks
1261
1320
  */
1262
- private _roomRes;
1321
+ private _groupTracksByTag;
1263
1322
  /**
1264
- * 主播分流资源
1323
+ * 按规则生成 pcName
1324
+ * 单 peerC roomId_pub
1325
+ * 多 peerC 上行: roomId_tag、下行: roomId_sub
1326
+ * 观众加房间: roomId_sub
1327
+ * 观众不加房间: userId_sub
1328
+ * @param isPub 是否为上行、下行
1329
+ * @param tag 多 peerC 时,上行需资源标识
1265
1330
  */
1266
- private _roomAnchorRes;
1331
+ private _genPCName;
1267
1332
  /**
1268
- * 合流、分流 remoteTracks
1333
+ * 创建一个 peerC
1334
+ * @param pcName 使用的 peerConnection 名称
1335
+ * @param tracks 本次要操作的资源
1269
1336
  */
1270
- private _remoteTracks;
1271
- private _appListener;
1272
- private _pc;
1273
- private _subscribedList;
1274
- private _sessionId;
1275
- private _destroyed;
1337
+ private _createOnePeerCItem;
1276
1338
  /**
1277
- * 北极星上报实例
1339
+ * 创建一组 peerC
1340
+ * @param pcName
1341
+ * @returns
1278
1342
  */
1279
- protected _polarisReport: PolarisReporter | null;
1343
+ createPeerCList(tracks: TrackParam[]): IMutilPeerC[];
1280
1344
  /**
1281
- * 音量上报实例
1345
+ * 移除所有 peerConnection 的上行资源
1282
1346
  */
1283
- private _audioLevelReport;
1347
+ private _removeAllLocalTrack;
1284
1348
  /**
1285
- * cdn_uris 资源
1349
+ * 销毁某一个 peerConnection
1286
1350
  */
1287
- private _CDNUris;
1351
+ destroyPeerC(pcName: string): void;
1288
1352
  /**
1289
- * 使用的 peerConnection 对应 id
1353
+ * 销毁所有 peerConnection
1290
1354
  */
1291
- private _pcName;
1292
- /**
1293
- * peerConnection 管理类
1294
- */
1295
- private _peerCManager;
1296
- constructor(_context: RTCPluginContext, _runtime: IRuntime, _initOptions: IRCRTCInitOptions, _roomId: string, _joinResData: {
1297
- token: string;
1298
- kvEntries: IServerRTCRoomEntry[];
1299
- }, _livingType: RCLivingType, _useMutilPeerC?: boolean | undefined, _clientSessionId?: string | undefined);
1355
+ private _destroyAllPeerC;
1300
1356
  /**
1301
- * 解析服务端返回的 KV 数据,赋值 room 内数据
1357
+ * 获取某一个 peerC
1302
1358
  */
1303
- private _setInitData;
1304
- protected _assertRoomDestroyed(): RCRTCCode | undefined;
1359
+ getPCItemByPCName(pcName: string): {
1360
+ /**
1361
+ * RCRTCPeerConnection 对象
1362
+ */
1363
+ pc: RCRTCPeerConnection;
1364
+ /**
1365
+ * 存放 peerConnection 上本次要发布、取消发布、订阅、取消订阅的 track
1366
+ */
1367
+ tracks: TrackParam[];
1368
+ /**
1369
+ * 当前 peerC 是否为发上行的 peerConnection
1370
+ */
1371
+ isPub: boolean;
1372
+ /**
1373
+ * peerConnection 上行资源,暂不需要
1374
+ */
1375
+ publishList?: IPublishedResource[] | undefined;
1376
+ /**
1377
+ * peerConnection 下行资源,暂不需要
1378
+ */
1379
+ subscribeList?: ISubscribeAttr[] | undefined;
1380
+ };
1305
1381
  /**
1306
- * @description 信令数据处理
1307
- * @param roomId 数据对应的房间 Id
1308
- * @param singalData 拉取到的数据
1309
- * * key RC_ANCHOR_LIST value: 为主播 ID 集合
1310
- * * key RC_RES_`userId` value: 为主播发布的资源
1311
- * * key RC_RTC_SESSIONID value: sessionId
1312
- * * key RC_CDN value: CDN 资源数据
1382
+ * 根据 trackId 获取 peerConnection 对象
1313
1383
  */
1314
- private singalDataChange;
1384
+ getPCByTrackId(trackId: string, isPub?: boolean): RCRTCPeerConnection;
1315
1385
  /**
1316
- * 计算加入离开的主播 ID 列表
1386
+ * 获取所有的 peerConnection
1317
1387
  */
1318
- private _diffAnchorList;
1319
- private _handleNewJoinedAnchor;
1320
- private _handleLeftedAnchor;
1388
+ getPCList(): RCRTCPeerConnection[];
1321
1389
  /**
1322
- * 计算新发布和取消发布的合流资源
1390
+ * 获取存储的多 peerConnection 数据
1323
1391
  */
1324
- private _diffRoomResource;
1325
- /**
1326
- * 计算主播发布和取消发布的资源,以及资源的状态变更
1327
- */
1328
- private _diffAnchorResource;
1329
- private _onUserUnpublish;
1330
- private _callAppListener;
1392
+ getMutilPeerCData(): {
1393
+ [key: string]: {
1394
+ /**
1395
+ * RCRTCPeerConnection 对象
1396
+ */
1397
+ pc: RCRTCPeerConnection;
1398
+ /**
1399
+ * 存放 peerConnection 上本次要发布、取消发布、订阅、取消订阅的 track
1400
+ */
1401
+ tracks: TrackParam[];
1402
+ /**
1403
+ * 当前 peerC 是否为发上行的 peerConnection
1404
+ */
1405
+ isPub: boolean;
1406
+ /**
1407
+ * peerConnection 上行资源,暂不需要
1408
+ */
1409
+ publishList?: IPublishedResource[] | undefined;
1410
+ /**
1411
+ * peerConnection 下行资源,暂不需要
1412
+ */
1413
+ subscribeList?: ISubscribeAttr[] | undefined;
1414
+ };
1415
+ };
1416
+ setPeerCData(pcName: string, key: string, value: any): void;
1331
1417
  /**
1332
- * ice 断线后,尝试重新走 exchange
1333
- */
1334
- private _reTryExchange;
1418
+ * 销毁资源
1419
+ */
1420
+ clear(): void;
1421
+ }
1422
+
1423
+ declare abstract class ReadableStore {
1424
+ readonly context: RTCPluginContext;
1425
+ readonly service: RCMediaService;
1426
+ readonly peerMgr: RCRTCPeerCManager;
1427
+ readonly roomId: string;
1428
+ readonly crtUserId: string;
1429
+ readonly roomMode: RTCMode;
1430
+ readonly polarisReport: PolarisReporter;
1431
+ readonly isUpgrade?: boolean | undefined;
1432
+ readonly isMainRoom?: boolean | undefined;
1335
1433
  /**
1336
- * 获取 subscribe 接口的请求体数据
1337
- * @param subscribeList 订阅清单
1338
- * @param publishedStreams 已发布流
1339
- * @param iceRestart
1434
+ * 房间资源数据
1340
1435
  */
1341
- protected _createSubscribeParams(subscribeList: ISubscribeAttr[], publishedStreams: {
1342
- [msid: string]: RCLocalMediaStream;
1343
- }, iceRestart: boolean): Promise<{
1344
- reqBody: IBroadcastSubReqBody;
1345
- offer: RTCSessionDescriptionInit;
1346
- dynamicBitrate: {
1347
- min: number;
1348
- max: number;
1349
- };
1350
- }>;
1351
- private _subscribeHandle;
1436
+ protected _roomResources: RoomData;
1352
1437
  /**
1353
- * 添加 peerConnection 事件
1438
+ * 远端 track
1354
1439
  */
1355
- private _addPeerCEvent;
1356
- private _getReqHeaders;
1357
- private _exchangeHandle;
1358
- private _updateSubListHandle;
1440
+ protected _remoteTracks: {
1441
+ [trackId: string]: RCRemoteTrack;
1442
+ };
1359
1443
  /**
1360
- * 对比 cdn_uris 资源
1361
- * @param newCDNUris 新的 cdn_uris 数据
1444
+ * 已订阅参数
1362
1445
  */
1363
- private _diffCDNUris;
1446
+ protected readonly _subscribedList: ISubscribeAttr[];
1364
1447
  /**
1365
- * 获取 CDN 资源对应的拉流地址
1366
- * _CDNUris 无 url 时,说明未开启 CDN 推送
1367
- * @returns CDNPlayUrl
1448
+ * MediaServer 交互需要的 token 信息
1368
1449
  */
1369
- private _getCDNPlayUrl;
1450
+ protected _token: string;
1370
1451
  /**
1371
- * 获取 CDN 资源对应的拉流地址
1372
- * @returns CDNPlayUrl
1452
+ * 每次加入房间后都会改变
1373
1453
  */
1374
- getCDNPlayUrl(resolution?: RCResolution, fps?: RCFrameRate): Promise<{
1375
- code: RCRTCCode;
1376
- CDNPlayUrl?: string;
1377
- }>;
1454
+ protected _sessionId: string;
1378
1455
  /**
1379
- * 订阅资源
1380
- * @param tracks
1456
+ * cdn_uris 信令扩散数据
1381
1457
  */
1382
- subscribe(tracks: (RCRemoteTrack | ISubscribeAttr)[]): Promise<{
1383
- code: RCRTCCode;
1384
- failedList?: ISubscribeAttr[];
1385
- }>;
1386
- private __unsubscribe;
1458
+ protected _CDNUris: ICDNUris | null;
1459
+ protected _CDNEnable: boolean;
1460
+ protected _destroyed: boolean;
1461
+ constructor(context: RTCPluginContext, service: RCMediaService, peerMgr: RCRTCPeerCManager, roomId: string, crtUserId: string, roomMode: RTCMode, polarisReport: PolarisReporter, isUpgrade?: boolean | undefined, isMainRoom?: boolean | undefined);
1462
+ get useMutilPeerC(): boolean;
1463
+ getResourcesByUserId(userId: string): IPublishedResource[] | undefined;
1464
+ getRemoteTrack(trackId: string): RCRemoteTrack | undefined;
1465
+ getRemoteTracksByUserId(userId: string): RCRemoteTrack[];
1466
+ getRemoteTracks(): {
1467
+ [trackId: string]: RCRemoteTrack;
1468
+ };
1469
+ getSessionId(): string;
1470
+ getAllUserIds(): string[];
1471
+ getRemoteUserIds(): string[];
1472
+ getSubscribedList(): ISubscribeAttr[];
1473
+ getPublishedResourceByTrackId(trackId: string): IPublishedResource | undefined;
1474
+ getToken(): string;
1475
+ getLocalTrack(trackId: string): RCLocalTrack | null;
1476
+ getLocalTracks(): RCLocalTrack[];
1477
+ getTrackState(trackId: string): 0 | 1;
1478
+ getCDNEnable(): boolean;
1479
+ getCDNUris(): ICDNUris | null;
1480
+ }
1481
+ declare class Store extends ReadableStore {
1482
+ private _initRemoteTracks;
1483
+ initWithRoomData(data: IJoinRTCRoomData): void;
1484
+ assignRoomData(data: RoomData): void;
1485
+ setResourcesByUserId(userId: string, arr: IPublishedResource[]): void;
1486
+ removeRemoteTrack(trackId: string): void;
1487
+ removeResourcesByUserId(userId: string): void;
1488
+ addRemoteTrack(track: RCRemoteTrack): void;
1489
+ removeRemoteTracks(): void;
1490
+ setCDNEnabel(bool: boolean): void;
1491
+ setCDNUris(uris: ICDNUris | null): void;
1492
+ }
1493
+
1494
+ declare enum CommandPriority {
1495
+ LOW = 0,
1496
+ NORMAL = 1,
1497
+ HIGH = 2
1498
+ }
1499
+ /**
1500
+ * 命令基类
1501
+ */
1502
+ declare abstract class BaseCommand<RES, STORE = Store> {
1387
1503
  /**
1388
- * 取消订阅资源
1389
- * @param tracks
1504
+ * 执行指令
1505
+ * @param store
1390
1506
  */
1391
- unsubscribe(tracks: RCRemoteTrack[]): Promise<{
1392
- code: RCRTCCode;
1393
- failedList?: ISubscribeAttr[];
1394
- }>;
1507
+ abstract execute(store: STORE, invoker: BaseInvoker<STORE>): Promise<RES>;
1395
1508
  /**
1396
- * 退出房间并销毁当前房间实例,退出后该房间的所有方法将不可用
1509
+ * 获取指令优先级,必要时可 override 此函数
1397
1510
  */
1398
- __destroy(quitRoom: boolean): Promise<void>;
1511
+ get priority(): CommandPriority;
1512
+ }
1513
+
1514
+ declare class BaseInvoker<STORE> {
1399
1515
  /**
1400
- * 根据 trackId 获取房间内的远端资源
1401
- * @param trackId
1516
+ * 内存数据管理实例
1402
1517
  */
1403
- getRemoteTrack(trackId: string): RCRemoteTrack;
1518
+ protected readonly _store: STORE;
1404
1519
  /**
1405
- * 获取 _pc 实例
1520
+ * 命令终止时返回的错误码定义
1406
1521
  */
1407
- __getPC(): RCRTCPeerConnection[];
1522
+ private abortCode;
1523
+ constructor(
1408
1524
  /**
1409
- * TODO 待优化
1410
- * @param trackId
1525
+ * 内存数据管理实例
1411
1526
  */
1412
- getLocalTrack(trackId: string): RCRemoteTrack;
1527
+ _store: STORE,
1413
1528
  /**
1414
- * 断线重连后处理逻辑, SDK 内部处理调用
1529
+ * 命令终止时返回的错误码定义
1415
1530
  */
1416
- __onReconnected(): Promise<void>;
1531
+ abortCode: RCRTCCode);
1532
+ private _queue;
1533
+ private _busy;
1534
+ private _next;
1535
+ private _execute;
1536
+ push<R>(command: BaseCommand<R, STORE>): Promise<R>;
1537
+ private _isDestroyed;
1538
+ isDestroyed(): boolean;
1539
+ destroy(): void;
1540
+ }
1541
+ /**
1542
+ * 房间任务队列管理
1543
+ */
1544
+ declare class Invoker extends BaseInvoker<Store> {
1545
+ constructor(context: RTCPluginContext, service: RCMediaService, peerMrg: RCRTCPeerCManager, roomId: string, crtUserId: string, mode: RTCMode, reporter: PolarisReporter, isUpgrade?: boolean, isMainRoom?: boolean);
1417
1546
  /**
1418
- * 观众房间事件注册
1419
- * @param tag 参数描述
1547
+ * 获取 store 存储实例,返回值类型 `ReadableStore`,避免非 command 定义中修改内存
1420
1548
  */
1421
- registerRoomEventListener(listener: IAudienceRoomEventListener | null): void;
1549
+ get store(): ReadableStore;
1550
+ destroy(): void;
1551
+ }
1552
+
1553
+ declare type ExchangeHooksRes = {
1554
+ headers: IRTCReqHeader;
1555
+ pushOtherRooms: IPushOtherRooms[];
1556
+ };
1557
+ declare type ExchangeHooks = (pcName: string) => ExchangeHooksRes;
1558
+
1559
+ declare type IOnRecvPKMsg = (msg: IReceivedMessage) => void;
1560
+ interface IRoomPKEventListener {
1422
1561
  /**
1423
- * 音量上报
1424
- * @param handler 业务端传入的音量上报事件
1425
- * @param gap 上报时间间隔
1562
+ * 收到连麦邀请
1426
1563
  */
1427
- onAudioLevelChange(handler: IAudioLevelChangeHandler | null, gap?: number): void;
1428
- private _reportListener;
1564
+ onRequestJoinOtherRoom: (info: IPKInviteInfo) => {};
1429
1565
  /**
1430
- * 注册房间数据监控
1431
- * @param listener
1566
+ * 收到取消连麦邀请
1432
1567
  */
1433
- registerReportListener(listener: IRCRTCReportListener | null): void;
1568
+ onCancelRequestOtherRoom: (info: IPKInviteInfo) => {};
1434
1569
  /**
1435
- * 获取房间 Id
1570
+ * 收到连麦 PK 请求响应结果
1436
1571
  */
1437
- getRoomId(): string;
1572
+ onResponseJoinOtherRoom: (info: IPKInviteAnswerInfo) => {};
1438
1573
  /**
1439
- * 获取当前 userId
1574
+ * 收到 PK 结束
1440
1575
  */
1441
- getCrtUserId(): string;
1576
+ onFinishOtherRoom: (info: IPKEndInfo) => {};
1577
+ }
1578
+ declare class RCLivingPKHandler {
1579
+ private _invoker;
1580
+ private _PKInfo;
1581
+ private _hooks;
1582
+ private readonly _context;
1583
+ private readonly _runtime;
1584
+ private readonly _service;
1585
+ private readonly _initOptions;
1442
1586
  /**
1443
- * 获取房间当前会话 Id,当房间内已无成员时房间会回收,重新加入时 sessionId 将更新
1587
+ * 主直播房间
1444
1588
  */
1445
- getSessionId(): string;
1589
+ private readonly _mainLivingRoom;
1590
+ private readonly _registerPKMsgListener;
1446
1591
  /**
1447
- * 获取远程主播用户列表
1592
+ * 加入 PK 房间回调
1448
1593
  */
1449
- getRemoteUserIds(): string[];
1594
+ private readonly _onJoinedPKRoom;
1595
+ protected readonly _clientSessionId?: string | undefined;
1450
1596
  /**
1451
- * 获取远端用户的资源列表
1452
- * @param userId
1453
- * @returns
1597
+ * PK 邀请超时时间,默认 30s
1454
1598
  */
1455
- getRemoteTracksByUserId(userId: string): RCRemoteTrack[];
1599
+ private readonly _inviteTimeout;
1600
+ private _appListener;
1601
+ private _mainRoomId;
1456
1602
  /**
1457
- * 获取房间内所有已发布的远端资源列表, 包含合流资源
1458
- * @returns
1603
+ * 跨房间连麦加入的 PK 房间
1459
1604
  */
1460
- getRemoteTracks(): RCRemoteTrack[];
1605
+ private _joinedPKRooms;
1606
+ constructor(_invoker: Invoker, _PKInfo: IPKInfo, _hooks: ExchangeHooks, _context: RTCPluginContext, _runtime: IRuntime, _service: RCMediaService, _initOptions: IRCRTCInitOptions,
1461
1607
  /**
1462
- * 获取远端 RTC tracks
1608
+ * 主直播房间
1463
1609
  */
1464
- getRemoteRTCTracks(): RCRemoteTrack[];
1610
+ _mainLivingRoom: RCLivingRoom, _registerPKMsgListener: (listener: IOnRecvPKMsg) => void,
1465
1611
  /**
1466
- * 获取远端 MCU tracks
1612
+ * 加入 PK 房间回调
1467
1613
  */
1468
- getRemoteMCUTracks(): RCRemoteTrack[];
1614
+ _onJoinedPKRoom: (roomId: string, room: RCLivingRoom) => void, _clientSessionId?: string | undefined);
1615
+ private _callAppListener;
1469
1616
  /**
1470
- * 获取房间内 CDN 信息
1617
+ * 收到连麦邀请
1471
1618
  */
1472
- getCDNInfo(): {
1473
- resolution: RCResolution;
1474
- fps: RCFrameRate;
1475
- CDNEnable: boolean | undefined;
1476
- } | {
1477
- CDNEnable: boolean;
1478
- resolution?: undefined;
1479
- fps?: undefined;
1480
- };
1481
- getClientSessionId(): string | undefined;
1482
- }
1483
-
1484
- /**
1485
- * 北极星上报角色
1486
- */
1487
- declare enum PolarisRole {
1619
+ private _onInvite;
1488
1620
  /**
1489
- * 会议参会者、主播
1621
+ * 收到取消连麦
1490
1622
  */
1491
- MeetingOrAnchor = 1,
1623
+ private _onCancelInvite;
1624
+ private _onInviteTimeout;
1492
1625
  /**
1493
- * 观众
1626
+ * 收到响应连麦
1494
1627
  */
1495
- Audience = 2
1496
- }
1497
-
1498
- declare class PolarisReporter {
1499
- private readonly _context;
1500
- private readonly _runtime;
1501
- private readonly _roomId;
1502
- private readonly _crtRTCRoom;
1503
- private readonly _userRole;
1504
- constructor(_context: RTCPluginContext, _runtime: IRuntime, _roomId: string, _crtRTCRoom: RCAbstractRoom | RCAudienceLivingRoom, _userRole?: PolarisRole);
1505
- private _send;
1506
- private _getClientID;
1628
+ private _onInviteAnswer;
1629
+ private createLeaveOtherRoomCommand;
1507
1630
  /**
1508
- * 小流需去掉 _tiny,小流 resourceId 为 userId_tag_mediaType_tiny
1631
+ * 收到连麦结束
1509
1632
  */
1510
- private _getRealResourceId;
1633
+ private _onPKEnd;
1511
1634
  /**
1512
- * 生成北极星上报的 trackId
1513
- * @param resourceId userId_11_1_tiny 改为 userId_11_tiny_video
1635
+ * 处理跨房间连麦相关消息
1514
1636
  */
1515
- private _getPolarisTrackId;
1516
- sendR3R4Data(data: IInnerRCRTCStateReport): Promise<boolean>;
1637
+ private _onRecvPKMsg;
1517
1638
  /**
1518
- * 加入房间
1639
+ * 注册跨房间连麦监听事件
1519
1640
  */
1520
- sendR1(): void;
1641
+ registerRoomPKEventListener(listener: IRoomPKEventListener): void;
1521
1642
  /**
1522
- * RTC 和 LIVE 发布、取消发布
1523
- * RTC 订阅、取消订阅
1643
+ * 发起跨房间连麦请求
1644
+ * @param inviteeRoomId 被邀请者所处的房间 roomId
1645
+ * @param inviteeUserId 被邀请者 userId
1646
+ * @param options.autoMix 是否要把邀请者发布的资源,合并到被邀请者房间内的 MCU 流中
1647
+ * @param options.extra 拓展字段,可随邀请连麦消息透传给被邀请者
1524
1648
  */
1525
- sendR2(action: string, status: string, trackIds: string[]): void;
1526
- }
1527
-
1528
- /**
1529
- * PC 实例管理类
1530
- */
1531
- declare class RCRTCPeerConnection extends EventEmitter {
1649
+ requestJoinOtherRoom(inviteeRoomId: string, inviteeUserId: string, options?: IReqResPKOptions): Promise<{
1650
+ code: RCRTCCode | ErrorCode;
1651
+ }>;
1532
1652
  /**
1533
- * peerConnection 对应名称
1534
- */
1535
- private readonly _pcName;
1653
+ * 取消跨房间连麦请求
1654
+ * @param inviteeRoomId 被邀请者所处的房间 roomId
1655
+ * @param inviteeUserId 被邀请者 userId
1656
+ * @param extra 附加信息,可随取消邀请连麦消息透传给被邀请者
1657
+ */
1658
+ cancelRequestJoinOtherRoom(inviteeRoomId: string, inviteeUserId: string, extra?: string): Promise<{
1659
+ code: RCRTCCode | ErrorCode;
1660
+ }>;
1536
1661
  /**
1537
- * _reTryExchange 方法
1662
+ * 响应跨房间连麦请求
1663
+ * @param inviterRoomId 邀请者所处的房间 roomId
1664
+ * @param inviterUserId 邀请者 userId
1665
+ * @param agree 是否同意连麦
1666
+ * @param options.autoMix 是否要把被邀请者发布的资源,合并到邀请者房间内的 MCU 流中
1667
+ * @param options.extra 附加信息,可随响应连麦消息透传给邀请者
1538
1668
  */
1539
- private readonly _reTryExchange;
1669
+ responseJoinOtherRoom(inviterRoomId: string, inviterUserId: string, agree: boolean, options?: IReqResPKOptions): Promise<{
1670
+ code: RCRTCCode | ErrorCode;
1671
+ }>;
1540
1672
  /**
1541
- * 北极星上传实例
1673
+ * 加入副直播房间
1674
+ * @roomId 副房间的 roomId
1542
1675
  */
1543
- private readonly _polarisReport?;
1544
- static __INNER_EVENT_TRACK_READY__: string;
1545
- private readonly _rtcPeerConn;
1546
- private readonly _sdpStrategy;
1547
- reportParser: IStatParser | null;
1548
- private pubLocalTracks;
1549
- private _reTryExchangeTimer;
1550
- private _reportStatsTimer;
1551
- private _reportR3R4ToPolarisTimer;
1552
- constructor(
1676
+ joinOtherRoom(roomId: string): Promise<{
1677
+ code: RCRTCCode;
1678
+ room?: RCLivingRoom;
1679
+ userIds?: string[];
1680
+ tracks?: RCRemoteTrack[];
1681
+ CDNEnable?: boolean;
1682
+ }>;
1553
1683
  /**
1554
- * peerConnection 对应名称
1555
- */
1556
- _pcName: string,
1684
+ * 退出副房间
1685
+ * @param room 要退出的副房间的 room 实例
1686
+ * @param isQuitPK 是否要结束连麦
1687
+ */
1688
+ leaveOtherRoom(room: RCLivingRoom, isQuitPK?: boolean): Promise<{
1689
+ code: RCRTCCode;
1690
+ }>;
1557
1691
  /**
1558
- * _reTryExchange 方法
1692
+ * 获取连麦信息
1693
+ * @param roomId 连麦房间的 roomId
1559
1694
  */
1560
- _reTryExchange: Function,
1695
+ getPKInfo(roomId: string): {
1696
+ inviteSessionId: string;
1697
+ inviterRoomId: string;
1698
+ inviterUserId: string;
1699
+ inviterUserAutoMix?: boolean | undefined;
1700
+ inviteeRoomId: string;
1701
+ inviteeUserAutoMix?: boolean | undefined;
1702
+ };
1561
1703
  /**
1562
- * 北极星上传实例
1704
+ * 获取所有连麦信息
1563
1705
  */
1564
- _polarisReport?: PolarisReporter | undefined);
1565
- getLocalTracks(): RCLocalTrack[];
1566
- private _onConnectionStateChange;
1567
- private _onICEConnectionStateChange;
1568
- private _onTrackReady;
1569
- setBitrate(max: number, min: number, start?: number): Promise<void>;
1570
- createOffer(iceRestart: boolean): Promise<IOfferInfo>;
1571
- setRemoteAnswer(answer: string): Promise<RCRTCCode>;
1572
- getLocalTrack(trackId: string): RCLocalTrack | null;
1573
- addLocalTrack(track: RCLocalTrack): void;
1574
- removeLocalTrackById(trackId: string): void;
1575
- removeAllLocalTrack(): void;
1576
- removeLocalTrack(track: RCLocalTrack): void;
1577
- private _updateRecvTransceiverMap;
1578
- updateSubRemoteTracks(remoteTracks: RCRemoteTrack[]): void;
1706
+ getAllPKInfo(): IPKInfo;
1579
1707
  /**
1580
- * 获取当前已发布视频流信息
1708
+ * 获取已加入的副房间
1581
1709
  */
1582
- getOutboundVideoInfo(): OutboundVideoInfo[];
1583
- private _onLocalTrackMuted;
1584
- private _onLocalTrackDestroied;
1585
- private _reportListener;
1710
+ getJoinedPKRooms(): {
1711
+ [roomId: string]: RCLivingRoom;
1712
+ };
1713
+ }
1714
+
1715
+ declare type ResourceMsgContent = {
1586
1716
  /**
1587
- * 注册连接数据监控,开启质量数据上报定时器
1588
- * @param listener
1717
+ * 旧版本兼容参数,当收到非 `RTCMessageName.TOTAL_CONTENT_RESOURCE` 时:
1718
+ * * ignore 值为 `true` 表示该消息由 signal server 向旧版本 RTCLib 提供的兼容消息,无需处理
1719
+ * * 否则认为该消息是由旧版本 RTCLib 主动发出的增量变更消息,需要处理
1589
1720
  */
1590
- registerReportListener(listener: IRCRTCReportListener | null): void;
1591
- private _createRCRTCStateReport;
1721
+ ignore?: boolean;
1592
1722
  /**
1593
- * 获取 peerConnection stats 数据并格式化
1594
- * @returns 返回格式化后的数据
1723
+ * 发布到房间内的资源列表,`RTCMessageName.TOTAL_CONTENT_RESOURCE` 消息携带全量数据,否则为增量数据
1595
1724
  */
1596
- private _getStatsData;
1597
- getAudioLevelReportData(): Promise<{
1598
- trackId: string;
1599
- audioLevel: number | null;
1600
- }[] | undefined>;
1725
+ uris: IPublishedResource[];
1726
+ cdn_uris?: ICDNUris[];
1727
+ };
1728
+
1729
+ /**
1730
+ * 房间抽象基类
1731
+ */
1732
+ declare abstract class RCAbstractRoom extends EventEmitter {
1733
+ protected readonly _context: RTCPluginContext;
1734
+ protected readonly _runtime: IRuntime;
1735
+ readonly _roomId: string;
1736
+ protected readonly _service: RCMediaService;
1737
+ protected readonly _initOptions: IRCRTCInitOptions;
1601
1738
  /**
1602
- * 通知用户质量数据、peerConnection 北极星数据上报
1603
- * @todo
1739
+ * 是否使用多 peerConnection
1604
1740
  */
1605
- private _reportHandle;
1741
+ protected readonly _useMutilPeerC?: boolean | undefined;
1742
+ protected readonly _clientSessionId: string;
1606
1743
  /**
1607
- * 北极星上报 R3、R4 数据
1744
+ * 房间保活 rtcPing
1608
1745
  */
1609
- private _sendR3R4Data;
1746
+ private _pinger;
1610
1747
  /**
1611
- * 2s 给北极星上报一次 R3、R4
1748
+ * 北极星上报实例
1612
1749
  */
1613
- __reportR3R4ToPolaris(): Promise<void>;
1614
- getRTCPeerConn(): RTCPeerConnection;
1615
- destroy(): void;
1616
- clearReTryExchangeTimer(): void;
1617
- }
1618
-
1619
- interface IRCTrackBitrate {
1750
+ protected _polarisReport: PolarisReporter | null;
1620
1751
  /**
1621
- * 最大码率
1752
+ * 音量上报实例
1622
1753
  */
1623
- max: number;
1754
+ private _audioLevelReport;
1624
1755
  /**
1625
- * 最小码率
1756
+ * peerConnection 管理类
1626
1757
  */
1627
- min: number;
1758
+ protected _peerCManager: RCRTCPeerCManager | null;
1759
+ protected readonly _invoker: Invoker;
1760
+ protected readonly _store: ReadableStore;
1761
+ constructor(_context: RTCPluginContext, _runtime: IRuntime, _roomId: string, _roomMode: RTCMode, _service: RCMediaService, _initOptions: IRCRTCInitOptions, isUpgrade?: boolean, isMainRoom?: boolean,
1628
1762
  /**
1629
- * 上行起始码率
1763
+ * 是否使用多 peerConnection
1630
1764
  */
1631
- start?: number;
1632
- }
1633
- /**
1634
- * MediaServer 返回的媒体资源数据
1635
- */
1636
- interface IResource {
1765
+ _useMutilPeerC?: boolean | undefined, _clientSessionId?: string);
1766
+ __innerInit(mode: RTCMode, joinType?: RTCJoinType, livingType?: RCLivingType, innerUserDatas?: IRTCUserData, outerUserDatas?: IRTCUserData): Promise<{
1767
+ code: RCRTCCode | ErrorCode;
1768
+ data?: IJoinRTCRoomData;
1769
+ }>;
1770
+ protected _initWithRoomData(offlineKickTime: number): void;
1771
+ private _handlePingResult;
1637
1772
  /**
1638
- * 媒体类型
1773
+ * 设置房间上行资源的总码率配置
1774
+ * @description
1775
+ * * 自 v5.1.0 版本开始,推荐使用 `RCLocalTrack.setBitrate` 对不同流分别指定码率。
1776
+ * * 该方法仅在 SDP `plan-b` 协议下(Chrome 92 与 Safari 11 之前的版本)有效。
1777
+ * @param max 音视频发送码率上限,不可小于 200 且不可小于 `min`
1778
+ * @param min 音视频发送码率下限,默认值为 1,且不可小于 1,不可大于 `max`
1779
+ * @param start 起始码率,默认为码率上限的 70%
1639
1780
  */
1640
- mediaType: RCMediaType.AUDIO_ONLY | RCMediaType.VIDEO_ONLY;
1781
+ setBitrate(max: number, min: number, start?: number): void;
1782
+ private _onTrackReady;
1783
+ protected _callAppListener(eventType: keyof IRoomEventListener, ...attrs: any[]): void;
1784
+ private _onTrackUnpublish;
1785
+ __parseInnerMessage(message: IReceivedMessage): boolean;
1641
1786
  /**
1642
- * MediaStream Id,基本为 `userId` 与 `tag` 以 `_` 拼接而来。该值无法直接作为资源的唯一性标识属性,
1643
- * 需与 mediaType 拼接使用
1787
+ * 被踢出房间通知
1788
+ * @param byServer
1789
+ * * 当值为 false 时,说明本端 rtcPing 超时
1790
+ * * 当值为 true 时,说明本端收到被踢出房间通知
1644
1791
  */
1645
- msid: string;
1792
+ private _kickoff;
1793
+ private _rtcpeerClosed;
1646
1794
  /**
1647
- * MediaServer 返回的资源地址
1648
- * @example 举例如下:
1649
- * `{"clusterId":"rtc-data-bdcbj.ronghub.com:80","serverId":"172.28.76.215:40080","resourceId":"13111111111_5vls_web_RongCloudRTC_1","connectionId":"AAYxMDAzNjgAFDEzMTExMTExMTExXzV2bHNfd2ViAAMzMzMA","ssrc":1716229921,"serviceProvider":"bdc","userTimestamp":1604994044706}`
1795
+ * 处理资源变更事件
1796
+ * @param content
1797
+ * @param messageType 消息类型
1798
+ * @param userId 消息发送者
1650
1799
  */
1651
- uri: string;
1800
+ protected _resourceHandle(content: ResourceMsgContent, messageType: RCRTCMessageType.PUBLISH | RCRTCMessageType.UNPUBLISH | RCRTCMessageType.MODIFY | RCRTCMessageType.TOTAL_CONTENT_RESOURCE, userId: string): Promise<void>;
1801
+ private _onTrackPublish;
1652
1802
  /**
1653
- * 资源特征,simulcast 代表这道流支持大小流
1654
- * @description 此参数存疑,MediaServer 似乎并未下发此字段,Web 端暂不启用
1655
- * @deprecated
1803
+ * 处理 `RCRTCMessageType.STATE` 消息
1804
+ * @param content
1656
1805
  */
1657
- features?: ['simulcast'] | [];
1658
- }
1659
- /**
1660
- * 向房间内发布的媒体数据
1661
- */
1662
- interface IPublishedResource extends IResource {
1806
+ private _stateHandle;
1663
1807
  /**
1664
- * 资源禁用/启用标识,用于向 signal 同步本端资源状态,1 为启用,0 为禁用
1808
+ * 获取房间 Id
1665
1809
  */
1666
- state: 0 | 1;
1810
+ getRoomId(): string;
1667
1811
  /**
1668
- * 资源标识,同标识的资源将视作同道流,标识不可重复
1812
+ * 获取当前 userId
1669
1813
  */
1670
- tag: string;
1671
- }
1672
- interface ISubscribeAttr {
1814
+ getCrtUserId(): string;
1673
1815
  /**
1674
- * 要订阅的音视轨数据 Id
1816
+ * 获取 _pc 实例
1675
1817
  */
1676
- track: RCRemoteTrack;
1818
+ __getPC(): RCRTCPeerConnection[];
1677
1819
  /**
1678
- * 订阅小流,默认为 `false`
1820
+ * 获取远程用户列表,不包含当前用户
1679
1821
  */
1680
- subTiny?: boolean;
1681
- }
1682
- /**
1683
- * 视频配置
1684
- */
1685
- interface IVideoProfile {
1822
+ getRemoteUserIds(): string[];
1686
1823
  /**
1687
- * 视频帧率
1824
+ * 获取所有房间已发布的远端资源列表
1825
+ * @returns
1688
1826
  */
1689
- frameRate: RCFrameRate;
1827
+ getRemoteTracks(): RCRemoteTrack[];
1690
1828
  /**
1691
- * 视频分辨率
1829
+ * 获取远端用户的资源列表
1830
+ * @param userId
1831
+ * @returns
1692
1832
  */
1693
- resolution: RCResolution;
1694
- }
1695
- /**
1696
- * 屏幕共享流配置
1697
- */
1698
- interface IScreenVideoProfile extends IVideoProfile {
1833
+ getRemoteTracksByUserId(userId: string): RCRemoteTrack[];
1699
1834
  /**
1700
- * Electron 平台下通过 `desktopCapturer.getSources` 获取到的 sourceId,在 Electron 环境下为必填项。
1701
- * @see `https://www.electronjs.org/docs/api/desktop-capturer`
1835
+ * 获取房间当前会话 Id,当房间内已无成员时房间会回收,重新加入时 sessionId 将更新
1702
1836
  */
1703
- chromeMediaSourceId?: string;
1704
- }
1705
- /**
1706
- * 待发布资源数据
1707
- */
1708
- interface IPublishAttrs {
1837
+ getSessionId(): string;
1709
1838
  /**
1710
- * 待发布的轨道数据
1839
+ * 向房间内发消息
1840
+ * @param name 消息名称
1841
+ * @param content 消息内容
1711
1842
  */
1712
- track: RCLocalTrack;
1843
+ sendMessage(name: string, content: any): Promise<{
1844
+ code: RCRTCCode;
1845
+ }>;
1713
1846
  /**
1714
- * 是否同时发布小流
1847
+ * 设置房间属性
1848
+ * @param key 属性名
1849
+ * @param value 属性值
1850
+ * @param message 是否在设置属性的时候携带消息内容,传空则不往房间中发送消息
1851
+ * @param isInner RTC 业务内部使用参数,用户忽略
1715
1852
  */
1716
- pubTiny?: boolean | IVideoProfile;
1717
- }
1718
- /**
1719
- * peerConnection 抛出给用户的 track 字段
1720
- */
1721
- interface IRCTrackStat {
1853
+ setRoomAttribute(key: string, value: string, message?: {
1854
+ name: string;
1855
+ content: string;
1856
+ }, isInner?: boolean): Promise<{
1857
+ code: RCRTCCode;
1858
+ }>;
1722
1859
  /**
1723
- * stat id
1724
- */
1725
- id?: string;
1860
+ * 删除房间属性
1861
+ * @param keys 待删除的属性名数组
1862
+ * @param message 是否在删除属性的时候携带消息内容,传空则不往房间中发送消息
1863
+ * @param isInner RTC 业务内部使用参数,用户忽略
1864
+ */
1865
+ deleteRoomAttributes(keys: string[], message?: {
1866
+ name: string;
1867
+ content: string;
1868
+ }, isInner?: boolean): Promise<{
1869
+ code: RCRTCCode;
1870
+ }>;
1726
1871
  /**
1727
- * 资源 Id
1872
+ * 获取房间属性
1873
+ * @param keys 要查询的属性名数组,当数组长度为空时,取所有已设置的 kv 值
1874
+ * @param isInner RTC 业务内部使用参数,用户忽略
1728
1875
  */
1729
- trackId: string;
1876
+ getRoomAttributes(keys?: string[], isInner?: boolean): Promise<{
1877
+ code: RCRTCCode;
1878
+ data?: KVString;
1879
+ }>;
1730
1880
  /**
1731
- * 资源类型
1881
+ * 设置当前用户属性(暂不开放)
1882
+ * @param key 属性名
1883
+ * @param value 属性值
1884
+ * @param message 是否在设置属性的时候携带消息内容,传空则不往房间中发送消息
1732
1885
  */
1733
- kind: 'audio' | 'video';
1886
+ private _setUserAttributeValue;
1734
1887
  /**
1735
- * 丢包率,有效值 `0` - `1`
1888
+ * 删除当前用户属性(暂不开放)
1889
+ * @param keys 待删除的属性名数组
1890
+ * @param message 是否在删除属性的时候携带消息内容,传空则不往房间中发送消息
1736
1891
  */
1737
- packetsLostRate: number | null;
1892
+ private _deleteUserAttributes;
1738
1893
  /**
1739
- * 是否是远端资源
1894
+ * 获取当前用户属性(暂不开放)
1895
+ * @param keys 要查询的属性名数组
1740
1896
  */
1741
- remoteResource: boolean;
1897
+ private _getUserAttributes;
1742
1898
  /**
1743
- * 音量
1899
+ * 查询房间是否已销毁
1744
1900
  */
1745
- audioLevel?: number | null;
1901
+ isDestroyed(): boolean;
1746
1902
  /**
1747
- * 视频高度
1903
+ * 退出并销毁当前房间实例,退出后该房间的所有方法将不可用
1748
1904
  */
1749
- frameHeight?: number | null;
1905
+ __destroy(quitRoom: boolean): Promise<void>;
1750
1906
  /**
1751
- * 视频宽度
1907
+ * 退出房间之前禁用所有远端资源,避免退出动作耗时过长,
1908
+ * 导致在未完全退出的过程中仍能听到房间内的声音问题
1752
1909
  */
1753
- frameWidth?: number | null;
1910
+ private _muteRemoteTracksBeforeQuit;
1911
+ private _leaveHandle;
1754
1912
  /**
1755
- * 视频帧率
1913
+ * 释放 PCManager 上的资源
1756
1914
  */
1757
- frameRate?: number | null;
1915
+ private _releasePCManager;
1916
+ private _onLocalTrackDestroied;
1758
1917
  /**
1759
- * 码率
1918
+ * 本端流状态修改,需通知房间内其他成员
1919
+ * @param localTrack
1760
1920
  */
1761
- bitrate: number;
1921
+ private _onLocalTrackMuted;
1762
1922
  /**
1763
- * 网络抖动,单位 ms
1764
- * @description 下行数据中,同道流中只有一个 track 会有值,另一轨道数据值为 `0`
1923
+ * 增量发布资源,若发布的资源 tag 及媒体类型重复,后者将覆盖前者进行发布。
1924
+ * @param tracks 待发布的 RCLocalTrack 实例
1925
+ * @returns
1765
1926
  */
1766
- jitter: number | null;
1767
- }
1768
- /**
1769
- * peerConnection 抛出给用户的 iceCandidatePair 字段
1770
- */
1771
- interface IRCCandidatePairStat {
1927
+ publish(tracks: (RCLocalTrack | IPublishAttrs)[]): Promise<IPubSuccessRes>;
1772
1928
  /**
1773
- * 本端 IP
1929
+ * 获取跨房间连麦需携带参数 pushOtherRooms 的值
1774
1930
  */
1775
- IP: string;
1931
+ protected _getPushOtherRoomsParams(): IPushOtherRooms[];
1776
1932
  /**
1777
- * 本地 UDP 端口
1933
+ * ice 断线后,尝试重新走 exchange
1778
1934
  */
1779
- port: number;
1935
+ protected _reTryExchange(pcName: string, isPub: boolean): Promise<void>;
1936
+ protected _getRTCReqestHeaders(pcName: string): IRTCReqHeader;
1780
1937
  /**
1781
- * 本地网络类型
1938
+ * 增量取消资源发布,若相应资源中存在小流资源,则同时取消发布
1939
+ * @param tracks 取消发布的 RCLocalTrack 列表
1782
1940
  */
1783
- networkType: string | null;
1941
+ unpublish(tracks: RCLocalTrack[]): Promise<IPubSuccessRes>;
1784
1942
  /**
1785
- * 远端 IP
1943
+ * 根据资源 Id 获取资源数据
1944
+ * @param trackId
1786
1945
  */
1787
- remoteIP: string;
1946
+ private _getResourceById;
1788
1947
  /**
1789
- * 远端 UDP 端口
1948
+ * resourceId 有效性验证
1949
+ * @param resourceId
1790
1950
  */
1791
- remotePort: number;
1951
+ protected _isValidResourceId(resourceId: string): boolean;
1952
+ private _subhook;
1953
+ private _pubhook;
1792
1954
  /**
1793
- * 协议
1955
+ * 订阅资源
1956
+ * @param tracks
1794
1957
  */
1795
- protocol: string;
1958
+ subscribe(tracks: (RCRemoteTrack | ISubscribeAttr)[]): Promise<{
1959
+ code: RCRTCCode;
1960
+ failedList?: ISubscribeAttr[];
1961
+ }>;
1796
1962
  /**
1797
- * 发送总码率,单位 kbps
1963
+ * 取消订阅资源
1964
+ * @param tracks 预取消远端资源
1798
1965
  */
1799
- bitrateSend: number;
1966
+ unsubscribe(tracks: RCRemoteTrack[]): Promise<{
1967
+ code: RCRTCCode;
1968
+ failedList?: ISubscribeAttr[];
1969
+ }>;
1800
1970
  /**
1801
- * 接收总码率,单位 kbps
1971
+ * 获取已发布的本地资源
1972
+ * @param trackId
1973
+ * @returns
1802
1974
  */
1803
- bitrateRecv: number;
1975
+ getLocalTrack(trackId: string): RCLocalTrack | null;
1804
1976
  /**
1805
- * (Round-Trip-Time)往返时延,单位 ms
1977
+ * 获取所有已发布的资源
1806
1978
  */
1807
- rtt: number | null;
1979
+ getLocalTracks(): RCLocalTrack[];
1808
1980
  /**
1809
- * 可用上行带宽,单位 bit
1981
+ * 根据 trackId 获取房间内的远端资源
1982
+ * @param trackId
1983
+ * @returns
1810
1984
  */
1811
- availableOutgoingBitrate: number | null;
1985
+ getRemoteTrack(trackId: string): RCRemoteTrack | null;
1812
1986
  /**
1813
- * 可用下行带宽,在无下行资源时,其值为 `0`,单位: `bit`
1987
+ * 强制修改订阅列表,仅订阅数组中的资源,取消订阅其他已订阅资源。
1988
+ * 当参数为 `[]` 时,意味着不再订阅任何资源
1989
+ * @param tracks 变更的资源列表
1814
1990
  */
1815
- availableIncomingBitrate: number | null;
1816
- }
1817
- /**
1818
- * iceCandidatePair 所有字段
1819
- * 含 peerConnection 抛出给用户的 iceCandidatePair 字段
1820
- * 含 北极星上报 R3、R4 所需的 totalPacketsLost
1821
- */
1822
- interface IInnerIcePair extends IRCCandidatePairStat {
1991
+ updateSubList(tracks: (RCRemoteTrack | ISubscribeAttr)[]): Promise<{
1992
+ code: RCRTCCode;
1993
+ failedList?: ISubscribeAttr[];
1994
+ }>;
1995
+ private _appListener;
1823
1996
  /**
1824
- * 上、下行总丢包率
1997
+ * 注册事件监听器,多次注册会导致后者覆盖前者,可以通过使用 `registerRoomEventListener(null)` 取消注册
1998
+ * @param listener
1825
1999
  */
1826
- totalPacketsLost?: number;
1827
- }
1828
- /**
1829
- * send track 所有字段
1830
- * 含 peerConnection 抛出给用户的 track 字段
1831
- * 含 北极星上报 R3 track 所需字段
1832
- */
1833
- interface ISendTrackState extends IRCTrackStat {
2000
+ registerRoomEventListener(listener: IRoomEventListener | null): void;
2001
+ private _reportListener;
1834
2002
  /**
1835
- * (Round-Trip-Time)往返时延,单位 ms
2003
+ * 注册房间数据监控
2004
+ * @param listener
2005
+ * @description 该方法暂仅支持 Chrome 浏览器
1836
2006
  */
1837
- rtt: number | null;
2007
+ registerReportListener(listener: IRCRTCReportListener | null): void;
1838
2008
  /**
1839
- * 编码方式
2009
+ * 音量上报
2010
+ * @param handler 业务端传入的音量上报事件
2011
+ * @param gap 上报时间间隔
1840
2012
  */
1841
- encoderImplementation: string | null;
2013
+ onAudioLevelChange(handler: IAudioLevelChangeHandler | null, gap?: number): void;
1842
2014
  /**
1843
- * PLI 请求数
2015
+ * 断线重连后尝试补发断线过程中的通知信息
1844
2016
  */
1845
- pliCount: number;
2017
+ __onReconnected(livingType?: RCLivingType): Promise<{
2018
+ data: IJoinRTCRoomData | undefined;
2019
+ } | void>;
2020
+ private _onAudioMuteChange;
2021
+ private _onVideoMuteChange;
1846
2022
  /**
1847
- * nack 数量
2023
+ * 存储连麦监听事件
1848
2024
  */
1849
- nackCount: number;
2025
+ private _onRecvPKMsg;
1850
2026
  /**
1851
- * 第一个关键帧是否正常收到
2027
+ * 注册 PK 业务监听方法
1852
2028
  */
1853
- googFirsSent: number;
2029
+ protected _registerPKMsgListener(listener: IOnRecvPKMsg | null): void;
1854
2030
  /**
1855
- * 音频采样率
2031
+ * 退出 PK 房间
1856
2032
  */
1857
- samplingRate: number;
2033
+ protected _quitAllPKRoom(): void;
2034
+ getClientSessionId(): string;
2035
+ }
2036
+
2037
+ declare class RCLocalMediaStream {
2038
+ readonly msid: string;
2039
+ readonly mediaStream: MediaStream;
2040
+ readonly tinyStream: MediaStream;
2041
+ readonly tag: string;
2042
+ constructor(msid: string);
2043
+ }
2044
+
2045
+ interface IAudienceRoomEventListener extends IRCRTCTrackEventListener {
1858
2046
  /**
1859
- * 接收卡顿(间隔时间, 单位: ms)
2047
+ * 主播加入
2048
+ * @param userIds 加入主播的 id 列表
1860
2049
  */
1861
- googRenderDelayMs: number;
2050
+ onAnchorJoin?(userId: string[]): void;
1862
2051
  /**
1863
- * 流状态(0:不可用, 1:可用)
2052
+ * 主播退出
2053
+ * @param userIds 退出主播的 id 列表
1864
2054
  */
1865
- trackState: TrackState;
1866
- }
1867
- /**
1868
- * receive track 所有字段
1869
- * 含 peerConnection 抛出给用户的 track 字段
1870
- * 含 北极星上报 R4 track 所需字段
1871
- */
1872
- interface IRecvTrackState extends IRCTrackStat {
2055
+ onAnchorLeave?(userId: string[]): void;
1873
2056
  /**
1874
- * 解码方式
2057
+ * 房间内合流发布资源
2058
+ * @param tracks 新发布的合流音轨与视轨数据列表,包含新发布的 RCRemoteAudioTrack 与 RCRemoteVideoTrack 实例
2059
+ * @description
2060
+ * 当房间内某个主播第一次发布资源时触发
1875
2061
  */
1876
- codecImplementationName: string | null;
1877
- samplingRate: number;
1878
- nackCount: number;
1879
- pliCount: number;
1880
- rtt: number | null;
1881
- googFirsReceived: number;
1882
- googRenderDelayMs: number;
1883
- trackState: TrackState;
1884
- }
1885
- /**
1886
- * peerConnection stats 解析出来业务所需的所有字段
1887
- */
1888
- interface IInnerRCRTCStateReport {
1889
- timestamp: number;
1890
- iceCandidatePair?: IInnerIcePair;
1891
- senders: ISendTrackState[];
1892
- receivers: IRecvTrackState[];
1893
- }
1894
- /**
1895
- * /**
1896
- * peerConnection stats 抛给用户的字段
1897
- */
1898
- interface IRCRTCStateReport {
1899
- pcName?: string;
2062
+ onTrackPublish?(tracks: RCRemoteTrack[]): void;
1900
2063
  /**
1901
- * 报告生成时间戳
2064
+ * 房间内取消合流发布资源
2065
+ * @param tracks 被取消发布的合流音轨与视轨数据列表
2066
+ * @description
2067
+ * 当房间内全部主播退出房间时,SDK 内部会取消对资源的订阅,业务层仅需处理 UI 业务
1902
2068
  */
1903
- timestamp: number;
2069
+ onTrackUnpublish?(tracks: RCRemoteTrack[]): void;
1904
2070
  /**
1905
- * 对等连接状态数据
2071
+ * 房间内主播发布资源
2072
+ * @param tracks 主播新发布的音轨与视轨数据列表,包含新发布的 RCRemoteAudioTrack 与 RCRemoteVideoTrack 实例
1906
2073
  */
1907
- iceCandidatePair?: IRCCandidatePairStat;
2074
+ onAnchorTrackPublish?(tracks: RCRemoteTrack[]): void;
1908
2075
  /**
1909
- * 上行状态数据
2076
+ * 房间内主播取消发布资源
2077
+ * @param tracks 被主播取消发布的音轨与视轨数据列表
2078
+ * @description 当资源被取消发布时,SDK 内部会取消对相关资源的订阅,业务层仅需处理 UI 业务
1910
2079
  */
1911
- senders: IRCTrackStat[];
2080
+ onAnchorTrackUnpublish?(tracks: RCRemoteTrack[]): void;
1912
2081
  /**
1913
- * 下行状态数据
2082
+ * 房间主播禁用/启用音频
2083
+ * @param audioTrack RCRemoteAudioTrack 类实例
1914
2084
  */
1915
- receivers: IRCTrackStat[];
1916
- }
1917
- interface IRCRTCReportListener {
2085
+ onAudioMuteChange?(audioTrack: RCRemoteAudioTrack): void;
1918
2086
  /**
1919
- * RTCPeerConnection 的详细状态数据
1920
- * @param report
2087
+ * 房间主播禁用/启用视频
2088
+ * @param videoTrack RCRemoteVideoTrack 类实例对象
2089
+ */
2090
+ onVideoMuteChange?(videoTrack: RCRemoteVideoTrack): void;
2091
+ /**
2092
+ * 房间内主播把发布的资源推至 CDN
1921
2093
  */
1922
- onStateReport?(report: IRCRTCStateReport): void;
2094
+ onCDNInfoEnable?(CDNInfo: {
2095
+ resolution: RCResolution;
2096
+ fps: RCFrameRate;
2097
+ }): void;
1923
2098
  /**
1924
- * ICE 连接状态变更通知
1925
- * @since version 5.1.5
2099
+ * 主播停止推 CDN
1926
2100
  */
1927
- onICEConnectionStateChange?(state: RTCIceConnectionState, pcName?: string): void;
2101
+ onCDNInfoDisable?(): void;
1928
2102
  /**
1929
- * @deprecated
2103
+ * 主播改变推 CDN 的分辨率或帧率
1930
2104
  */
1931
- onConnectionStateChange?(state: RTCPeerConnectionState, pcName?: string): void;
2105
+ onCDNInfoChange?(CDNInfo: {
2106
+ resolution: RCResolution;
2107
+ fps: RCFrameRate;
2108
+ }): void;
1932
2109
  }
1933
- interface IRCRTCTrackEventListener {
2110
+ /**
2111
+ * 观众直播房间类
2112
+ * 处理:
2113
+ * 1、通知观众房间内 人员变更、资源变更
2114
+ * 2、观众订阅、取消订阅资源
2115
+ */
2116
+ declare class RCAudienceLivingRoom {
2117
+ private readonly _context;
2118
+ private readonly _runtime;
2119
+ private readonly _initOptions;
2120
+ private readonly _roomId;
2121
+ private readonly _joinResData;
2122
+ readonly livingType: RCLivingType;
2123
+ private _useMutilPeerC?;
2124
+ protected readonly _clientSessionId: string;
2125
+ private readonly _service;
1934
2126
  /**
1935
- * 订阅的音视频流通道已建立, track 已可以进行播放
1936
- * @param track RCRemoteTrack 类实例
2127
+ * 主播列表
1937
2128
  */
1938
- onTrackReady?(track: RCRemoteTrack): void;
1939
- }
1940
- interface IRoomEventListener extends IRCRTCTrackEventListener {
2129
+ private _roomAnchorList;
1941
2130
  /**
1942
- * 当 RTCPeerConnection 连接被异常关闭时触发,此时需业务层重新加入房间并重新发布、订阅资源。
1943
- * 引起连接异常中断的原因包括但不限于:电脑休眠、浏览器页面长期后台运行等
1944
- * @since 5.1.5
2131
+ * 合流、分流资源
1945
2132
  */
1946
- onRTCPeerConnectionCloseByException?(): void;
2133
+ private _roomRes;
1947
2134
  /**
1948
- * 当本端被剔出房间时触发
1949
- * @description 被踢出房间可能是由于服务端超出一定时间未能收到 rtcPing 消息,所以认为己方离线。
1950
- * 另一种可能是己方 rtcPing 失败次数超出上限
1951
- * @param byServer 当值为 `false` 时,说明本端 rtcPing 超时;当值为 `true` 时,说明本端收到被踢出房间通知
2135
+ * 主播分流资源
1952
2136
  */
1953
- onKickOff?(byServer: boolean, state?: RCKickReason): void;
2137
+ private _roomAnchorRes;
1954
2138
  /**
1955
- * 接收到房间信令时回调,用户可通过房间实例的 sendMessage 接口发送信令
1956
- * @param name 信令名
1957
- * @param content 信令内容
1958
- * @param senderUserId 发送者 Id
1959
- * @param messageUId 消息唯一标识
2139
+ * 合流、分流 remoteTracks
1960
2140
  */
1961
- onMessageReceive?(name: string, content: any, senderUserId: string, messageUId: string): void;
2141
+ private _remoteTracks;
2142
+ private _appListener;
2143
+ private _pc;
2144
+ private _subscribedList;
2145
+ private _sessionId;
2146
+ private _destroyed;
1962
2147
  /**
1963
- * 房间属性变更回调
1964
- * @param name
1965
- * @param content
2148
+ * 北极星上报实例
1966
2149
  */
1967
- onRoomAttributeChange?(name: string, content?: string): void;
2150
+ protected _polarisReport: PolarisReporter | null;
1968
2151
  /**
1969
- * 房间用户禁用/启用音频
1970
- * @param audioTrack RCRemoteAudioTrack 类实例
2152
+ * 音量上报实例
1971
2153
  */
1972
- onAudioMuteChange?(audioTrack: RCRemoteAudioTrack): void;
2154
+ private _audioLevelReport;
1973
2155
  /**
1974
- * 房间用户禁用/启用视频
1975
- * @param videoTrack RCRemoteVideoTrack 类实例对象
2156
+ * cdn_uris 资源
1976
2157
  */
1977
- onVideoMuteChange?(videoTrack: RCRemoteVideoTrack): void;
2158
+ private _CDNUris;
1978
2159
  /**
1979
- * 房间内用户发布资源
1980
- * @param tracks 新发布的音轨与视轨数据列表,包含新发布的 RCRemoteAudioTrack 与 RCRemoteVideoTrack 实例
2160
+ * 使用的 peerConnection 对应 id
1981
2161
  */
1982
- onTrackPublish?(tracks: RCRemoteTrack[]): void;
2162
+ private _pcName;
1983
2163
  /**
1984
- * 房间用户取消发布资源
1985
- * @param tracks 被取消发布的音轨与视轨数据列表
1986
- * @description 当资源被取消发布时,SDK 内部会取消对相关资源的订阅,业务层仅需处理 UI 业务
2164
+ * peerConnection 管理类
2165
+ */
2166
+ private _peerCManager;
2167
+ constructor(_context: RTCPluginContext, _runtime: IRuntime, _initOptions: IRCRTCInitOptions, _roomId: string, _joinResData: {
2168
+ token: string;
2169
+ kvEntries: IServerRTCRoomEntry[];
2170
+ }, livingType: RCLivingType, _useMutilPeerC?: boolean | undefined, _clientSessionId?: string);
2171
+ /**
2172
+ * 解析服务端返回的 KV 数据,赋值 room 内数据
1987
2173
  */
1988
- onTrackUnpublish?(tracks: RCRemoteTrack[]): void;
2174
+ private _setInitData;
2175
+ protected _assertRoomDestroyed(): RCRTCCode | undefined;
1989
2176
  /**
1990
- * 人员加入
1991
- * @param userIds 加入的人员 id 列表
2177
+ * @description 信令数据处理
2178
+ * @param roomId 数据对应的房间 Id
2179
+ * @param singalData 拉取到的数据
2180
+ * * key RC_ANCHOR_LIST value: 为主播 ID 集合
2181
+ * * key RC_RES_`userId` value: 为主播发布的资源
2182
+ * * key RC_RTC_SESSIONID value: sessionId
2183
+ * * key RC_CDN value: CDN 资源数据
1992
2184
  */
1993
- onUserJoin?(userIds: string[]): void;
2185
+ private singalDataChange;
1994
2186
  /**
1995
- * 人员退出
1996
- * @param userIds
2187
+ * 计算加入离开的主播 ID 列表
1997
2188
  */
1998
- onUserLeave?(userIds: string[]): void;
2189
+ private _diffAnchorList;
2190
+ private _handleNewJoinedAnchor;
2191
+ private _handleLeftedAnchor;
1999
2192
  /**
2000
- * 主播开启、停止推 CDN 状态通知
2193
+ * 计算新发布和取消发布的合流资源
2001
2194
  */
2002
- onCDNEnableChange?(enable: boolean): void;
2195
+ private _diffRoomResource;
2003
2196
  /**
2004
- * RTC 每次 Ping 的结果
2005
- * @since version: 5.1.5
2197
+ * 计算主播发布和取消发布的资源,以及资源的状态变更
2198
+ */
2199
+ private _diffAnchorResource;
2200
+ private _onUserUnpublish;
2201
+ private _callAppListener;
2202
+ /**
2203
+ * ice 断线后,尝试重新走 exchange
2204
+ */
2205
+ private _reTryExchange;
2206
+ /**
2207
+ * 获取 subscribe 接口的请求体数据
2208
+ * @param subscribeList 订阅清单
2209
+ * @param publishedStreams 已发布流
2210
+ * @param iceRestart
2006
2211
  */
2007
- onPing?(result: RCRTCPingResult): void;
2212
+ protected _createSubscribeParams(subscribeList: ISubscribeAttr[], publishedStreams: {
2213
+ [msid: string]: RCLocalMediaStream;
2214
+ }, iceRestart: boolean): Promise<{
2215
+ reqBody: IBroadcastSubReqBody;
2216
+ offer: RTCSessionDescriptionInit;
2217
+ dynamicBitrate: {
2218
+ min: number;
2219
+ max: number;
2220
+ };
2221
+ }>;
2222
+ private _subscribeHandle;
2008
2223
  /**
2009
- * 主播和观众切换身份通知
2224
+ * 添加 peerConnection 事件
2010
2225
  */
2011
- onSwitchRole?(userId: string, role: RCRTCLiveRole): void;
2012
- }
2013
- /**
2014
- * RTCClient 初始化配置
2015
- * @public
2016
- */
2017
- interface IRCRTCInitOptions {
2226
+ private _addPeerCEvent;
2227
+ private _getReqHeaders;
2228
+ private _exchangeHandle;
2229
+ private _updateSubListHandle;
2018
2230
  /**
2019
- * 自定义 MediaServer Url,公有云用户无需关注
2020
- * @description
2021
- * 1. 仅当 `location.hostname` 为 `localhost` 时,`http` 协议地址有效,否则必须使用 `https` 协议地址
2022
- * 2. 当该值有效时,将不再从 IMLib 导航数据中获取 mediaServer 地址
2231
+ * 对比 cdn_uris 资源
2232
+ * @param newCDNUris 新的 cdn_uris 数据
2023
2233
  */
2024
- mediaServer?: string;
2234
+ private _diffCDNUris;
2025
2235
  /**
2026
- * 输出日志等级,生产环境默认使用 WARN,开发环境默认为 DEBUG
2027
- * @description
2028
- * * 0 - DEBUG
2029
- * * 1 - INFO
2030
- * * 2 - WARN
2031
- * * 3 - ERROR
2236
+ * 获取 CDN 资源对应的拉流地址
2237
+ * _CDNUris 无 url 时,说明未开启 CDN 推送
2238
+ * @returns CDNPlayUrl
2032
2239
  */
2033
- logLevel?: LogLevel;
2240
+ private _getCDNPlayUrl;
2034
2241
  /**
2035
- * 修改默认的 log 输出函数
2242
+ * 获取 CDN 资源对应的拉流地址
2243
+ * @returns CDNPlayUrl
2036
2244
  */
2037
- logStdout?: (logLevel: LogLevel, content: string) => void;
2245
+ getCDNPlayUrl(resolution?: RCResolution, fps?: RCFrameRate): Promise<{
2246
+ code: RCRTCCode;
2247
+ CDNPlayUrl?: string;
2248
+ }>;
2038
2249
  /**
2039
- * 与 MediaServer 的 http 请求超时时间,单位为毫秒,默认值为 `5000`,有效值 `5000-30000`。
2040
- * 优先级:用户配置 > 导航配置 > 默认时间。
2250
+ * 订阅资源
2251
+ * @param tracks
2041
2252
  */
2042
- timeout?: number;
2253
+ subscribe(tracks: (RCRemoteTrack | ISubscribeAttr)[]): Promise<{
2254
+ code: RCRTCCode;
2255
+ failedList?: ISubscribeAttr[];
2256
+ }>;
2257
+ private __unsubscribe;
2043
2258
  /**
2044
- * 房间 Ping 间隔时长,默认 `10000` ms,有效值 `3000`-`10000`
2259
+ * 取消订阅资源
2260
+ * @param tracks
2045
2261
  */
2046
- pingGap?: number;
2262
+ unsubscribe(tracks: RCRemoteTrack[]): Promise<{
2263
+ code: RCRTCCode;
2264
+ failedList?: ISubscribeAttr[];
2265
+ }>;
2047
2266
  /**
2048
- * 优化使用的 SDP 协议版本,仅当运行时浏览器支持相应 SDP 协议版本时生效
2267
+ * 退出房间并销毁当前房间实例,退出后该房间的所有方法将不可用
2049
2268
  */
2050
- sdpSemantics?: ISdpSemantics;
2269
+ __destroy(quitRoom: boolean): Promise<void>;
2051
2270
  /**
2052
- * 观众拉内置 CDN 资源的直播拉流协议,默认为 RCInnerCDNPullKind.FLV
2271
+ * 根据 trackId 获取房间内的远端资源
2272
+ * @param trackId
2053
2273
  */
2054
- pullInnerCDNProtocol?: RCInnerCDNPullKind;
2274
+ getRemoteTrack(trackId: string): RCRemoteTrack;
2055
2275
  /**
2056
- * 观众拉内置 CDN 资源时是否使用 https,默认为 RCInnerCDNPullIsHttps.HTTPS
2276
+ * 获取 _pc 实例
2057
2277
  */
2058
- pullInnerCDNUseHttps?: RCInnerCDNPullIsHttps;
2059
- }
2060
- interface ICameraVideoProfile extends IVideoProfile {
2061
- cameraId?: string;
2062
- faceMode?: 'user' | 'environment';
2063
- }
2064
- interface IMicphoneAudioProfile {
2065
- micphoneId?: string;
2066
- sampleRate?: number;
2067
- }
2068
- interface ICreateLocalTrackOptions {
2278
+ __getPC(): RCRTCPeerConnection[];
2069
2279
  /**
2070
- * 剔除音轨
2280
+ * TODO 待优化
2281
+ * @param trackId
2071
2282
  */
2072
- withoutAudio?: boolean;
2283
+ getLocalTrack(trackId: string): RCRemoteTrack;
2073
2284
  /**
2074
- * 剔除视轨
2285
+ * 断线重连后处理逻辑, SDK 内部处理调用
2075
2286
  */
2076
- withoutVideo?: boolean;
2077
- }
2078
- /**
2079
- * 音量上报事件接口
2080
- */
2081
- interface IAudioLevelChangeHandler {
2082
- (audioLevelReportList: {
2083
- track: RCLocalAudioTrack | RCRemoteAudioTrack;
2084
- audioLevel: number;
2085
- }[]): void;
2086
- }
2087
- /**
2088
- * 房间资源数据
2089
- */
2090
- declare type RoomData = {
2091
- [userId: string]: IPublishedResource[];
2092
- };
2093
- /**
2094
- * IMutilPeerC 中的 track 类型
2095
- */
2096
- declare type TrackParam = RCLocalTrack | IPublishAttrs | RCRemoteTrack | ISubscribeAttr;
2097
- /**
2098
- * RCRTCPeerCManager 创建的一条 pcItem 上的数据类型
2099
- */
2100
- interface IMutilPeerC {
2287
+ __onReconnected(): Promise<void>;
2101
2288
  /**
2102
- * pcName,/exchange 请求中 request header 中的 Peer-Connection-Id 值
2289
+ * 观众房间事件注册
2290
+ * @param tag 参数描述
2103
2291
  */
2104
- pcName: string;
2292
+ registerRoomEventListener(listener: IAudienceRoomEventListener | null): void;
2105
2293
  /**
2106
- * RCRTCPeerConnection 对象
2294
+ * 音量上报
2295
+ * @param handler 业务端传入的音量上报事件
2296
+ * @param gap 上报时间间隔
2107
2297
  */
2108
- pc: RCRTCPeerConnection;
2298
+ onAudioLevelChange(handler: IAudioLevelChangeHandler | null, gap?: number): void;
2299
+ private _reportListener;
2109
2300
  /**
2110
- * 存放 peerConnection 上本次要发布、取消发布、订阅、取消订阅的 track
2301
+ * 注册房间数据监控
2302
+ * @param listener
2111
2303
  */
2112
- tracks: TrackParam[];
2113
- }
2114
- interface IPKInfo {
2115
- [roomId: string]: {
2116
- inviteSessionId: string;
2117
- inviterRoomId: string;
2118
- inviterUserId: string;
2119
- inviterUserAutoMix?: boolean;
2120
- inviteeRoomId: string;
2121
- inviteeUserAutoMix?: boolean;
2122
- };
2123
- }
2124
- /**
2125
- * 业务层发起连麦、响应连麦可选参数定义
2126
- */
2127
- interface IReqResPKOptions {
2128
- autoMix?: boolean;
2129
- extra?: string;
2130
- }
2131
- interface IPKInviterBaseInfo {
2304
+ registerReportListener(listener: IRCRTCReportListener | null): void;
2132
2305
  /**
2133
- * 邀请者房间 ID
2306
+ * 获取房间 Id
2134
2307
  */
2135
- inviterRoomId: string;
2308
+ getRoomId(): string;
2136
2309
  /**
2137
- * 邀请者用户 ID
2310
+ * 获取当前 userId
2138
2311
  */
2139
- inviterUserId: string;
2140
- }
2141
- interface IPKInviteeBaseInfo {
2312
+ getCrtUserId(): string;
2142
2313
  /**
2143
- * 被邀请者房间 ID
2314
+ * 获取房间当前会话 Id,当房间内已无成员时房间会回收,重新加入时 sessionId 将更新
2144
2315
  */
2145
- inviteeRoomId: string;
2316
+ getSessionId(): string;
2146
2317
  /**
2147
- * 被邀请者用户 ID
2318
+ * 获取远程主播用户列表
2148
2319
  */
2149
- inviteeUserId: string;
2150
- }
2151
- /**
2152
- * 业务层监听收到连麦邀请、取消连麦的字段
2153
- */
2154
- interface IPKInviteInfo extends IPKInviterBaseInfo {
2320
+ getRemoteUserIds(): string[];
2155
2321
  /**
2156
- * 邀请额外信息
2322
+ * 获取远端用户的资源列表
2323
+ * @param userId
2324
+ * @returns
2157
2325
  */
2158
- extra?: string;
2159
- }
2160
- /**
2161
- * 业务层监听收到连麦应答的字段
2162
- */
2163
- interface IPKInviteAnswerInfo extends IPKInviterBaseInfo, IPKInviteeBaseInfo {
2326
+ getRemoteTracksByUserId(userId: string): RCRemoteTrack[];
2164
2327
  /**
2165
- * 是否同意邀请
2328
+ * 获取房间内所有已发布的远端资源列表, 包含合流资源
2329
+ * @returns
2166
2330
  */
2167
- agree: boolean;
2331
+ getRemoteTracks(): RCRemoteTrack[];
2168
2332
  /**
2169
- * 响应额外信息
2333
+ * 获取远端 RTC tracks
2170
2334
  */
2171
- extra?: string;
2172
- }
2173
- /**
2174
- * 业务层监听收到连麦结束的字段
2175
- */
2176
- interface IPKEndInfo {
2335
+ getRemoteRTCTracks(): RCRemoteTrack[];
2177
2336
  /**
2178
- * 发起结束的房间 ID
2337
+ * 获取远端 MCU tracks
2179
2338
  */
2180
- endRoomId: string;
2339
+ getRemoteMCUTracks(): RCRemoteTrack[];
2181
2340
  /**
2182
- * 发起结束的用户 ID
2341
+ * 获取房间内 CDN 信息
2183
2342
  */
2184
- endUserId: string;
2185
- }
2186
- /**
2187
- * 观众加房间返回给客户的 CDN 信息
2188
- */
2189
- interface IJoinResCDNInfo {
2190
- resolution?: RCResolution;
2191
- fps?: RCFrameRate;
2192
- CDNEnable?: boolean;
2193
- }
2194
-
2195
- declare enum RCInnerCDNPushMode {
2196
- AUTOMATIC = 0,
2197
- MANUAL = 1
2198
- }
2199
-
2200
- declare enum RCInnerCDNBroadcast {
2201
- SPREAD = 0,
2202
- NO_SPREAD = -1
2343
+ getCDNInfo(): {
2344
+ resolution: RCResolution;
2345
+ fps: RCFrameRate;
2346
+ CDNEnable: boolean | undefined;
2347
+ } | {
2348
+ CDNEnable: boolean;
2349
+ resolution?: undefined;
2350
+ fps?: undefined;
2351
+ };
2352
+ getClientSessionId(): string;
2203
2353
  }
2204
2354
 
2205
2355
  /**
2206
- * 与 MediaServer 交互所需的 Request Header 信息
2356
+ * 北极星上报角色
2207
2357
  */
2208
- interface IRTCReqHeader {
2209
- /**
2210
- * RTC Token
2211
- * @todo 有效期问题处理
2212
- */
2213
- Token: string;
2214
- /**
2215
- * 房间 Id
2216
- */
2217
- RoomId: string;
2358
+ declare enum PolarisRole {
2218
2359
  /**
2219
- * 用户 Id
2360
+ * 会议参会者、主播
2220
2361
  */
2221
- UserId: string;
2362
+ MeetingOrAnchor = 1,
2222
2363
  /**
2223
- * 仅在直播模式下需要
2364
+ * 观众
2224
2365
  */
2225
- RoomType?: RTCMode;
2366
+ Audience = 2
2367
+ }
2368
+
2369
+ declare class PolarisReporter {
2370
+ private readonly _context;
2371
+ private readonly _runtime;
2372
+ private readonly _roomId;
2373
+ private readonly _crtRTCRoom;
2374
+ private readonly _userRole;
2375
+ constructor(_context: RTCPluginContext, _runtime: IRuntime, _roomId: string, _crtRTCRoom: RCAbstractRoom | RCAudienceLivingRoom, _userRole?: PolarisRole);
2376
+ private _send;
2377
+ private _getClientID;
2226
2378
  /**
2227
- * 开发者的 AppKey
2379
+ * 小流需去掉 _tiny,小流 resourceId 为 userId_tag_mediaType_tiny
2228
2380
  */
2229
- 'App-Key': string;
2381
+ private _getRealResourceId;
2230
2382
  /**
2231
- * signal 会话 session id
2383
+ * 生成北极星上报的 trackId
2384
+ * @param resourceId userId_11_1_tiny 改为 userId_11_tiny_video
2232
2385
  */
2233
- 'Session-Id'?: string;
2386
+ private _getPolarisTrackId;
2387
+ sendR3R4Data(data: IInnerRCRTCStateReport): Promise<boolean>;
2234
2388
  /**
2235
- * peerConnection Id
2389
+ * 加入房间
2236
2390
  */
2237
- 'Peer-Connection-Id'?: string;
2391
+ sendR1(): void;
2238
2392
  /**
2239
- * client-session-id 标识一个端用户进入房间后的唯一标识
2393
+ * RTC 和 LIVE 发布、取消发布
2394
+ * RTC 订阅、取消订阅
2240
2395
  */
2241
- 'Client-Session-Id'?: string;
2242
- }
2243
- interface IMCUReqHeaders {
2244
- 'App-Key': string;
2245
- Token: string;
2246
- RoomId: string;
2247
- UserId: string;
2248
- SessionId: string;
2396
+ sendR2(action: string, status: string, trackIds: string[]): void;
2249
2397
  }
2398
+
2250
2399
  /**
2251
- * exchange 接口中 pushOtherRooms 字段接口
2400
+ * PC 实例管理类
2252
2401
  */
2253
- interface IPushOtherRooms {
2254
- /**
2255
- * 房间 Id
2256
- */
2257
- roomId: string;
2258
- /**
2259
- * 是否默认合流
2260
- */
2261
- autoMix: boolean;
2402
+ declare class RCRTCPeerConnection extends EventEmitter {
2262
2403
  /**
2263
- * 房间 Id 对应的 SessionId
2404
+ * peerConnection 对应名称
2264
2405
  */
2265
- sessionId: string;
2266
- }
2267
- /**
2268
- * exchange 接口的请求体结构
2269
- */
2270
- interface IExchangeReqBody {
2271
- /**
2272
- * local description
2273
- */
2274
- sdp: IOfferInfo;
2406
+ private readonly _pcName;
2275
2407
  /**
2276
- * 订阅列表
2408
+ * _reTryExchange 方法
2277
2409
  */
2278
- subscribeList: {
2279
- /**
2280
- * 流资源 uri
2281
- */
2282
- uri: string;
2283
- /**
2284
- * 大小流订阅,`1` 为大流,`2` 为小流,默认使用大流
2285
- */
2286
- simulcast: RCStreamType;
2287
- /**
2288
- * 分辨率信息
2289
- */
2290
- resolution: string;
2291
- }[];
2410
+ private readonly _reTryExchange;
2292
2411
  /**
2293
- * 透传参数,一般用于传递参数给其他服务,如 MCU/Record 等,MediaServer 仅透传不处理
2294
- * @example `{"resolutionInfo":[{"trackId":"021ad6e8-a50c-479c-96c8-5f3f09d2352d","simulcast":1,"resolution":"640x480"}]}`
2412
+ * 当前用户 id
2295
2413
  */
2296
- extend: string;
2414
+ private readonly _currentUserId;
2297
2415
  /**
2298
- * 跨房间连麦时其他房间的推流信息
2416
+ * 北极星上传实例
2299
2417
  */
2300
- pushOtherRooms?: IPushOtherRooms[];
2418
+ private readonly _polarisReport?;
2419
+ static __INNER_EVENT_TRACK_READY__: string;
2420
+ private readonly _rtcPeerConn;
2421
+ private readonly _sdpStrategy;
2422
+ reportParser: IStatParser | null;
2423
+ private pubLocalTracks;
2424
+ private _reTryExchangeTimer;
2425
+ private _reportStatsTimer;
2426
+ private _reportR3R4ToPolarisTimer;
2427
+ constructor(
2301
2428
  /**
2302
- * server 根据网络动态切换大小流开关,默认为 `false`
2303
- */
2304
- switchstream: boolean;
2305
- }
2306
- interface ILiveUrls {
2429
+ * peerConnection 对应名称
2430
+ */
2431
+ _pcName: string,
2307
2432
  /**
2308
- * MCU 服务地址,直播模式中用于向 MCU 服务提交 CDN 及合流配置
2433
+ * _reTryExchange 方法
2309
2434
  */
2310
- configUrl: string;
2435
+ _reTryExchange: Function,
2311
2436
  /**
2312
- * 观众端订阅地址,由业务层分发
2437
+ * 当前用户 id
2313
2438
  */
2314
- liveUrl: string;
2439
+ _currentUserId: string,
2315
2440
  /**
2316
- * 自动推 CDN 模式下,发布资源后返回的 CDN 信息
2441
+ * 北极星上传实例
2317
2442
  */
2318
- pull_url?: string;
2319
- }
2320
- interface IRTCResponse {
2443
+ _polarisReport?: PolarisReporter | undefined);
2444
+ getName(): string;
2445
+ getLocalTracks(): RCLocalTrack[];
2446
+ private _onConnectionStateChange;
2447
+ private _onICEConnectionStateChange;
2448
+ private _onTrackReady;
2449
+ setBitrate(max: number, min: number, start?: number): Promise<void>;
2450
+ createOffer(iceRestart: boolean): Promise<IOfferInfo>;
2451
+ setRemoteAnswer(answer: string): Promise<RCRTCCode>;
2452
+ getLocalTrack(trackId: string): RCLocalTrack | null;
2453
+ addLocalTrack(track: RCLocalTrack): void;
2454
+ removeLocalTrackById(trackId: string): void;
2455
+ removeAllLocalTrack(): void;
2456
+ removeLocalTrack(track: RCLocalTrack): void;
2457
+ private _updateRecvTransceiverMap;
2458
+ updateSubRemoteTracks(remoteTracks: RCRemoteTrack[]): void;
2321
2459
  /**
2322
- * 请求响应码,只有在 resultCode 值为 `10000` 时才为正常响应
2460
+ * 获取当前已发布视频流信息
2323
2461
  */
2324
- resultCode: RCRTCCode;
2325
- /**
2326
- * 与 resultCode 相应的可读性文字信息
2327
- */
2328
- message: string;
2462
+ getOutboundVideoInfo(): OutboundVideoInfo[];
2463
+ private _onLocalTrackMuted;
2464
+ private _onLocalTrackDestroied;
2465
+ private _reportListener;
2329
2466
  /**
2330
- * 客户端发送的 Request-Id
2467
+ * 注册连接数据监控,开启质量数据上报定时器
2468
+ * @param listener
2331
2469
  */
2332
- 'Request-Id': string;
2333
- }
2334
- /**
2335
- * /exchange 响应结果
2336
- */
2337
- interface IExchangeResponse extends IRTCResponse {
2470
+ registerReportListener(listener: IRCRTCReportListener | null): void;
2471
+ private _createRCRTCStateReport;
2338
2472
  /**
2339
- * 数据中心地址,当存在此值时,后续所有请求发送到该地址。该地址不携带协议头,故需要补全 `https://` 协议头
2473
+ * 获取 peerConnection stats 数据并格式化
2474
+ * @returns 返回格式化后的数据
2340
2475
  */
2341
- clusterId: string;
2476
+ private _getStatsData;
2477
+ getAudioLevelReportData(): Promise<{
2478
+ trackId: string;
2479
+ audioLevel: number | null;
2480
+ }[] | undefined>;
2342
2481
  /**
2343
- * 发布的资源列表
2482
+ * 通知用户质量数据、peerConnection 北极星数据上报
2483
+ * @todo
2344
2484
  */
2345
- publishList: IResource[];
2485
+ private _reportHandle;
2346
2486
  /**
2347
- * @deprecated 目前并未使用,服务器返回值为 ''
2487
+ * 北极星上报 R3、R4 数据
2348
2488
  */
2349
- roomId: '';
2489
+ private _sendR3R4Data;
2350
2490
  /**
2351
- * 远端 SDP 数据
2491
+ * 2s 给北极星上报一次 R3、R4
2352
2492
  */
2353
- sdp: {
2354
- type: 'answer';
2355
- sdp: string;
2356
- };
2493
+ __reportR3R4ToPolaris(): Promise<void>;
2494
+ getRTCPeerConn(): RTCPeerConnection;
2495
+ destroy(): void;
2496
+ clearReTryExchangeTimer(): void;
2497
+ }
2498
+
2499
+ interface IRCTrackBitrate {
2357
2500
  /**
2358
- * 直播模式推流数据,仅在直播模式有值
2501
+ * 最大码率
2359
2502
  */
2360
- urls?: ILiveUrls;
2503
+ max: number;
2361
2504
  /**
2362
- * 跨房间连麦响应数据
2505
+ * 最小码率
2363
2506
  */
2364
- otherRoomsRes?: {
2365
- [roomId: string]: ILiveUrls;
2366
- };
2507
+ min: number;
2367
2508
  /**
2368
- * 直播 mcu 资源
2369
- * 主播发布为具体资源,会议模式为空数组
2509
+ * 上行起始码率
2370
2510
  */
2371
- mcuPublishList?: IResource[];
2511
+ start?: number;
2512
+ }
2513
+ /**
2514
+ * MediaServer 返回的媒体资源数据
2515
+ */
2516
+ interface IResource {
2372
2517
  /**
2373
- * 订阅成功的资源
2518
+ * 媒体类型
2374
2519
  */
2375
- subscribedList?: {
2376
- mediaType: RCMediaType.AUDIO_ONLY | RCMediaType.VIDEO_ONLY;
2377
- msid: string;
2378
- userId: string;
2379
- simulcast?: RCStreamType;
2380
- }[];
2381
- }
2382
- interface IBroadcastSubReqBody {
2520
+ mediaType: RCMediaType.AUDIO_ONLY | RCMediaType.VIDEO_ONLY;
2383
2521
  /**
2384
- * 客户端 offer
2522
+ * MediaStream Id,基本为 `userId` 与 `tag` 以 `_` 拼接而来。该值无法直接作为资源的唯一性标识属性,
2523
+ * 需与 mediaType 拼接使用
2385
2524
  */
2386
- sdp: {
2387
- type: 'offer';
2388
- sdp: string;
2389
- };
2525
+ msid: string;
2390
2526
  /**
2391
- * 直播信息
2527
+ * MediaServer 返回的资源地址
2528
+ * @example 举例如下:
2529
+ * `{"clusterId":"rtc-data-bdcbj.ronghub.com:80","serverId":"172.28.76.215:40080","resourceId":"13111111111_5vls_web_RongCloudRTC_1","connectionId":"AAYxMDAzNjgAFDEzMTExMTExMTExXzV2bHNfd2ViAAMzMzMA","ssrc":1716229921,"serviceProvider":"bdc","userTimestamp":1604994044706}`
2392
2530
  */
2393
- liveUrl?: string;
2531
+ uri: string;
2394
2532
  /**
2395
- * 订阅的资源类型,默认为 `RCMediaType.AUDIO_VIDEO`
2533
+ * 资源特征,simulcast 代表这道流支持大小流
2534
+ * @description 此参数存疑,MediaServer 似乎并未下发此字段,Web 端暂不启用
2535
+ * @deprecated
2396
2536
  */
2397
- mediaType?: RCMediaType;
2537
+ features?: ['simulcast'] | [];
2538
+ }
2539
+ /**
2540
+ * 向房间内发布的媒体数据
2541
+ */
2542
+ interface IPublishedResource extends IResource {
2398
2543
  /**
2399
- * 订阅大/小流,默认订阅大流
2544
+ * 资源禁用/启用标识,用于向 signal 同步本端资源状态,1 为启用,0 为禁用
2400
2545
  */
2401
- simulcast?: RCStreamType;
2546
+ state: 0 | 1;
2402
2547
  /**
2403
- * 允许 server 根据网络状况动态切换大小流,默认为 false
2548
+ * 资源标识,同标识的资源将视作同道流,标识不可重复
2404
2549
  */
2405
- switchstream: boolean;
2550
+ tag: string;
2551
+ }
2552
+ interface ISubscribeAttr {
2406
2553
  /**
2407
- * 订阅列表
2554
+ * 要订阅的音视轨数据 Id
2408
2555
  */
2409
- subscribeList?: {
2410
- /**
2411
- * 流资源 uri
2412
- */
2413
- uri: string;
2414
- /**
2415
- * 大小流订阅,`1` 为大流,`2` 为小流,默认使用大流
2416
- */
2417
- simulcast: RCStreamType;
2418
- /**
2419
- * 分辨率信息
2420
- */
2421
- resolution: string;
2422
- }[];
2556
+ track: RCRemoteTrack;
2423
2557
  /**
2424
- * 是否采用新版本模式,加入房间
2558
+ * 订阅小流,默认为 `false`
2425
2559
  */
2426
- newVersionFlag?: boolean;
2560
+ subTiny?: boolean;
2427
2561
  }
2428
- interface IBroadcastSubRespBody extends IRTCResponse {
2562
+ /**
2563
+ * 视频配置
2564
+ */
2565
+ interface IVideoProfile {
2429
2566
  /**
2430
- * 已订阅的资源列表
2567
+ * 视频帧率
2431
2568
  */
2432
- subscribedList: IResource[];
2569
+ frameRate: RCFrameRate;
2433
2570
  /**
2434
- * 远端 SDP
2571
+ * 视频分辨率
2435
2572
  */
2436
- sdp: {
2437
- type: 'answer';
2438
- sdp: string;
2439
- };
2573
+ resolution: RCResolution;
2440
2574
  }
2441
2575
  /**
2442
- * 获取 CDN 资源拉流地址请求 headers
2576
+ * 屏幕共享流配置
2443
2577
  */
2444
- interface ICDNPlayUrlReqHeaders extends IMCUReqHeaders {
2578
+ interface IScreenVideoProfile extends IVideoProfile {
2579
+ /**
2580
+ * Electron 平台下通过 `desktopCapturer.getSources` 获取到的 sourceId,在 Electron 环境下为必填项。
2581
+ * @see `https://www.electronjs.org/docs/api/desktop-capturer`
2582
+ */
2583
+ chromeMediaSourceId?: string;
2445
2584
  }
2446
2585
  /**
2447
- * 获取 CDN 资源拉流地址响应
2586
+ * 待发布资源数据
2448
2587
  */
2449
- interface ICDNPlayUrlResponse extends IRTCResponse {
2450
- data: {
2451
- fps: number;
2452
- h: number;
2453
- 'pull_url': string;
2454
- w: number;
2455
- };
2588
+ interface IPublishAttrs {
2589
+ /**
2590
+ * 待发布的轨道数据
2591
+ */
2592
+ track: RCLocalTrack;
2593
+ /**
2594
+ * 是否同时发布小流
2595
+ */
2596
+ pubTiny?: boolean | IVideoProfile;
2456
2597
  }
2457
2598
  /**
2458
- * cdn_uris 里面包含的字段
2599
+ * peerConnection 抛出给用户的 track 字段
2459
2600
  */
2460
- interface ICDNUris {
2601
+ interface IRCTrackStat {
2461
2602
  /**
2462
- * 是否扩散
2603
+ * stat id
2604
+ */
2605
+ id?: string;
2606
+ /**
2607
+ * 资源 Id
2463
2608
  */
2464
- broadcast: RCInnerCDNBroadcast;
2609
+ trackId: string;
2465
2610
  /**
2466
- * 拉流资源的宽度
2611
+ * 资源类型
2467
2612
  */
2468
- w?: number;
2613
+ kind: 'audio' | 'video';
2469
2614
  /**
2470
- * 拉流资源的高度
2615
+ * 丢包率,有效值 `0` - `1`
2471
2616
  */
2472
- h?: number;
2617
+ packetsLostRate: number | null;
2473
2618
  /**
2474
- * 帧率
2475
- */
2476
- fps?: number;
2619
+ * 是否是远端资源
2620
+ */
2621
+ remoteResource: boolean;
2477
2622
  /**
2478
- * 获取拉流地址的 url
2623
+ * 音量
2479
2624
  */
2480
- url: string;
2625
+ audioLevel?: number | null;
2481
2626
  /**
2482
- * 开启、停用 CDN
2627
+ * 视频高度
2483
2628
  */
2484
- enableInnerCDN?: boolean;
2629
+ frameHeight?: number | null;
2485
2630
  /**
2486
- * 推送模式,手动 or 自动
2631
+ * 视频宽度
2487
2632
  */
2488
- 'push_mode': RCInnerCDNPushMode;
2489
- 'pull_safe': boolean;
2490
- }
2491
-
2492
- /**
2493
- * 直播布局模式定义
2494
- */
2495
- declare enum MixLayoutMode {
2633
+ frameWidth?: number | null;
2496
2634
  /**
2497
- * 自定义布局
2635
+ * 视频帧率
2498
2636
  */
2499
- CUSTOMIZE = 1,
2637
+ frameRate?: number | null;
2500
2638
  /**
2501
- * 悬浮布局(默认)
2639
+ * 码率
2502
2640
  */
2503
- SUSPENSION = 2,
2641
+ bitrate: number;
2504
2642
  /**
2505
- * 自适应布局
2643
+ * 网络抖动,单位 ms
2644
+ * @description 下行数据中,同道流中只有一个 track 会有值,另一轨道数据值为 `0`
2506
2645
  */
2507
- ADAPTATION = 3
2646
+ jitter: number | null;
2508
2647
  }
2509
-
2510
2648
  /**
2511
- * 合流布局对视频的填充模式
2649
+ * peerConnection 抛出给用户的 iceCandidatePair 字段
2512
2650
  */
2513
- declare enum MixVideoRenderMode {
2651
+ interface IRCCandidatePairStat {
2514
2652
  /**
2515
- * 裁剪(默认)
2653
+ * 本端 IP
2516
2654
  */
2517
- CROP = 1,
2655
+ IP: string;
2518
2656
  /**
2519
- * 不裁剪
2657
+ * 本地 UDP 端口
2520
2658
  */
2521
- WHOLE = 2
2522
- }
2523
-
2524
- declare enum RCInnerCDNModel {
2525
- OPEN = 1,
2526
- STOP = 2
2527
- }
2528
-
2529
- declare enum RCMixInputFilterMode {
2530
- /** 全合流,后续加入房间的用户会自动合流 */
2531
- AUDIO_VIDEO_ALL = 0,
2532
- /** 全不合流,后续加入本房间的用户 */
2533
- AUDIO_VIDEO_NO = 1,
2534
- /** 音频全订阅, 视频全不订阅 */
2535
- AUDIO_ALL_VIDEO_NO = 2,
2536
- /** 视频全订阅, 音频全不订阅 */
2537
- AUDIO_NO_VIDEO_ALL = 3,
2659
+ port: number;
2538
2660
  /**
2539
- * 根据设置的音频合流列表和视频合流列表合并媒体流
2661
+ * 本地网络类型
2540
2662
  */
2541
- AUDIO_VIDEO_INPUT = 4,
2542
- /** 音频全订阅,视频根据设置的视频合流列表 */
2543
- AUDIO_ALL_VIDEO_INPUT = 5,
2544
- /** 音频全不订阅, 视频根据input里面的视频项订阅 */
2545
- AUDIO_NO_VIDEO_INPUT = 6,
2546
- /** 视频全订阅, 音频根据input里面的音频项订阅 */
2547
- AUDIO_INPUT_VIDEO_ALL = 7,
2548
- /** 视频全不订阅, 音频根据input里面的音频项订阅 */
2549
- AUDIO_INPUT_VIDEO_NO = 8,
2550
- /** 按房间列表订阅音视频(保留当前已经订阅的, 但没在房间列表里的音视频) */
2551
- ROOM_AUDIO_VIDEO_APPEND = 9,
2552
- /** 按房间列表订阅音视频(清理当前已经订阅的, 但没在房间列表里的音视频) */
2553
- ROOM_AUDIO_VIDEO_NOT_APPEND = 10,
2554
- /** 按房间列表订阅音频, 不订阅视频(保留当前已经订阅的, 但没在房间列表里的音频) */
2555
- ROOM_AUDIO_APPEND = 11,
2556
- /** 按房间列表订阅音视, 不订阅视频(清理当前已经订阅的, 但没在房间列表里的音频) */
2557
- ROOM_AUDIO_NOT_APPEND = 12,
2558
- /** 按房间列表订阅视频, 不订阅音频(保留当前已经订阅的, 但没在房间列表里的视频) */
2559
- ROOM_VIDEO_APPEND = 13,
2560
- /** 按房间列表订阅视频, 不订阅音频(清理当前已经订阅的, 但没在房间列表里的视频) */
2561
- ROOM_VIDEO_NOT_APPEND = 14
2562
- }
2563
-
2564
- /**
2565
- * 合流后的 video 输出编码配置,包含分辨率、帧率、码率配置项
2566
- */
2567
- interface IMCUOutputVideoAttrs {
2663
+ networkType: string | null;
2568
2664
  /**
2569
- * 视频分辨率宽度
2665
+ * 远端 IP
2570
2666
  */
2571
- width?: number;
2667
+ remoteIP: string;
2572
2668
  /**
2573
- * 视频分辨率高度
2669
+ * 远端 UDP 端口
2574
2670
  */
2575
- height?: number;
2671
+ remotePort: number;
2576
2672
  /**
2577
- * 帧率
2673
+ * 协议
2578
2674
  */
2579
- fps?: number;
2675
+ protocol: string;
2580
2676
  /**
2581
- * 码率
2677
+ * 发送总码率,单位 kbps
2582
2678
  */
2583
- bitrate?: number;
2584
- }
2585
- /**
2586
- * 合并入 MCU 的音频流
2587
- */
2588
- interface IMCUInputAudio {
2589
- user_id: string;
2590
- stream_id: string;
2679
+ bitrateSend: number;
2680
+ /**
2681
+ * 接收总码率,单位 kbps
2682
+ */
2683
+ bitrateRecv: number;
2684
+ /**
2685
+ * (Round-Trip-Time)往返时延,单位 ms
2686
+ */
2687
+ rtt: number | null;
2688
+ /**
2689
+ * 可用上行带宽,单位 bit
2690
+ */
2691
+ availableOutgoingBitrate: number | null;
2692
+ /**
2693
+ * 可用下行带宽,在无下行资源时,其值为 `0`,单位: `bit`
2694
+ */
2695
+ availableIncomingBitrate: number | null;
2591
2696
  }
2592
2697
  /**
2593
- * 自定义布局中的单一视频流布局
2698
+ * iceCandidatePair 所有字段
2699
+ * 含 peerConnection 抛出给用户的 iceCandidatePair 字段
2700
+ * 含 北极星上报 R3、R4 所需的 totalPacketsLost
2594
2701
  */
2595
- interface IMCUInputVideoLayout {
2596
- user_id: string;
2597
- stream_id: string;
2598
- x: number;
2599
- y: number;
2600
- width: number;
2601
- height: number;
2702
+ interface IInnerIcePair extends IRCCandidatePairStat {
2703
+ /**
2704
+ * 上、下行总丢包率
2705
+ */
2706
+ totalPacketsLost?: number;
2602
2707
  }
2603
2708
  /**
2604
- * 图片配置,用于水印、视频流背景图
2709
+ * send track 所有字段
2710
+ * 含 peerConnection 抛出给用户的 track 字段
2711
+ * 含 北极星上报 R3 track 所需字段
2605
2712
  */
2606
- interface IPictureAttrs {
2607
- /**
2608
- * 资源下载地址,需包含协议
2609
- */
2610
- uri: string;
2713
+ interface ISendTrackState extends IRCTrackStat {
2611
2714
  /**
2612
- * 相对于整体画布的起始位置 x 坐标
2715
+ * (Round-Trip-Time)往返时延,单位 ms
2613
2716
  */
2614
- x: number;
2717
+ rtt: number | null;
2615
2718
  /**
2616
- * 相对于整体画布的起始位置 y 坐标
2719
+ * 编码方式
2617
2720
  */
2618
- y: number;
2721
+ encoderImplementation: string | null;
2619
2722
  /**
2620
- * 相对于整体画布的宽(百分比),有效值 `0.0` - `1.0`
2723
+ * PLI 请求数
2621
2724
  */
2622
- w: number;
2725
+ pliCount: number;
2623
2726
  /**
2624
- * 相对于整体画布的高(百分比),有效值 `0.0` - `1.0`
2727
+ * nack 数量
2625
2728
  */
2626
- h: number;
2627
- }
2628
- /**
2629
- * 合流后的 Video 输出配置,包含背景图、背景色、大小流编码等配置项
2630
- */
2631
- interface IMCUOutputVideoConfig {
2729
+ nackCount: number;
2632
2730
  /**
2633
- * 标准流输出定义
2731
+ * 第一个关键帧是否正常收到
2634
2732
  */
2635
- normal?: IMCUOutputVideoAttrs;
2733
+ googFirsSent: number;
2636
2734
  /**
2637
- * 小流输出定义
2735
+ * 音频采样率
2638
2736
  */
2639
- tiny?: IMCUOutputVideoAttrs;
2640
- exparams?: {
2641
- /**
2642
- * 合流布局时,对视频流的填充方式
2643
- */
2644
- renderMode: MixVideoRenderMode;
2645
- };
2737
+ samplingRate: number;
2646
2738
  /**
2647
- * 背景色,如 `'0xf1a2c3'`
2739
+ * 接收卡顿(间隔时间, 单位: ms)
2648
2740
  */
2649
- backgroundColor?: string;
2741
+ googRenderDelayMs: number;
2650
2742
  /**
2651
- * 背景图
2743
+ * 流状态(0:不可用, 1:可用)
2652
2744
  */
2653
- backgroundPicture?: {
2654
- /**
2655
- * 填充模式:
2656
- * 1. 按比例裁剪
2657
- * 2. 不裁剪,按比例压缩
2658
- */
2659
- fillMode: 1 | 2;
2660
- /**
2661
- * 资源列表
2662
- */
2663
- picture: IPictureAttrs[];
2664
- };
2745
+ trackState: TrackState;
2665
2746
  }
2666
2747
  /**
2667
- * 合流后的媒体输出定义
2748
+ * receive track 所有字段
2749
+ * 含 peerConnection 抛出给用户的 track 字段
2750
+ * 含 北极星上报 R4 track 所需字段
2668
2751
  */
2669
- interface IMCUOutputConfig {
2670
- /**
2671
- * 输出视频配置
2672
- */
2673
- video: IMCUOutputVideoConfig;
2674
- /**
2675
- * 输出音频配置
2676
- */
2677
- audio?: {
2678
- /**
2679
- * 音频码率
2680
- */
2681
- bitrate: number;
2682
- };
2752
+ interface IRecvTrackState extends IRCTrackStat {
2683
2753
  /**
2684
- * CDN 推流地址列表
2754
+ * 解码方式
2685
2755
  */
2686
- cdn?: {
2687
- /**
2688
- * 推流地址,如:`'rtmp://xxxx'`
2689
- */
2690
- pushurl: string;
2691
- }[];
2756
+ codecImplementationName: string | null;
2757
+ samplingRate: number;
2758
+ nackCount: number;
2759
+ pliCount: number;
2760
+ rtt: number | null;
2761
+ googFirsReceived: number;
2762
+ googRenderDelayMs: number;
2763
+ trackState: TrackState;
2692
2764
  }
2693
2765
  /**
2694
- * 时间戳参数,用于水印
2766
+ * peerConnection stats 解析出来业务所需的所有字段
2695
2767
  */
2696
- interface ITimestampAttrs {
2768
+ interface IInnerRCRTCStateReport {
2769
+ timestamp: number;
2770
+ iceCandidatePair?: IInnerIcePair;
2771
+ senders: ISendTrackState[];
2772
+ receivers: IRecvTrackState[];
2773
+ }
2774
+ /**
2775
+ * /**
2776
+ * peerConnection stats 抛给用户的字段
2777
+ */
2778
+ interface IRCRTCStateReport {
2779
+ pcName?: string;
2697
2780
  /**
2698
- * 时区
2781
+ * 报告生成时间戳
2699
2782
  */
2700
- timezone: number;
2783
+ timestamp: number;
2701
2784
  /**
2702
- * 字体像素大小
2785
+ * 对等连接状态数据
2703
2786
  */
2704
- fontSize: number;
2787
+ iceCandidatePair?: IRCCandidatePairStat;
2705
2788
  /**
2706
- * 字体颜色
2789
+ * 上行状态数据
2707
2790
  */
2708
- color: 'black' | 'white';
2791
+ senders: IRCTrackStat[];
2709
2792
  /**
2710
- * 透明度,有效值 `0.0` 至 `1.0`
2793
+ * 下行状态数据
2711
2794
  */
2712
- alpha: number;
2795
+ receivers: IRCTrackStat[];
2796
+ }
2797
+ interface IRCRTCReportListener {
2713
2798
  /**
2714
- * 相较于整体画布的 x 坐标(百分比),有效值 `0.0` 至 `1.0`
2799
+ * RTCPeerConnection 的详细状态数据
2800
+ * @param report
2715
2801
  */
2716
- x: number;
2802
+ onStateReport?(report: IRCRTCStateReport): void;
2717
2803
  /**
2718
- * 相较于整体画布的 y 坐标(百分比),有效值 `0.0` 至 `1.0`
2804
+ * ICE 连接状态变更通知
2805
+ * @since version 5.1.5
2719
2806
  */
2720
- y: number;
2807
+ onICEConnectionStateChange?(state: RTCIceConnectionState, pcName?: string): void;
2808
+ /**
2809
+ * @deprecated
2810
+ */
2811
+ onConnectionStateChange?(state: RTCPeerConnectionState, pcName?: string): void;
2721
2812
  }
2722
- /**
2723
- * 文本参数,用于水印
2724
- */
2725
- interface ITextAttrs {
2813
+ interface IRCRTCTrackEventListener {
2726
2814
  /**
2727
- * 文字内容
2815
+ * 订阅的音视频流通道已建立, track 已可以进行播放
2816
+ * @param track RCRemoteTrack 类实例
2728
2817
  */
2729
- content: string;
2818
+ onTrackReady?(track: RCRemoteTrack): void;
2819
+ }
2820
+ interface IRoomEventListener extends IRCRTCTrackEventListener {
2730
2821
  /**
2731
- * 文字像素
2822
+ * 当 RTCPeerConnection 连接被异常关闭时触发,此时需业务层重新加入房间并重新发布、订阅资源。
2823
+ * 引起连接异常中断的原因包括但不限于:电脑休眠、浏览器页面长期后台运行等
2824
+ * @since 5.1.5
2732
2825
  */
2733
- fontSize: number;
2826
+ onRTCPeerConnectionCloseByException?(): void;
2734
2827
  /**
2735
- * 文字颜色
2828
+ * 当本端被剔出房间时触发
2829
+ * @description 被踢出房间可能是由于服务端超出一定时间未能收到 rtcPing 消息,所以认为己方离线。
2830
+ * 另一种可能是己方 rtcPing 失败次数超出上限
2831
+ * @param byServer 当值为 `false` 时,说明本端 rtcPing 超时;当值为 `true` 时,说明本端收到被踢出房间通知
2736
2832
  */
2737
- color: 'black' | 'white';
2833
+ onKickOff?(byServer: boolean, state?: RCKickReason): void;
2738
2834
  /**
2739
- * 透明度,有效值 `0.0` 至 `1.0`
2835
+ * 接收到房间信令时回调,用户可通过房间实例的 sendMessage 接口发送信令
2836
+ * @param name 信令名
2837
+ * @param content 信令内容
2838
+ * @param senderUserId 发送者 Id
2839
+ * @param messageUId 消息唯一标识
2740
2840
  */
2741
- alpha: number;
2841
+ onMessageReceive?(name: string, content: any, senderUserId: string, messageUId: string): void;
2742
2842
  /**
2743
- * 相较于整体画布的 x 坐标(百分比),有效值 `0.0` 至 `1.0`
2843
+ * 房间属性变更回调
2844
+ * @param name
2845
+ * @param content
2744
2846
  */
2745
- x: number;
2847
+ onRoomAttributeChange?(name: string, content?: string): void;
2746
2848
  /**
2747
- * 相较于整体画布的 y 坐标(百分比),有效值 `0.0` 至 `1.0`
2849
+ * 房间用户禁用/启用音频
2850
+ * @param audioTrack RCRemoteAudioTrack 类实例
2748
2851
  */
2749
- y: number;
2750
- }
2751
- /**
2752
- * 屏幕水印配置
2753
- */
2754
- interface IWaterMarkConfig {
2852
+ onAudioMuteChange?(audioTrack: RCRemoteAudioTrack): void;
2755
2853
  /**
2756
- * 时间戳水印配置
2854
+ * 房间用户禁用/启用视频
2855
+ * @param videoTrack RCRemoteVideoTrack 类实例对象
2757
2856
  */
2758
- timestamp?: ITimestampAttrs;
2857
+ onVideoMuteChange?(videoTrack: RCRemoteVideoTrack): void;
2759
2858
  /**
2760
- * 图片水印配置
2859
+ * 房间内用户发布资源
2860
+ * @param tracks 新发布的音轨与视轨数据列表,包含新发布的 RCRemoteAudioTrack 与 RCRemoteVideoTrack 实例
2761
2861
  */
2762
- picture?: IPictureAttrs[];
2862
+ onTrackPublish?(tracks: RCRemoteTrack[]): void;
2763
2863
  /**
2764
- * 文字水印配置
2864
+ * 房间用户取消发布资源
2865
+ * @param tracks 被取消发布的音轨与视轨数据列表
2866
+ * @description 当资源被取消发布时,SDK 内部会取消对相关资源的订阅,业务层仅需处理 UI 业务
2765
2867
  */
2766
- text: ITextAttrs[];
2767
- }
2768
- /**
2769
- * 合流前的单一视频流水印配置
2770
- */
2771
- interface IMCUSignalScreenWaterMarkConfig extends IWaterMarkConfig {
2868
+ onTrackUnpublish?(tracks: RCRemoteTrack[]): void;
2772
2869
  /**
2773
- * 媒体流的 msid
2870
+ * 人员加入
2871
+ * @param userIds 加入的人员 id 列表
2774
2872
  */
2775
- streamId: string;
2776
- }
2777
- interface IMCUWaterMarkConfig {
2873
+ onUserJoin?(userIds: string[]): void;
2778
2874
  /**
2779
- * 合流后的屏幕水印配置
2875
+ * 人员退出
2876
+ * @param userIds
2780
2877
  */
2781
- mixScreen: IWaterMarkConfig;
2878
+ onUserLeave?(userIds: string[]): void;
2782
2879
  /**
2783
- * 合流前的单人视频流水印配置
2880
+ * 主播开启、停止推 CDN 状态通知
2784
2881
  */
2785
- signalScreen: IMCUSignalScreenWaterMarkConfig[];
2786
- }
2787
- /**
2788
- * 发布到服务器的 MCU 配置数据
2789
- */
2790
- interface IMCUConfig {
2882
+ onCDNEnableChange?(enable: boolean): void;
2791
2883
  /**
2792
- * 为向后兼容,当前为常量 1
2884
+ * RTC 每次 Ping 的结果
2885
+ * @since version: 5.1.5
2793
2886
  */
2794
- version: 1;
2887
+ onPing?(result: RCRTCPingResult): void;
2795
2888
  /**
2796
- * 布局模式,在只配置推流 CDN 时,该值不存在
2889
+ * 主播和观众切换身份通知
2797
2890
  */
2798
- mode: MixLayoutMode;
2891
+ onSwitchRole?(userId: string, role: RCRTCLiveRole): void;
2892
+ }
2893
+ /**
2894
+ * RTCClient 初始化配置
2895
+ * @public
2896
+ */
2897
+ interface IRCRTCInitOptions {
2799
2898
  /**
2800
- * 渲染到主位置上的流 Id,当该值为空时,输出到主位置的流按发布时间顺序优先选择最早发布的流
2899
+ * 自定义 MediaServer Url,公有云用户无需关注
2900
+ * @description
2901
+ * 1. 仅当 `location.hostname` 为 `localhost` 时,`http` 协议地址有效,否则必须使用 `https` 协议地址
2902
+ * 2. 当该值有效时,将不再从 IMLib 导航数据中获取 mediaServer 地址
2801
2903
  */
2802
- host_stream_id?: string;
2904
+ mediaServer?: string;
2803
2905
  /**
2804
- * 自定义布局输入定义,只有在 mode 值为 `MixLayoutMode.CUSTOMIZE` 时需传值
2906
+ * 输出日志等级,生产环境默认使用 WARN,开发环境默认为 DEBUG
2907
+ * @description
2908
+ * * 0 - DEBUG
2909
+ * * 1 - INFO
2910
+ * * 2 - WARN
2911
+ * * 3 - ERROR
2805
2912
  */
2806
- input?: {
2807
- video?: IMCUInputVideoLayout[];
2808
- audio?: IMCUInputAudio[];
2809
- };
2913
+ logLevel?: LogLevel;
2810
2914
  /**
2811
- * 合流后的媒体输出配置
2915
+ * 修改默认的 log 输出函数
2812
2916
  */
2813
- output?: IMCUOutputConfig;
2917
+ logStdout?: (logLevel: LogLevel, content: string) => void;
2814
2918
  /**
2815
- * 水印配置
2919
+ * 与 MediaServer 的 http 请求超时时间,单位为毫秒,默认值为 `5000`,有效值 `5000-30000`。
2920
+ * 优先级:用户配置 > 导航配置 > 默认时间。
2816
2921
  */
2817
- waterMark?: IMCUWaterMarkConfig;
2922
+ timeout?: number;
2818
2923
  /**
2819
- * MCU 拉流配置,决定 MCU MediaServer 拉流的方式
2924
+ * 房间 Ping 间隔时长,默认 `10000` ms,有效值 `3000`-`10000`
2820
2925
  */
2821
- inputFilterMode?: RCMixInputFilterMode;
2926
+ pingGap?: number;
2822
2927
  /**
2823
- * MCU 混入列表中房间内的资源
2928
+ * 优化使用的 SDP 协议版本,仅当运行时浏览器支持相应 SDP 协议版本时生效
2824
2929
  */
2825
- mixRooms?: string[];
2826
- }
2827
- /**
2828
- * 设置开启、停用内置 CDN 数据
2829
- */
2830
- interface ISetEnableCDN {
2831
- version: 2;
2832
- output: {
2833
- /**
2834
- * 手动开启/停用内置 CDN
2835
- */
2836
- inCDNModel: RCInnerCDNModel;
2837
- };
2838
- }
2839
-
2840
- declare class RCMediaService {
2841
- private readonly _runtime;
2842
- private readonly _context;
2930
+ sdpSemantics?: ISdpSemantics;
2843
2931
  /**
2844
- * 自定义 MediaServer 地址,当有值时,不再使用导航内的地址
2932
+ * 观众拉内置 CDN 资源的直播拉流协议,默认为 RCInnerCDNPullKind.FLV
2845
2933
  */
2846
- private readonly _msUrl?;
2934
+ pullInnerCDNProtocol?: RCInnerCDNPullKind;
2847
2935
  /**
2848
- * 请求超时时长
2936
+ * 观众拉内置 CDN 资源时是否使用 https,默认为 RCInnerCDNPullIsHttps.HTTPS
2849
2937
  */
2850
- private readonly _timeout;
2938
+ pullInnerCDNUseHttps?: RCInnerCDNPullIsHttps;
2939
+ }
2940
+ interface ICameraVideoProfile extends IVideoProfile {
2941
+ cameraId?: string;
2942
+ faceMode?: 'user' | 'environment';
2943
+ }
2944
+ interface IMicphoneAudioProfile {
2945
+ micphoneId?: string;
2946
+ sampleRate?: number;
2947
+ }
2948
+ interface ICreateLocalTrackOptions {
2851
2949
  /**
2852
- * navi 中获取的媒体服务地址
2950
+ * 剔除音轨
2853
2951
  */
2854
- private readonly _msInNavi;
2952
+ withoutAudio?: boolean;
2855
2953
  /**
2856
- * 已失败的请求地址
2954
+ * 剔除视轨
2857
2955
  */
2858
- private readonly _failedMs;
2956
+ withoutVideo?: boolean;
2957
+ }
2958
+ /**
2959
+ * 音量上报事件接口
2960
+ */
2961
+ interface IAudioLevelChangeHandler {
2962
+ (audioLevelReportList: {
2963
+ track: RCLocalAudioTrack | RCRemoteAudioTrack;
2964
+ audioLevel: number;
2965
+ }[]): void;
2966
+ }
2967
+ /**
2968
+ * 房间资源数据
2969
+ */
2970
+ declare type RoomData = {
2971
+ [userId: string]: IPublishedResource[];
2972
+ };
2973
+ /**
2974
+ * IMutilPeerC 中的 track 类型
2975
+ */
2976
+ declare type TrackParam = RCLocalTrack | IPublishAttrs | RCRemoteTrack | ISubscribeAttr;
2977
+ /**
2978
+ * RCRTCPeerCManager 创建的一条 pcItem 上的数据类型
2979
+ */
2980
+ interface IMutilPeerC {
2859
2981
  /**
2860
- * 服务器指纹数据,客户端不得修改,直接透传
2982
+ * pcName,/exchange 请求中 request header 中的 Peer-Connection-Id 值
2861
2983
  */
2862
- private _rtcFinger;
2984
+ pcName: string;
2863
2985
  /**
2864
- * 服务器接口返回的 clusterId 数据,当此数据有值时,后续所有请求向此服务发送
2986
+ * RCRTCPeerConnection 对象
2865
2987
  */
2866
- private _clusterId;
2988
+ pc: RCRTCPeerConnection;
2867
2989
  /**
2868
- * MCU 服务地址
2990
+ * 存放 peerConnection 上本次要发布、取消发布、订阅、取消订阅的 track
2869
2991
  */
2870
- private _configUrl;
2871
- constructor(_runtime: IRuntime, _context: RTCPluginContext,
2992
+ tracks: TrackParam[];
2993
+ }
2994
+ interface IPKInfo {
2995
+ [roomId: string]: {
2996
+ inviteSessionId: string;
2997
+ inviterRoomId: string;
2998
+ inviterUserId: string;
2999
+ inviterUserAutoMix?: boolean;
3000
+ inviteeRoomId: string;
3001
+ inviteeUserAutoMix?: boolean;
3002
+ };
3003
+ }
3004
+ /**
3005
+ * 业务层发起连麦、响应连麦可选参数定义
3006
+ */
3007
+ interface IReqResPKOptions {
3008
+ autoMix?: boolean;
3009
+ extra?: string;
3010
+ }
3011
+ interface IPKInviterBaseInfo {
2872
3012
  /**
2873
- * 自定义 MediaServer 地址,当有值时,不再使用导航内的地址
3013
+ * 邀请者房间 ID
2874
3014
  */
2875
- _msUrl?: string | undefined,
3015
+ inviterRoomId: string;
2876
3016
  /**
2877
- * 请求超时时长
3017
+ * 邀请者用户 ID
2878
3018
  */
2879
- _timeout?: number);
2880
- getNaviMS(): string[];
3019
+ inviterUserId: string;
3020
+ }
3021
+ interface IPKInviteeBaseInfo {
2881
3022
  /**
2882
- * 发送请求,请求发送若失败,会继续尝试使用后续可用地址直到无地址可用,此时认为请求失败
2883
- * @param path
2884
- * @param header
2885
- * @param body
3023
+ * 被邀请者房间 ID
2886
3024
  */
2887
- private _request;
3025
+ inviteeRoomId: string;
2888
3026
  /**
2889
- * 资源协商接口,订阅、发布、变更资源均可以使用此接口。该接口通过 sdp 字段交换 SDP 信息,
2890
- * 并通过 subscribeList 和 publishList 表明最终发布和订阅的资源。本端产出 offer,服务器产出 answer
2891
- * 每次接口调用,都会全量覆盖发布和订阅的资源。
2892
- * @param header
2893
- * @param body
3027
+ * 被邀请者用户 ID
2894
3028
  */
2895
- exchange(headers: IRTCReqHeader, body: IExchangeReqBody): Promise<{
2896
- code: RCRTCCode;
2897
- data?: IExchangeResponse | undefined;
2898
- }>;
3029
+ inviteeUserId: string;
3030
+ }
3031
+ /**
3032
+ * 业务层监听收到连麦邀请、取消连麦的字段
3033
+ */
3034
+ interface IPKInviteInfo extends IPKInviterBaseInfo {
2899
3035
  /**
2900
- * 退出房间
3036
+ * 邀请额外信息
2901
3037
  */
2902
- exit(headers: IRTCReqHeader): Promise<RCRTCCode>;
3038
+ extra?: string;
3039
+ }
3040
+ /**
3041
+ * 业务层监听收到连麦应答的字段
3042
+ */
3043
+ interface IPKInviteAnswerInfo extends IPKInviterBaseInfo, IPKInviteeBaseInfo {
2903
3044
  /**
2904
- * 观众端订阅主播资源
3045
+ * 是否同意邀请
2905
3046
  */
2906
- broadcastSubscribe(headers: IRTCReqHeader, body: IBroadcastSubReqBody): Promise<{
2907
- code: RCRTCCode;
2908
- data?: IBroadcastSubRespBody | undefined;
2909
- }>;
3047
+ agree: boolean;
2910
3048
  /**
2911
- * 观众端退出订阅
3049
+ * 响应额外信息
2912
3050
  */
2913
- broadcastExit(headers: IRTCReqHeader): Promise<{
2914
- code: RCRTCCode;
2915
- }>;
3051
+ extra?: string;
3052
+ }
3053
+ /**
3054
+ * 业务层监听收到连麦结束的字段
3055
+ */
3056
+ interface IPKEndInfo {
2916
3057
  /**
2917
- * 直播推流、自定义布局配置
3058
+ * 发起结束的房间 ID
2918
3059
  */
2919
- setMcuConfig(headers: IMCUReqHeaders, body: IMCUConfig | ISetEnableCDN): Promise<{
2920
- code: RCRTCCode;
2921
- res?: any;
2922
- }>;
3060
+ endRoomId: string;
2923
3061
  /**
2924
- * 房间内观众获取 CDN 资源信息、拉流地址
3062
+ * 发起结束的用户 ID
2925
3063
  */
2926
- getCDNResourceInfo(headers: ICDNPlayUrlReqHeaders, url: string): Promise<{
3064
+ endUserId: string;
3065
+ }
3066
+ /**
3067
+ * 观众加房间返回给客户的 CDN 信息
3068
+ */
3069
+ interface IJoinResCDNInfo {
3070
+ resolution?: RCResolution;
3071
+ fps?: RCFrameRate;
3072
+ CDNEnable?: boolean;
3073
+ }
3074
+ interface IPubSuccessRes {
3075
+ code: RCRTCCode;
3076
+ liveUrl?: string;
3077
+ failedTracks?: {
2927
3078
  code: RCRTCCode;
2928
- res?: ICDNPlayUrlResponse;
2929
- }>;
3079
+ tracks: RCLocalTrack[];
3080
+ }[];
2930
3081
  }
2931
3082
 
2932
3083
  /**
@@ -2944,37 +3095,26 @@ declare enum BackgroundPictureFillMode {
2944
3095
  }
2945
3096
 
2946
3097
  declare class RCMCUConfigBuilder {
3098
+ private _invoker;
2947
3099
  /**
2948
3100
  * flush 提交回调
2949
3101
  */
2950
- private readonly _onFlush;
2951
3102
  /**
2952
3103
  * trackId 有效性验证方法
2953
3104
  */
2954
3105
  private readonly _isValidTrackId;
2955
- /**
2956
- * 扩散 cdn_uris
2957
- */
2958
- private readonly _sendCDNInfoSignal;
2959
3106
  /**
2960
3107
  * mcu 配置数据,每次向服务器提交全量数据
2961
3108
  */
2962
3109
  private _values;
2963
- constructor(
3110
+ constructor(_invoker: Invoker,
2964
3111
  /**
2965
3112
  * flush 提交回调
2966
3113
  */
2967
- _onFlush: (config: IMCUConfig) => Promise<{
2968
- code: RCRTCCode;
2969
- }>,
2970
3114
  /**
2971
3115
  * trackId 有效性验证方法
2972
3116
  */
2973
- _isValidTrackId: (trackId: string) => boolean,
2974
- /**
2975
- * 扩散 cdn_uris
2976
- */
2977
- _sendCDNInfoSignal: () => void);
3117
+ _isValidTrackId: (trackId: string) => boolean);
2978
3118
  /**
2979
3119
  * 设置合流后的主位置显示的视频流
2980
3120
  * @param videoTrackId 视频流资源 Id
@@ -3141,6 +3281,7 @@ declare class RCMCUConfigBuilder {
3141
3281
  flush(reset?: boolean): Promise<{
3142
3282
  code: RCRTCCode;
3143
3283
  }>;
3284
+ __innerGetValues(): IMCUConfig;
3144
3285
  }
3145
3286
 
3146
3287
  /**
@@ -3148,29 +3289,32 @@ declare class RCMCUConfigBuilder {
3148
3289
  */
3149
3290
  declare class RCLivingRoom extends RCAbstractRoom {
3150
3291
  private _livingType;
3151
- /**
3152
- * 是否是主房间
3153
- */
3154
- protected _isMainRoom: boolean;
3155
3292
  readonly _mcuConfigBuilder: RCMCUConfigBuilder;
3156
3293
  /**
3157
- * cdn_uris 信令扩散数据
3294
+ * 跨房间连麦管理器
3158
3295
  */
3159
- private _CDNUris;
3160
- private _CDNEnable;
3296
+ private _roomPKHandler;
3297
+ constructor(context: RTCPluginContext, runtime: IRuntime, roomId: string, service: RCMediaService, initOptions: IRCRTCInitOptions, _livingType: RCLivingType, isUpgrade?: boolean, isMainRoom?: boolean,
3161
3298
  /**
3162
- * 跨房间连麦管理器
3299
+ * 是否使用多 peerConnection
3163
3300
  */
3164
- private readonly _roomPKHandler;
3165
- constructor(context: RTCPluginContext, runtime: IRuntime, roomId: string, data: IJoinRTCRoomData, service: RCMediaService, initOptions: IRCRTCInitOptions, clientEvent: Function, _livingType: RCLivingType, isUpgrage: boolean | undefined,
3301
+ useMutilPeerC?: boolean, _clientSessionId?: string);
3302
+ private _initAfterCatchRoomData;
3166
3303
  /**
3167
- * 是否是主房间
3304
+ * @override
3168
3305
  */
3169
- _isMainRoom: boolean,
3306
+ __innerInit(mode: RTCMode, joinType?: RTCJoinType, livingType?: RCLivingType, innerUserDatas?: IRTCUserData, outerUserDatas?: IRTCUserData): Promise<{
3307
+ code: RCRTCCode | ErrorCode;
3308
+ data?: IJoinRTCRoomData;
3309
+ }>;
3310
+ __innerInitByIdentityChange(): Promise<ErrorCode>;
3170
3311
  /**
3171
- * 是否使用多 peerConnection
3312
+ * 增量发布资源,若发布的资源 tag 及媒体类型重复,后者将覆盖前者进行发布。
3313
+ * @param tracks 待发布的 RCLocalTrack 实例
3314
+ * @returns
3172
3315
  */
3173
- useMutilPeerC?: boolean, _clientSessionId?: string);
3316
+ publish(tracks: (RCLocalTrack | IPublishAttrs)[]): Promise<IPubSuccessRes>;
3317
+ unpublish(tracks: RCLocalTrack[]): Promise<IPubSuccessRes>;
3174
3318
  /**
3175
3319
  * resourceId 有效性验证
3176
3320
  * @param resourceId
@@ -3183,58 +3327,19 @@ declare class RCLivingRoom extends RCAbstractRoom {
3183
3327
  getMCUConfigBuilder(): RCMCUConfigBuilder | {
3184
3328
  code: RCRTCCode;
3185
3329
  };
3186
- /**
3187
- * 接收 MCU 配置并向 MediaServer 提交
3188
- * @param data
3189
- */
3190
- private _onMCUConfigFlush;
3191
- /**
3192
- * 主播端断线重连后,需更新内存中的 CDN 数据
3193
- * 判断房间内 CDN 状态是否和内存数据一致,不一致时需通知到客户端
3194
- */
3195
- __onReconnected(): Promise<void>;
3196
3330
  /**
3197
3331
  * 开启/停用推 CDN
3198
3332
  */
3199
3333
  enableInnerCDN(enable: boolean): Promise<{
3200
3334
  code: RCRTCCode;
3201
3335
  }>;
3202
- /**
3203
- * 开启、停用 CDN 推资源后发信令
3204
- */
3205
- private _sendCDNInfoSignal;
3206
- /**
3207
- * 扩散 cdn_uris 资源
3208
- */
3209
- private _spreadCDNInfo;
3210
- /**
3211
- * 给房间设置 CDN 数据
3212
- */
3213
- private _setRoomCDNInfo;
3214
3336
  /**
3215
3337
  * 资源变化时触发
3216
3338
  * 直播房间需单独处理 cdn_uris
3217
3339
  */
3218
- protected _resourceHandle(content: {
3219
- /**
3220
- * 旧版本兼容参数,当收到非 `RTCMessageName.TOTAL_CONTENT_RESOURCE` 时:
3221
- * * ignore 值为 `true` 表示该消息由 signal server 向旧版本 RTCLib 提供的兼容消息,无需处理
3222
- * * 否则认为该消息是由旧版本 RTCLib 主动发出的增量变更消息,需要处理
3223
- */
3224
- ignore?: boolean;
3225
- /**
3226
- * 发布到房间内的资源列表,`RTCMessageName.TOTAL_CONTENT_RESOURCE` 消息携带全量数据,否则为增量数据
3227
- */
3228
- uris: IPublishedResource[];
3340
+ protected _resourceHandle(content: ResourceMsgContent & {
3229
3341
  cdn_uris?: ICDNUris[];
3230
- }, messageType: string, userId: string): Promise<void>;
3231
- /**
3232
- * 重写父类 _exchangeHandle 方法
3233
- */
3234
- protected _exchangeHandle(body: IExchangeReqBody, pcName: string): Promise<{
3235
- code: RCRTCCode;
3236
- data?: IExchangeResponse | undefined;
3237
- }>;
3342
+ }, messageType: RCRTCMessageType.PUBLISH | RCRTCMessageType.UNPUBLISH | RCRTCMessageType.MODIFY | RCRTCMessageType.TOTAL_CONTENT_RESOURCE, userId: string): Promise<void>;
3238
3343
  /**
3239
3344
  * 观众切换为主播后直接处理人员变更及资源变更
3240
3345
  */
@@ -3243,28 +3348,20 @@ declare class RCLivingRoom extends RCAbstractRoom {
3243
3348
  * 返回 CDN 是否可用
3244
3349
  * @returns boolean
3245
3350
  */
3246
- __getCDNEnable(): boolean | undefined;
3351
+ __getCDNEnable(): boolean;
3247
3352
  /**
3248
3353
  * 返回 CDN 推送模式: 自动 or 手动
3249
- * @returns boolean
3250
3354
  */
3251
3355
  __getCDNPushMode(): RCInnerCDNPushMode | undefined;
3252
3356
  /**
3357
+ * @override
3253
3358
  * 加入 PK 房间回调
3254
3359
  */
3255
3360
  private _onJoinedPKRoom;
3256
- /**
3257
- * 离开 PK 房间后,如果参与过连麦,pushOtherRooms 需去掉退出的连麦房间配置,重新和 mediaServer 交互
3258
- */
3259
- private _onLeavePKRoom;
3260
3361
  /**
3261
3362
  * @override
3262
3363
  */
3263
3364
  protected _getPushOtherRoomsParams(): IPushOtherRooms[];
3264
- /**
3265
- * 携带 pushOtherRooms 与 mediaServer 重新交互
3266
- */
3267
- private _exchangeWithPushOtherRoom;
3268
3365
  /**
3269
3366
  * 获取 PK 业务处理器
3270
3367
  * @since version 5.3.0
@@ -3280,14 +3377,14 @@ declare class RCLivingRoom extends RCAbstractRoom {
3280
3377
  /**
3281
3378
  * 是否是主房间
3282
3379
  */
3283
- isMainRoom(): boolean;
3380
+ isMainRoom(): boolean | undefined;
3284
3381
  }
3285
3382
 
3286
3383
  /**
3287
3384
  * 普通音视频房间
3288
3385
  */
3289
3386
  declare class RCRTCRoom extends RCAbstractRoom {
3290
- constructor(context: RTCPluginContext, runtime: IRuntime, roomId: string, data: IJoinRTCRoomData, service: RCMediaService, initOptions: IRCRTCInitOptions, clientEvent: Function,
3387
+ constructor(context: RTCPluginContext, runtime: IRuntime, roomId: string, service: RCMediaService, initOptions: IRCRTCInitOptions, isUpgrade?: boolean, isMainRoom?: boolean,
3291
3388
  /**
3292
3389
  * 是否使用多 peerConnection
3293
3390
  */
@@ -3303,7 +3400,6 @@ declare class RCAudienceClient {
3303
3400
  * 是否使用多 peerConnection
3304
3401
  */
3305
3402
  private readonly _useMutilPeerC?;
3306
- private readonly _clientSessionId?;
3307
3403
  private _pc;
3308
3404
  private _service;
3309
3405
  /**
@@ -3330,11 +3426,12 @@ declare class RCAudienceClient {
3330
3426
  * peerConnection 管理类
3331
3427
  */
3332
3428
  private _peerCManager;
3429
+ private readonly _clientSessionId;
3333
3430
  constructor(_context: RTCPluginContext, runtime: IRuntime, _initOption: IRCRTCInitOptions,
3334
3431
  /**
3335
3432
  * 是否使用多 peerConnection
3336
3433
  */
3337
- _useMutilPeerC?: boolean | undefined, _clientSessionId?: string | undefined);
3434
+ _useMutilPeerC?: boolean | undefined);
3338
3435
  private _getReqHeaders;
3339
3436
  private _clearSubscribeInfo;
3340
3437
  private _livingType;
@@ -3392,7 +3489,6 @@ declare class RCRTCClient {
3392
3489
  * 获取加入的连麦房间
3393
3490
  */
3394
3491
  private _getJoinedPKRoomList;
3395
- private _getPKRoomIds;
3396
3492
  /**
3397
3493
  * 获取当前用户 Id,若 IM 未连接,这返回 `''`
3398
3494
  * @returns
@@ -3411,7 +3507,6 @@ declare class RCRTCClient {
3411
3507
  userIds?: string[];
3412
3508
  tracks?: RCRemoteTrack[];
3413
3509
  }>;
3414
- private _joinRTCRoom;
3415
3510
  /**
3416
3511
  * 主播加入直播房间或观众上麦场景调用,观众上麦之前需先取消已订阅的直播间资源
3417
3512
  * @param roomId 房间 Id
@@ -3426,7 +3521,6 @@ declare class RCRTCClient {
3426
3521
  tracks?: RCRemoteTrack[];
3427
3522
  CDNEnable?: boolean;
3428
3523
  }>;
3429
- private _joinLivingRoom;
3430
3524
  private _audience;
3431
3525
  /**
3432
3526
  * 获取直播观众客户端
@@ -3441,11 +3535,6 @@ declare class RCRTCClient {
3441
3535
  leaveRoom(room: RCAbstractRoom): Promise<{
3442
3536
  code: RCRTCCode;
3443
3537
  }>;
3444
- private _leaveRoom;
3445
- /**
3446
- * 清除 _crtRoom 的引用
3447
- */
3448
- private _releaseCrtRoomObj;
3449
3538
  private _getMediaStream;
3450
3539
  /**
3451
3540
  * 从麦克风中捕获音轨数据