trtc-cloud-js-sdk 2.12.2-beta.1 → 2.12.2-beta.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trtc-cloud-js-sdk",
3
- "version": "2.12.2-beta.1",
3
+ "version": "2.12.2-beta.10",
4
4
  "description": "Tencent Cloud RTC SDK for Web And Electron",
5
5
  "main": "trtc-cloud-js-sdk.js",
6
6
  "module": "trtc-cloud-js-sdk.esm.js",
@@ -19,6 +19,6 @@
19
19
  "author": "Tencent Cloud Client R&D Center",
20
20
  "license": "ISC",
21
21
  "dependencies": {
22
- "trtc-sdk-v5": "5.18.0"
22
+ "trtc-sdk-v5": "5.18.1-beta.5"
23
23
  }
24
24
  }
@@ -2,6 +2,7 @@ import EventEmitter from 'eventemitter3';
2
2
  import { VirtualBackground } from 'trtc-sdk-v5/plugins/video-effect/virtual-background';
3
3
  import { BasicBeauty } from 'trtc-sdk-v5/plugins/video-effect/basic-beauty';
4
4
  import VideoMixer from 'trtc-sdk-v5/plugins/video-effect/video-mixer';
5
+ import Whiteboard from 'trtc-sdk-v5/plugins/whiteboard';
5
6
 
6
7
  declare enum TRTCVideoResolution {
7
8
  TRTCVideoResolution_120_120 = 1,
@@ -780,11 +781,14 @@ interface ITRTCMediaMixingManager {
780
781
  addMediaSource(mediaSource: TRTCMediaSource): Promise<void>;
781
782
  removeMediaSource(mediaSource: TRTCMediaSource): Promise<void>;
782
783
  updateMediaSource(mediaSource: TRTCMediaSource): Promise<void>;
783
- startPublish(): Promise<void>;
784
+ startPublish(options?: {
785
+ streamType?: TRTCVideoStreamType;
786
+ }): Promise<void>;
784
787
  stopPublish(): Promise<void>;
785
788
  updatePublishParams(params: TRTCMediaMixingEncParam): Promise<void>;
786
- bindPreviewArea(view: HTMLElement | null): void;
787
- destroy(): void;
789
+ bindPreviewArea(view: HTMLElement | null): Promise<void>;
790
+ updatePreviewArea(view: HTMLElement | null): Promise<void>;
791
+ destroy(): Promise<void>;
788
792
  on(event: string, func: (...args: any[]) => void): void;
789
793
  off(event: string, func: (...args: any[]) => void): void;
790
794
  }
@@ -813,6 +817,8 @@ declare class TRTCMediaMixingManager implements ITRTCMediaMixingManager {
813
817
  private sourceList;
814
818
  private trtcSourceMap;
815
819
  private mixVideoTrack;
820
+ /** 记录混流输出的推流目标,stopPublish 时据此停止对应流 */
821
+ private publishStreamType;
816
822
  private selectedSource;
817
823
  private logger;
818
824
  private trtc;
@@ -853,6 +859,12 @@ declare class TRTCMediaMixingManager implements ITRTCMediaMixingManager {
853
859
  * mediaMixingManager.bindPreviewArea( previewDOM);
854
860
  */
855
861
  bindPreviewArea(view: HTMLElement | null): Promise<void>;
862
+ /**
863
+ * 更新本地混流预览容器,不重启 VideoMixer 或替换混流输出 Track。
864
+ * 用于 RoomKit 布局切换时,将现有预览迁移到新的 DOM 容器。
865
+ * @param view {HTMLElement | null} - 新的本地混流预览容器
866
+ */
867
+ updatePreviewArea(view: HTMLElement | null): Promise<void>;
856
868
  private _getTRTCSourceKey;
857
869
  private _getTRTCFillMode;
858
870
  private _getTRTCVideoProfile;
@@ -881,9 +893,14 @@ declare class TRTCMediaMixingManager implements ITRTCMediaMixingManager {
881
893
  updateMediaSource(mediaSource: TRTCMediaSource): Promise<void>;
882
894
  /**
883
895
  * 开始推流
896
+ * @param options {Object} - 推流参数,可选
897
+ * @param options.streamType {TRTCVideoStreamType} - 混流输出推流目标,默认 `TRTCVideoStreamTypeBig`(主流)。
898
+ * 传入 `TRTCVideoStreamTypeSub`(辅流)时,混流输出走屏幕分享辅流通道,远端按屏幕分享订阅(对齐 RoomKit「辅流 = 混流输出」模型)。
884
899
  * @returns {Promise<void>}
885
900
  */
886
- startPublish(): Promise<void>;
901
+ startPublish(options?: {
902
+ streamType?: TRTCVideoStreamType;
903
+ }): Promise<void>;
887
904
  /**
888
905
  * 停止推流
889
906
  * @returns {Promise<void>}
@@ -925,6 +942,245 @@ declare class TRTCMediaMixingManager implements ITRTCMediaMixingManager {
925
942
  private unselectMediaSource;
926
943
  }
927
944
 
945
+ /**
946
+ * 互动白板类型定义
947
+ *
948
+ * 设计目标:Web 端对上层 RoomEngine 的对外契约与 Native 完全对齐。
949
+ * - 下行(RoomEngine -> SDK):通过 `callExperimentalAPI` 透传 `OnRecvWhiteboardCommand` 指令
950
+ * - 上行(SDK -> RoomEngine):通过 `WhiteboardDelegate.onSendWhiteboardCommand` 回调笔迹数据
951
+ *
952
+ * 为了与 Native 的 JSON 线上格式保持一致,字段命名沿用 Native 的 snake_case。
953
+ */
954
+ /**
955
+ * 绘图工具类型
956
+ * @enum {String}
957
+ */
958
+ declare type WhiteboardToolType = 'pen' | 'rect' | 'ellipse' | 'arrow' | 'eraserObject';
959
+ /**
960
+ * 白板操作指令
961
+ * - undo / redo / clearall:下行(远端控制)
962
+ * - clearself:上行 payload 中使用
963
+ * @enum {String}
964
+ */
965
+ declare type WhiteboardOp = 'undo' | 'redo' | 'clearall' | 'clearself';
966
+ /**
967
+ * 白板事件名
968
+ */
969
+ declare enum TRTCWhiteboardEvent {
970
+ /** 上行:本端笔迹/操作数据,需上层转发给远端 */
971
+ onSendWhiteboardCommand = "onSendWhiteboardCommand"
972
+ }
973
+ /**
974
+ * 工具配置
975
+ */
976
+ interface WhiteboardToolConfig {
977
+ /** 工具类型,默认 pen */
978
+ type?: WhiteboardToolType;
979
+ /** 画笔颜色,支持 '#RRGGBB' / '#AARRGGBB' / 0xAARRGGBB 整型 */
980
+ color?: string | number;
981
+ /** 线宽 */
982
+ line_width?: number;
983
+ }
984
+ declare const WhiteboardToolConfig: any;
985
+ /**
986
+ * 画布尺寸
987
+ */
988
+ interface WhiteboardCanvasInfo {
989
+ width: number;
990
+ height: number;
991
+ }
992
+ declare const WhiteboardCanvasInfo: any;
993
+ /**
994
+ * 下行指令参数 —— 与 Native `OnRecvWhiteboardCommand` 的 `params` 对齐。
995
+ *
996
+ * 该指令承担两类职责:
997
+ * 1. 配置/生命周期:`enable`、`canvas`、`tool`、`whiteboard.interactive`、`view_handle`
998
+ * 2. 远端协同:`owner_id`、`stroke_id`、`op`,以及远端笔迹点数据(`xs`/`ys`/`tool`/`color`/`lw`)
999
+ */
1000
+ interface WhiteboardRecvCommand {
1001
+ /** 1=启用, 0=关闭;关闭时其余字段忽略 */
1002
+ enable: number;
1003
+ /** 笔迹 id */
1004
+ stroke_id?: string;
1005
+ /** 操作指令 undo|redo|clearall */
1006
+ op?: WhiteboardOp;
1007
+ /** 操作/笔迹归属用户;存在时表示这是一条远端协同指令 */
1008
+ owner_id?: string;
1009
+ /**
1010
+ * 视图句柄。
1011
+ * - Native:int64 句柄
1012
+ * - Web:传入绑定事件的 DOM 元素或其 id(HTMLElement | string)。
1013
+ * 白板启动后再次传入时,会将现有画布和交互迁移到新的视图。
1014
+ */
1015
+ view_handle?: number | string | HTMLElement;
1016
+ /** 接收 Native 回调数据的实例句柄(Web 端忽略,仅为兼容 Native 透传) */
1017
+ whiteboard_delegate_handle?: number;
1018
+ /** 画布尺寸 */
1019
+ canvas?: WhiteboardCanvasInfo;
1020
+ /** 工具配置 */
1021
+ tool?: WhiteboardToolConfig;
1022
+ /** 白板交互配置 */
1023
+ whiteboard?: {
1024
+ /** canvas 是否响应触摸/鼠标交互事件 */
1025
+ interactive?: boolean;
1026
+ };
1027
+ /** 远端笔迹:是否首包(仅 pen) */
1028
+ is_first?: boolean;
1029
+ /** 远端笔迹颜色(与上行 payload 对齐) */
1030
+ color?: string | number;
1031
+ /** 远端笔迹线宽(line_width 简写,与上行 payload 对齐) */
1032
+ lw?: number;
1033
+ /** 远端笔迹 x 坐标序列(base64 编码,与上行 payload 对齐) */
1034
+ xs?: string;
1035
+ /** 远端笔迹 y 坐标序列(base64 编码,与上行 payload 对齐) */
1036
+ ys?: string;
1037
+ }
1038
+ declare const WhiteboardRecvCommand: any;
1039
+ /**
1040
+ * 上行回调 payload —— 与 Native `OnSendWhiteboardCommand` 的 payload 对齐。
1041
+ */
1042
+ interface WhiteboardSendPayload {
1043
+ /** stroke_id */
1044
+ id: string;
1045
+ /** 仅 pen 的时候发,首包哨兵 */
1046
+ is_first?: boolean;
1047
+ /** 工具类型 */
1048
+ tool?: WhiteboardToolType;
1049
+ /** 颜色 */
1050
+ color?: string;
1051
+ /** 线宽 */
1052
+ lw?: number;
1053
+ /** x 坐标序列(base64 编码) */
1054
+ xs?: string;
1055
+ /** y 坐标序列(base64 编码) */
1056
+ ys?: string;
1057
+ /** 操作指令 undo|redo|clearself */
1058
+ op?: WhiteboardOp;
1059
+ }
1060
+ declare const WhiteboardSendPayload: any;
1061
+ /**
1062
+ * 白板上行数据回调通道 —— 与 Native `WhiteboardDelegate` 对齐。
1063
+ */
1064
+ interface WhiteboardDelegate {
1065
+ /**
1066
+ * Native/SDK 返回给上层 room 的信令数据
1067
+ * @param isNeedAck 是否需要 ack
1068
+ * @param payload JSON 字符串,结构见 {@link WhiteboardSendPayload}
1069
+ */
1070
+ onSendWhiteboardCommand(isNeedAck: boolean, payload: string): void;
1071
+ }
1072
+ declare const WhiteboardDelegate: any;
1073
+ /**
1074
+ * 白板管理器对外接口
1075
+ */
1076
+ interface ITRTCWhiteboardManager {
1077
+ /** 设置上行数据回调(与 Native WhiteboardDelegate 对齐) */
1078
+ setDelegate(delegate: WhiteboardDelegate | null): void;
1079
+ /** 处理下行指令(对应 callExperimentalAPI 的 OnRecvWhiteboardCommand) */
1080
+ onRecvWhiteboardCommand(command: WhiteboardRecvCommand): Promise<void>;
1081
+ /** 销毁,释放插件与监听 */
1082
+ destroy(): Promise<void>;
1083
+ on(event: string, func: (...args: any[]) => void): void;
1084
+ off(event: string, func: (...args: any[]) => void): void;
1085
+ }
1086
+ declare const ITRTCWhiteboardManager: any;
1087
+
1088
+ /**
1089
+ * 互动白板管理器
1090
+ *
1091
+ * 对上层(RoomEngine)暴露与 Native 完全一致的契约:
1092
+ * - 下行:{@link onRecvWhiteboardCommand}(由 `trtcCloud.callExperimentalAPI('OnRecvWhiteboardCommand', ...)` 路由进来)
1093
+ * - 上行:{@link WhiteboardDelegate#onSendWhiteboardCommand}(或 `on('onSendWhiteboardCommand', cb)` 事件)
1094
+ *
1095
+ * 内部依赖 Web 端 `Whiteboard` 插件完成本地渲染并合流到 VideoMixer,因此使用前必须先启动 VideoMixer
1096
+ * (通常通过 `trtcCloud.getMediaMixingManager().bindPreviewArea(view)`)。
1097
+ */
1098
+ declare class TRTCWhiteboardManager implements ITRTCWhiteboardManager {
1099
+ static whiteboardManager: TRTCWhiteboardManager | null;
1100
+ private readonly logPrefix;
1101
+ private logger;
1102
+ private trtc;
1103
+ private trtcCloud;
1104
+ private eventEmitter;
1105
+ private delegate;
1106
+ /** 白板插件是否已启动 */
1107
+ private started;
1108
+ /** 绑定交互事件的 view */
1109
+ private view;
1110
+ constructor(options: {
1111
+ logger: any;
1112
+ trtc: any;
1113
+ trtcCloud: any;
1114
+ });
1115
+ /**
1116
+ * 设置上行数据回调(与 Native WhiteboardDelegate 对齐)
1117
+ * @param delegate 回调实例,传 null 取消
1118
+ */
1119
+ setDelegate(delegate: WhiteboardDelegate | null): void;
1120
+ /**
1121
+ * 处理下行指令 —— 对应 Native `OnRecvWhiteboardCommand`。
1122
+ *
1123
+ * @param command {@link WhiteboardRecvCommand}
1124
+ */
1125
+ onRecvWhiteboardCommand(command: WhiteboardRecvCommand): Promise<void>;
1126
+ /**
1127
+ * 启动白板插件
1128
+ */
1129
+ private _start;
1130
+ /**
1131
+ * 更新白板配置(视图、工具、颜色、线宽、交互)
1132
+ */
1133
+ private _update;
1134
+ /**
1135
+ * 停止白板插件
1136
+ */
1137
+ private _stop;
1138
+ /**
1139
+ * 执行本端操作(undo/redo/clearall)
1140
+ */
1141
+ private _applyLocalOp;
1142
+ /**
1143
+ * 远端协同指令(带 owner_id)。
1144
+ *
1145
+ * 说明:Web `Whiteboard` 插件的跨端笔迹同步由插件内部通过 TRTC customMessage + SEI 自动完成
1146
+ * (guest 在本地预览 canvas 绘制并同步给 host,host 合流进推流),无需上层 RoomEngine 转发
1147
+ * 远端笔迹点数据。因此这里对远端笔迹数据(xs/ys)不做注入,仅记录日志,保持与 Native 契约形态一致。
1148
+ */
1149
+ private _applyRemoteCommand;
1150
+ /**
1151
+ * native tool 配置 -> Web 插件 tool 分组对象({ name, color, lineWidth })
1152
+ */
1153
+ private _buildToolGroup;
1154
+ /**
1155
+ * native whiteboard.interactive -> Web 插件 config 分组对象({ interactive })
1156
+ */
1157
+ private _buildConfigGroup;
1158
+ /**
1159
+ * native canvas -> Web 插件 canvasInfo 分组对象({ width, height })
1160
+ */
1161
+ private _buildCanvasInfo;
1162
+ /**
1163
+ * native op(undo|redo|clearall|clearself) -> Web 插件 operation(undo|redo|clear)
1164
+ */
1165
+ private _opToOperation;
1166
+ /**
1167
+ * 颜色归一化:支持 '#RRGGBB' / '#AARRGGBB' / 0xAARRGGBB 整型 -> CSS 颜色字符串
1168
+ */
1169
+ private _normalizeColor;
1170
+ /**
1171
+ * 解析 view 句柄。
1172
+ * - HTMLElement:直接使用
1173
+ * - string:作为元素 id 查找
1174
+ * - number(Native int64 句柄):Web 端无法使用,回退到 VideoMixer 默认 view
1175
+ */
1176
+ private _resolveView;
1177
+ on(event: string, func: (...args: any[]) => void): void;
1178
+ off(event: string, func: (...args: any[]) => void): void;
1179
+ destroy(): Promise<void>;
1180
+ private log;
1181
+ private logError;
1182
+ }
1183
+
928
1184
  /**
929
1185
  * 转录参数
930
1186
  */
@@ -1127,7 +1383,7 @@ declare class TRTC_Cloud extends EventEmitter {
1127
1383
  private _hasJoinedRoom;
1128
1384
  private _isExitingRoom;
1129
1385
  constructor(config?: ITRTCCloudConfig);
1130
- static getPlugin(pluginName: string): typeof VirtualBackground | typeof BasicBeauty | typeof VideoMixer | null;
1386
+ static getPlugin(pluginName: string): typeof VirtualBackground | typeof BasicBeauty | typeof VideoMixer | typeof Whiteboard | null;
1131
1387
  /**
1132
1388
  * 创建 TRTCCloud 对象单例
1133
1389
  * @param {ITRTCCloudConfig} config 构造函数初始化
@@ -1673,10 +1929,13 @@ declare class TRTC_Cloud extends EventEmitter {
1673
1929
  * await trtcCloud.stopScreenShare();
1674
1930
  */
1675
1931
  stopScreenShare(): Promise<void>;
1676
- _startPublishVideoTrack({ videoTrack }: {
1932
+ _startPublishVideoTrack({ videoTrack, streamType }: {
1677
1933
  videoTrack: MediaStreamTrack;
1934
+ streamType?: TRTCVideoStreamType;
1935
+ }): Promise<void>;
1936
+ _stopPublishVideoTrack({ streamType }?: {
1937
+ streamType?: TRTCVideoStreamType;
1678
1938
  }): Promise<void>;
1679
- _stopPublishVideoTrack(): Promise<void>;
1680
1939
  startScreenCapture(): void;
1681
1940
  pauseScreenCapture(): void;
1682
1941
  resumeScreenCapture(): void;
@@ -2040,7 +2299,34 @@ declare class TRTC_Cloud extends EventEmitter {
2040
2299
  * @returns {TRTCMediaMixingManager | null}
2041
2300
  */
2042
2301
  getMediaMixingManager(): TRTCMediaMixingManager;
2302
+ /**
2303
+ * 获取互动白板管理器
2304
+ *
2305
+ * 白板依赖 VideoMixer,使用前请先通过 `getMediaMixingManager().bindPreviewArea(view)` 启动 VideoMixer。
2306
+ * 对上层(RoomEngine)的契约与 Native 对齐:
2307
+ * - 下行:`callExperimentalAPI(JSON.stringify({ api: 'OnRecvWhiteboardCommand', params: {...} }))`
2308
+ * - 上行:`getWhiteboardManager().setDelegate({ onSendWhiteboardCommand })`
2309
+ * 或 `getWhiteboardManager().on('onSendWhiteboardCommand', (isNeedAck, payload) => {})`
2310
+ *
2311
+ * @example
2312
+ * import TRTCCloud from 'trtc-cloud-js-sdk';
2313
+ *
2314
+ * const trtcCloud = TRTCCloud.getTRTCShareInstance();
2315
+ * const whiteboardManager = trtcCloud.getWhiteboardManager();
2316
+ * whiteboardManager.setDelegate({
2317
+ * onSendWhiteboardCommand(isNeedAck, payload) {
2318
+ * // 转发给远端
2319
+ * },
2320
+ * });
2321
+ * trtcCloud.callExperimentalAPI(JSON.stringify({
2322
+ * api: 'OnRecvWhiteboardCommand',
2323
+ * params: { enable: 1, tool: { type: 'pen', color: '#ff0000', line_width: 3 } },
2324
+ * }));
2325
+ *
2326
+ * @returns {TRTCWhiteboardManager}
2327
+ */
2328
+ getWhiteboardManager(): TRTCWhiteboardManager;
2043
2329
  getAITranscriberManager(): AITranscriberManager;
2044
2330
  }
2045
2331
 
2046
- export { AITranscriberListener, AudioMuteType, IAITranscriberManager, ITRTCMediaMixingEvent, ITRTCMediaMixingManager, InteractionOption, Rect, TRTCAppScene, TRTCAudioQuality, TRTCAudioSceneEx, TRTCBeautyStyle, TRTCCameraCaptureMode, TRTCCameraCaptureParams, TRTCDeviceInfo, TRTCDeviceState, TRTCDeviceType, TRTCImageBuffer, TRTCLocalStatistics, TRTCLogLevel, TRTCMediaMixingEncParam, TRTCMediaMixingErrorCode, TRTCMediaMixingEvent, TRTCMediaSource, TRTCMediaSourceType, TRTCMixInputType, TRTCMixUser, TRTCNetworkQosParam, TRTCParams, TRTCPublishCDNParam, TRTCQosControlMode, TRTCQuality, TRTCQualityInfo, TRTCRemoteStatistics, TRTCRenderParams, TRTCRoleType, TRTCScreenCaptureProperty, TRTCScreenCaptureSourceInfo, TRTCScreenCaptureSourceType, TRTCStatistics, TRTCTranscodingConfig, TRTCTranscodingConfigMode, TRTCVideoEncParam, TRTCVideoFillMode, TRTCVideoMirrorType, TRTCVideoQosPreference, TRTCVideoResolution, TRTCVideoResolutionMode, TRTCVideoRotation, TRTCVideoStreamType, TRTCVolumeInfo, TranscriberMessage, TranscriberParams, TRTC_Cloud as default };
2332
+ export { AITranscriberListener, AudioMuteType, IAITranscriberManager, ITRTCMediaMixingEvent, ITRTCMediaMixingManager, ITRTCWhiteboardManager, InteractionOption, Rect, TRTCAppScene, TRTCAudioQuality, TRTCAudioSceneEx, TRTCBeautyStyle, TRTCCameraCaptureMode, TRTCCameraCaptureParams, TRTCDeviceInfo, TRTCDeviceState, TRTCDeviceType, TRTCImageBuffer, TRTCLocalStatistics, TRTCLogLevel, TRTCMediaMixingEncParam, TRTCMediaMixingErrorCode, TRTCMediaMixingEvent, TRTCMediaSource, TRTCMediaSourceType, TRTCMixInputType, TRTCMixUser, TRTCNetworkQosParam, TRTCParams, TRTCPublishCDNParam, TRTCQosControlMode, TRTCQuality, TRTCQualityInfo, TRTCRemoteStatistics, TRTCRenderParams, TRTCRoleType, TRTCScreenCaptureProperty, TRTCScreenCaptureSourceInfo, TRTCScreenCaptureSourceType, TRTCStatistics, TRTCTranscodingConfig, TRTCTranscodingConfigMode, TRTCVideoEncParam, TRTCVideoFillMode, TRTCVideoMirrorType, TRTCVideoQosPreference, TRTCVideoResolution, TRTCVideoResolutionMode, TRTCVideoRotation, TRTCVideoStreamType, TRTCVolumeInfo, TRTCWhiteboardEvent, TranscriberMessage, TranscriberParams, WhiteboardCanvasInfo, WhiteboardDelegate, WhiteboardOp, WhiteboardRecvCommand, WhiteboardSendPayload, WhiteboardToolConfig, WhiteboardToolType, TRTC_Cloud as default };