index.d.ts 9.4 KB

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