index.d.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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';
  11. export declare type ConnectionState = 'OPEN' | 'CONNECTING' | 'CLOSING' | 'RECONNECTING' | 'CLOSED';
  12. export declare type WaterMarkPosition = 'left-top' | 'left-bottom' | 'right-top' | 'right-bottom'; // 左上,左下,右上,右下
  13. export declare type WaterMarkType = 'time' | 'image' | 'text';
  14. export declare type MainViewType = 'desktop' | 'screen' | 'camera'; // todo - remove desktop
  15. export declare type NetworkQuality = '0' | '1' | '2' | '3' | '4' | '5' | '6';
  16. export interface ClientOptions {
  17. type?: RoomType
  18. role?: UserRole
  19. codec?: VideoCodec // 可设 vp8 或 h264,默认为 h264
  20. }
  21. export interface Codecs {
  22. audio: Array<AudioCodec>,
  23. video: Array<VideoCodec>
  24. }
  25. declare type FacingMode = 'user' | 'environment' | 'left' | 'right';
  26. export interface PublishOptions {
  27. audio: boolean // 是否开启麦克风
  28. video: boolean // 是否开启摄像头
  29. facingMode?: FacingMode
  30. screen: boolean // 是否共享屏幕
  31. microphoneId?: string // 麦克风设备ID
  32. cameraId?: string // 摄像头设备ID
  33. extensionId?: string // chrome插件ID
  34. mediaStream?: MediaStream // 自定义的媒体流
  35. }
  36. export interface DeviceOptions {
  37. audio: boolean // 是否开启麦克风
  38. video: boolean // 是否开启摄像头
  39. facingMode?: FacingMode
  40. microphoneId?: string // 麦克风设备ID
  41. cameraId?: string // 摄像头设备ID
  42. }
  43. export interface DeviceDetectionOptions {
  44. audio: boolean // 必填,指定是否检测麦克风设备
  45. video: boolean // 必填,指定是否检测摄像头设备
  46. microphoneId?: string // 选填,指定需要检测的麦克风设备的ID,可通过 getMicrophones 方法查询获得该ID,不填时,将检测默认的麦克风设备
  47. cameraId?: string // 选填,指定需要检测的摄像头设备的ID,可以通过 getCameras 方法查询获得该ID,不填时,将检测默认的摄像头设备
  48. }
  49. export interface DeviceDetectionResult {
  50. audio: boolean
  51. audioError?: string
  52. video: boolean
  53. videoError?: string
  54. }
  55. export interface User {
  56. uid: string // 用户ID
  57. }
  58. export interface Stream {
  59. sid: string // 流ID
  60. uid: string // 对应的用户的ID
  61. type: 'publish'|'subscribe' // 流类型
  62. mediaType?: 'camera'|'screen' // 流的媒体类型,用于对发布流的区分
  63. video: boolean // 是否包含音频
  64. audio: boolean // 是否包含视频
  65. muteAudio: boolean // 音频是否静音
  66. muteVideo: boolean // 视频是否静音
  67. mediaStream?: MediaStream // 业务侧自定义媒体流
  68. }
  69. export interface LeaveRoomOptions {
  70. keepRecording: boolean // 是否保持服务端录制,默认不保持
  71. }
  72. export interface AudioVolumeOptions {
  73. streamId?: string
  74. element?: HTMLMediaElement
  75. volume: number
  76. }
  77. export interface WaterMarkOptions {
  78. position?: WaterMarkPosition
  79. type?: WaterMarkType // 水印类型
  80. remarks?: string // 水印备注
  81. }
  82. export interface MixStreamOptions {
  83. width?: number // 混流后视频的宽度
  84. height?: number // 混流后视频的高度
  85. template?: number // 混流模板,对应不同的录制布局
  86. isAverage?: boolean // 是否均匀,均分对应平铺,不均分对应垂直
  87. }
  88. export interface RelayOptions {
  89. time?: number, // 转推开启时间的时间戳,不填时,将默认使用当前时间的时间戳
  90. fragment: number, // 切片
  91. }
  92. export interface RecordOptions {
  93. bucket: string
  94. region: string
  95. uid?: string // 指定某用户的流为主画面
  96. mainViewType?: MainViewType // 主画面类型
  97. mixStream?: MixStreamOptions
  98. waterMark?: WaterMarkOptions
  99. relay?: RelayOptions
  100. }
  101. export interface Record {
  102. FileName: string,
  103. RecordId: string
  104. }
  105. export interface EffectOptions {
  106. streamId?: string
  107. effectId: number
  108. filePath?: string
  109. loop?: boolean
  110. playTime?: number
  111. replace?: boolean
  112. }
  113. export interface EffectVolumeOptions {
  114. streamId?: string
  115. effectId: number
  116. volume: number
  117. }
  118. export interface SwitchDeviceOptions {
  119. streamId?: string
  120. type: DeviceType
  121. deviceId: string
  122. }
  123. export interface SwitchImageOptions {
  124. streamId?: string
  125. file?: File,
  126. filePath?: string
  127. }
  128. export interface SnapshotOptions {
  129. streamId?: string
  130. download?: string | boolean
  131. }
  132. export interface AudioStats {
  133. br: number
  134. lostpre: number
  135. vol: number
  136. mime: string
  137. }
  138. export interface VideoStats {
  139. br: number,
  140. lostpre: number,
  141. frt: number,
  142. w: number,
  143. h: number,
  144. mime: string
  145. }
  146. export interface NetworkStats {
  147. rtt: number
  148. }
  149. export interface ReplaceTrackOptions {
  150. streamId?: string
  151. track: MediaStreamTrack
  152. retain?: boolean
  153. }
  154. export declare type MixType = 'relay' | 'record' | 'relay-and-record' | 'update-config'
  155. export declare type MixLayoutType = 'flow' | 'main' | 'custom'
  156. export declare type MixAudioCodec = 'aac'
  157. export declare type MixVideoCodec = 'h264' | 'h265'
  158. export declare type H264Quality = 'B' | 'CB' | 'M' | 'E' | 'H'
  159. export interface MixLayoutOptions {
  160. type: MixLayoutType // layout 类型
  161. custom?: Object[] // layout 为 'custom',自定义布局填在custom里,格式参照RFC5707 Media Server Markup Language (MSML)
  162. mainViewUId?: string // 指定某用户的流为主画面
  163. mainViewType?: MainViewType // 主画面类型
  164. }
  165. export interface MixAudioOptions {
  166. codec: MixAudioCodec
  167. }
  168. export interface MixVideoOptions {
  169. codec: MixVideoCodec
  170. quality?: H264Quality // 当 codec 为 h264 时,此项起作用
  171. frameRate?: number
  172. bitRate?: number
  173. }
  174. export interface BackgroundColorOptions {
  175. r: number
  176. g: number
  177. b: number
  178. }
  179. export interface MixOptions {
  180. type?: MixType // 默认为 record
  181. bucket?: string
  182. region?: string
  183. pushURL?: string[] // type 是 转推,转推和录制时,需指定
  184. layout?: MixLayoutOptions
  185. audio?: MixAudioOptions
  186. video?: MixVideoOptions
  187. width?: number
  188. height?: number
  189. backgroundColor?: BackgroundColorOptions
  190. waterMark?: WaterMarkOptions
  191. streams?: MixStream[]
  192. }
  193. export interface StopMixOptions {
  194. type?: MixType // 默认为 record
  195. pushURL?: string[] // 如果 type 为 relay 或 relay-and-record,需要指定停止对哪个 url 的转推,如果留空会停止对所有 url 的转推
  196. }
  197. export interface MixResult {
  198. MixId: string
  199. FileName?: string
  200. Type?: MixType
  201. PushURL?: string[]
  202. }
  203. export interface MixStream {
  204. uid: string, // 用户 ID
  205. mediaType: 'camera'|'screen' // 流的媒体类型
  206. }
  207. export interface AddMixStreamsOptions {
  208. streams: MixStream[]
  209. }
  210. export interface RemoveMixStreamsOptions {
  211. streams: MixStream[]
  212. }