index.d.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. export declare type VideoCodec = 'vp8' | 'h264';
  2. export declare type AudioCodec = 'opus';
  3. export declare type RoomType = 'rtc' | 'live';
  4. export declare type UserRole = 'pull' | 'push' | 'push-and-pull';
  5. export declare type DeviceType = 'audio' | 'video';
  6. // 业务方使用的事件类型
  7. export declare type EventType =
  8. | 'user-added'
  9. | 'user-removed'
  10. | 'stream-added'
  11. | 'stream-removed'
  12. | 'stream-published'
  13. | 'stream-subscribed'
  14. | 'mute-video'
  15. | 'unmute-video'
  16. | 'mute-audio'
  17. | 'unmute-audio'
  18. | 'screenshare-stopped'
  19. | 'connection-state-change'
  20. | 'kick-off'
  21. | 'network-quality'
  22. | 'stream-reconnected'
  23. | 'record-notify'
  24. | 'relay-notify'
  25. | 'volume-indicator';
  26. export declare type ConnectionState = 'OPEN' | 'CONNECTING' | 'CLOSING' | 'RECONNECTING' | 'CLOSED';
  27. export declare type WaterMarkPosition = 'left-top' | 'left-bottom' | 'right-top' | 'right-bottom'; // 左上,左下,右上,右下
  28. export declare type WaterMarkType = 'time' | 'image' | 'text';
  29. export declare type MainViewType = 'desktop' | 'screen' | 'camera'; // todo - remove desktop
  30. export declare type NetworkQuality = '0' | '1' | '2' | '3' | '4' | '5' | '6';
  31. export interface ClientOptions {
  32. type?: RoomType;
  33. role?: UserRole;
  34. codec?: VideoCodec; // 可设 vp8 或 h264,默认为 h264
  35. }
  36. export interface Codecs {
  37. audio: Array<AudioCodec>;
  38. video: Array<VideoCodec>;
  39. }
  40. declare type FacingMode = 'user' | 'environment' | 'left' | 'right';
  41. export interface PublishOptions {
  42. audio: boolean; // 是否开启麦克风
  43. video: boolean; // 是否开启摄像头
  44. screenAudio?: boolean; // 是否获取屏幕共享的音频
  45. screen: boolean; // 是否共享屏幕
  46. facingMode?: FacingMode; // 指定使用的摄像头
  47. microphoneId?: string; // 麦克风设备ID
  48. cameraId?: string; // 摄像头设备ID
  49. extensionId?: string; // chrome插件ID
  50. mediaStream?: MediaStream; // 自定义的媒体流
  51. file?: File; // 图片流使用的图片文件
  52. filePath?: string; // 图片流使用的图片的地址
  53. previewId?: string; // 预览流ID
  54. }
  55. export interface PreviewStreamOptions extends PublishOptions {
  56. previewId: string; // 预览流ID
  57. }
  58. export interface DeviceOptions {
  59. audio: boolean; // 是否开启麦克风
  60. video: boolean; // 是否开启摄像头
  61. facingMode?: FacingMode;
  62. microphoneId?: string; // 麦克风设备ID
  63. cameraId?: string; // 摄像头设备ID
  64. }
  65. export interface DeviceDetectionOptions {
  66. audio: boolean; // 必填,指定是否检测麦克风设备
  67. video: boolean; // 必填,指定是否检测摄像头设备
  68. microphoneId?: string; // 选填,指定需要检测的麦克风设备的ID,可通过 getMicrophones 方法查询获得该ID,不填时,将检测默认的麦克风设备
  69. cameraId?: string; // 选填,指定需要检测的摄像头设备的ID,可以通过 getCameras 方法查询获得该ID,不填时,将检测默认的摄像头设备
  70. }
  71. export interface DeviceDetectionResult {
  72. audio: boolean;
  73. audioError?: string;
  74. video: boolean;
  75. videoError?: string;
  76. }
  77. export interface User {
  78. uid: string; // 用户ID
  79. }
  80. export interface Stream {
  81. previewId?: string; // 预览Id
  82. sid: string; // 流ID
  83. uid: string; // 对应的用户的ID
  84. type: 'publish' | 'subscribe' | 'preview'; // 流类型
  85. mediaType?: 'camera' | 'screen'; // 流的媒体类型,用于对发布流的区分
  86. video: boolean; // 是否包含音频
  87. audio: boolean; // 是否包含视频
  88. muteAudio: boolean; // 音频是否静音
  89. muteVideo: boolean; // 视频是否静音
  90. mediaStream?: MediaStream; // 业务侧自定义媒体流
  91. }
  92. export interface LeaveRoomOptions {
  93. keepRecording: boolean; // 是否保持服务端录制,默认不保持
  94. }
  95. export interface AudioVolumeOptions {
  96. streamId?: string;
  97. element?: HTMLMediaElement;
  98. volume: number;
  99. }
  100. export interface WaterMarkOptions {
  101. position?: WaterMarkPosition;
  102. type?: WaterMarkType; // 水印类型
  103. remarks?: string; // 水印备注
  104. }
  105. export interface MixStreamOptions {
  106. width?: number; // 混流后视频的宽度
  107. height?: number; // 混流后视频的高度
  108. template?: number; // 混流模板,对应不同的录制布局
  109. isAverage?: boolean; // 是否均匀,均分对应平铺,不均分对应垂直
  110. }
  111. export interface RelayOptions {
  112. time?: number; // 转推开启时间的时间戳,不填时,将默认使用当前时间的时间戳
  113. fragment: number; // 切片
  114. }
  115. export interface RecordOptions {
  116. bucket: string;
  117. region: string;
  118. uid?: string; // 指定某用户的流为主画面
  119. mainViewType?: MainViewType; // 主画面类型
  120. mixStream?: MixStreamOptions;
  121. waterMark?: WaterMarkOptions;
  122. relay?: RelayOptions;
  123. }
  124. export interface Record {
  125. FileName: string;
  126. RecordId: string;
  127. }
  128. export interface EffectOptions {
  129. streamId?: string;
  130. effectId: number;
  131. filePath?: string;
  132. loop?: boolean;
  133. playTime?: number;
  134. replace?: boolean;
  135. }
  136. export interface EffectVolumeOptions {
  137. streamId?: string;
  138. effectId: number;
  139. volume: number;
  140. }
  141. export interface SwitchDeviceOptions {
  142. streamId?: string;
  143. type: DeviceType;
  144. deviceId: string;
  145. }
  146. export interface SwitchImageOptions {
  147. streamId?: string;
  148. file?: File;
  149. filePath?: string;
  150. }
  151. export interface SnapshotOptions {
  152. streamId?: string;
  153. download?: string | boolean;
  154. }
  155. export interface AudioStats {
  156. br: number;
  157. lostpre: number;
  158. vol: number;
  159. mime: string;
  160. }
  161. export interface VideoStats {
  162. br: number;
  163. lostpre: number;
  164. frt: number;
  165. w: number;
  166. h: number;
  167. mime: string;
  168. }
  169. export interface NetworkStats {
  170. rtt: number;
  171. }
  172. export interface ReplaceTrackOptions {
  173. streamId?: string;
  174. track: MediaStreamTrack;
  175. retain?: boolean;
  176. }
  177. export declare type MixType = 'relay' | 'record' | 'relay-and-record' | 'update-config';
  178. export declare type MixLayoutType = 'flow' | 'main' | 'custom' | 'customMain' | 'customFlow' | 'single';
  179. export declare type MixAudioCodec = 'aac';
  180. export declare type MixVideoCodec = 'h264' | 'h265';
  181. export declare type H264Quality = 'B' | 'CB' | 'M' | 'E' | 'H';
  182. export declare type MixOutputMode = 'audio-video' | 'audio'; // 默认为 audio-video
  183. export declare type MixStreamAddMode = 'automatic' | 'manual'; // 默认为 'automatic 自动的
  184. export interface MixLayoutOptions {
  185. type: MixLayoutType; // layout 类型
  186. standbyTypes?: MixLayoutType[]; // 待切换的 layout 类型
  187. custom?: Array<object>; // layout 为 'custom',自定义布局填在custom里,格式参照RFC5707 Media Server Markup Language (MSML)
  188. mainViewUId?: string; // 指定某用户的流为主画面
  189. mainViewType?: MainViewType; // 主画面类型
  190. }
  191. export interface MixAudioOptions {
  192. codec: MixAudioCodec;
  193. }
  194. export interface MixVideoOptions {
  195. codec: MixVideoCodec;
  196. quality?: H264Quality; // 当 codec 为 h264 时,此项起作用
  197. frameRate?: number;
  198. bitRate?: number;
  199. }
  200. export interface BackgroundColorOptions {
  201. r: number;
  202. g: number;
  203. b: number;
  204. }
  205. export interface MixOptions {
  206. type?: MixType; // 默认为 record
  207. bucket?: string;
  208. region?: string;
  209. pushURL?: string[]; // type 是 转推,转推和录制时,需指定
  210. layout?: MixLayoutOptions;
  211. audio?: MixAudioOptions;
  212. video?: MixVideoOptions;
  213. outputMode?: MixOutputMode;
  214. width?: number;
  215. height?: number;
  216. backgroundColor?: BackgroundColorOptions;
  217. waterMark?: WaterMarkOptions;
  218. streams?: MixStream[];
  219. streamAddMode?: MixStreamAddMode;
  220. timeoutPeriod?: number; // 超时周期,任务检测到没有(指定)流后超过此时间,将自动停止,单位是s,最长24小时
  221. keyUser?: string; // 指定关键用户,退出房间后,录制/转推任务自动关闭
  222. }
  223. export interface StopMixOptions {
  224. type?: MixType; // 默认为 record
  225. pushURL?: string[]; // 如果 type 为 relay 或 relay-and-record,需要指定停止对哪个 url 的转推,如果留空会停止对所有 url 的转推
  226. }
  227. export interface MixResult {
  228. MixId: string;
  229. FileName?: string;
  230. Type?: MixType;
  231. PushURL?: string[];
  232. }
  233. export interface MixStream {
  234. uid: string; // 用户 ID
  235. mediaType: 'camera' | 'screen'; // 流的媒体类型
  236. }
  237. export interface AddMixStreamsOptions {
  238. streams: MixStream[];
  239. }
  240. export interface RemoveMixStreamsOptions {
  241. streams: MixStream[];
  242. }
  243. // 录制
  244. export interface StartRecordOptions {
  245. bucket: string;
  246. region: string;
  247. layout?: MixLayoutOptions;
  248. width?: number;
  249. height?: number;
  250. backgroundColor?: BackgroundColorOptions;
  251. waterMark?: WaterMarkOptions;
  252. streams?: MixStream[]; // 如果列表为空,会自动添加房间内所有用户的流,如果指定了用户,则只添加该用户的指定流
  253. }
  254. export interface RecordResult {
  255. Id: string;
  256. FileName?: string;
  257. }
  258. declare type UpdateMixStreamsType = 'add' | 'remove' | 'replace';
  259. export interface UpdateMixStreamsOptions {
  260. type: UpdateMixStreamsType;
  261. streams: MixStream[];
  262. }
  263. export interface StartRelayOptions {
  264. pushURL?: string[];
  265. layout?: MixLayoutOptions;
  266. audio?: MixAudioOptions;
  267. video?: MixVideoOptions;
  268. outputMode?: MixOutputMode;
  269. width?: number;
  270. height?: number;
  271. backgroundColor?: BackgroundColorOptions;
  272. waterMark?: WaterMarkOptions;
  273. streams?: MixStream[];
  274. streamAddMode?: MixStreamAddMode;
  275. }
  276. export interface RelayResult {
  277. Id: string;
  278. PushURL?: string[];
  279. }
  280. declare type UpdateRelayPushURLType = 'add' | 'remove' | 'replace';
  281. export interface UpdateRelayPushURLOptions {
  282. type: UpdateRelayPushURLType;
  283. pushURL: string[];
  284. }
  285. export interface UpdateRelayLayoutOptions {
  286. layout: MixLayoutOptions;
  287. }
  288. export interface UpdateRelayWaterMarkOptions {
  289. waterMark: WaterMarkOptions;
  290. }
  291. declare type VideoFitType = 'cover' | 'contain'; // cover 模式:优先保证视窗被填满。contain 模式:优先保证视频内容全部显示。
  292. declare type PlayControlsOption = 'show' | 'hide' | 'auto'; // 默认 auto,正常播放时隐藏,未播放时显示
  293. export interface PlayOptions {
  294. streamId: string;
  295. container: HTMLElement | string;
  296. mute?: boolean;
  297. mirror?: boolean;
  298. fit?: VideoFitType;
  299. controls?: PlayControlsOption;
  300. }
  301. export interface CustomVideoProfile {
  302. width: number; // 640, 视频宽度
  303. height: number; // 480, 视频高度
  304. framerate: number; // 15, 帧率
  305. bitrate: number; // 500, 比特率 kbps
  306. }
  307. export interface VideoProfileOptions {
  308. previewId?: string;
  309. profile: string | CustomVideoProfile;
  310. }
  311. export interface MixNotification {
  312. code: string;
  313. message: string;
  314. }
  315. export interface AudioVolume {
  316. sid: string; // 流ID
  317. uid: string; // 对应的用户的ID
  318. mediaType: 'camera' | 'screen'; // 流的媒体类型,用于对发布流的区分
  319. volume: number;
  320. }