index.d.ts 9.8 KB

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