index.d.ts 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717
  1. // Generated by dts-bundle v0.7.3
  2. declare module '@urtc/sdk-web' {
  3. import { Client } from '__@urtc/sdk-web/client';
  4. import { LocalStream, LocalStreamOptions } from '__@urtc/sdk-web/stream/local-stream';
  5. import { generateToken } from '__@urtc/sdk-web/utils/token';
  6. import { ClientOptions } from '__@urtc/sdk-web/types';
  7. import { LogLevel } from '__@urtc/sdk-web/logger';
  8. /**
  9. * 创建客户端
  10. * @param appId - 应用 ID,可在控制台查看
  11. * @param opts - 定义客户端的属性
  12. * @public
  13. * @example
  14. * ```js
  15. * const client = createClient('AppID');
  16. * client
  17. * .join('roomId', 'userId', 'token')
  18. * .then(() => {
  19. * client.publish(localStream);
  20. * })
  21. * .catch((err) => {
  22. * console.log(`加入房间失败 ${err}`);
  23. * });
  24. * ```
  25. * @throws {@link RtcError}
  26. */
  27. export function createClient(appId: string, opts?: ClientOptions): Client;
  28. /**
  29. * 创建本地流
  30. * @param opts - 必传,定义本地音视频流的属性
  31. * 注:
  32. * 1. video, screen 不可同时为 true
  33. * 2. audio, video, screen 不可同时为 false
  34. * 3. 若指定了 file,则 init 时将优先使用 file 来创建初始化本地流的视频
  35. * 4. screenAudio 在不同浏览器上表现不同,参见 {@link LocalStreamOptions}
  36. * @public
  37. * @example
  38. * ```js
  39. * const localStream = createStream({ audio: true, video: true, screen: false });
  40. * localStream
  41. * .init()
  42. * .then(() => {
  43. * localStream
  44. * .play(container)
  45. * .catch((err) => {console.log(`播放失败: ${err}`)});
  46. * })
  47. * .catch((err) => {
  48. * console.log(`本地流初始化失败 ${err}`);
  49. * });
  50. * ```
  51. * @throws {@link RtcError}
  52. */
  53. export function createStream(opts: LocalStreamOptions): LocalStream;
  54. /**
  55. * 设置日志打印级别,用于打印出更多日志来调试或定位问题,默认 warn 级别
  56. * @param level - 日志级别,有 'debug', 'info', 'warn', 'error' 级别;
  57. * @public
  58. * @example
  59. * ```js
  60. * setLogLevel('info');
  61. * ```
  62. */
  63. export function setLogLevel(level: LogLevel): void;
  64. /**
  65. * 开启日志(操作/错误/状态)的上报,默认开启
  66. * @public
  67. * @example
  68. * ```js
  69. * enableUploadLog();
  70. * ```
  71. */
  72. export function enableUploadLog(): void;
  73. /**
  74. * 关闭日志(操作/错误/状态)的上报
  75. * 注:若无特殊原因,不建议关闭日志上报,关闭后,在线上出现错误时,将无法根据日志定位问题
  76. * @public
  77. * @example
  78. * ```js
  79. * disableUploadLog();
  80. * ```
  81. */
  82. export function disableUploadLog(): void;
  83. export { generateToken };
  84. export * from '__@urtc/sdk-web/devices';
  85. export * from '__@urtc/sdk-web/client';
  86. export * from '__@urtc/sdk-web/types';
  87. export * from '__@urtc/sdk-web/event';
  88. export * from '__@urtc/sdk-web/error';
  89. export * from '__@urtc/sdk-web/user/user';
  90. export * from '__@urtc/sdk-web/stream/types';
  91. export * from '__@urtc/sdk-web/stream/stream';
  92. export * from '__@urtc/sdk-web/stream/local-stream';
  93. export * from '__@urtc/sdk-web/stream/remote-stream';
  94. export * from '__@urtc/sdk-web/connection/types';
  95. export * from '__@urtc/sdk-web/server';
  96. export * from '__@urtc/sdk-web/plugin';
  97. export * from '__@urtc/sdk-web/version';
  98. /************** 4 plugin ****************/
  99. export { Client };
  100. export { LocalStream };
  101. export { RemoteStream } from '__@urtc/sdk-web/stream/remote-stream';
  102. }
  103. declare module '__@urtc/sdk-web/client' {
  104. import { RtcEventType } from '__@urtc/sdk-web/event';
  105. import { Listener } from '__@urtc/sdk-web/event-emitter';
  106. import { LocalStream } from '__@urtc/sdk-web/stream/local-stream';
  107. import { RemoteStream } from '__@urtc/sdk-web/stream/remote-stream';
  108. import { User } from '__@urtc/sdk-web/user/user';
  109. import { JoinOptions, RoleType } from '__@urtc/sdk-web/types';
  110. import { ClientPlugin } from '__@urtc/sdk-web/plugin';
  111. /**
  112. * RTC 客户端,可进行加入、离开房间,发布、订阅流等操作。
  113. * @public
  114. */
  115. export class Client {
  116. /**
  117. * 加载 Client 插件,使用插件功能
  118. * @param plugin - 插件
  119. * @param options - 插件初始化参数
  120. */
  121. static use(plugin: ClientPlugin, options?: any): void;
  122. /**
  123. * 获取远端用户信息
  124. * @example
  125. * ```js
  126. * const users = client.getRemoteUsers();
  127. * ```
  128. */
  129. getRemoteUsers(): User[];
  130. /**
  131. * 获取当前 Client 已发布的本地流
  132. * @example
  133. * ```js
  134. * const localStreams = client.getLocalStreams();
  135. * ```
  136. */
  137. getLocalStreams(): LocalStream[];
  138. /**
  139. * 获取当前 Client 已接收到的远端流(包含已订阅或未订阅的远端流)
  140. * @example
  141. * ```js
  142. * const remoteStreams = client.getRemoteStreams();
  143. * ```
  144. */
  145. getRemoteStreams(): RemoteStream[];
  146. /**
  147. * 加入房间
  148. * @param roomId - 房间ID
  149. * @param userId - 用户ID
  150. * @param token - 由 AppId,AppKey,RoomId,UserId 生成的令牌
  151. * @param opts - 其他选项
  152. * @example
  153. * ```js
  154. * const remoteStreams = client.getRemoteStreams();
  155. * client
  156. * .join('roomIdxxx', 'userIdxxx', 'tokenxxx')
  157. * .then(() => {
  158. * console.log(`加入房间成功`);
  159. * // client.publish(localStream);
  160. * })
  161. * .catch((err) => {
  162. * console.log(`加入房间失败 ${err}`);
  163. * });
  164. * ```
  165. * @reject {@link RtcError}
  166. */
  167. join(roomId: string, userId: string, token: string, opts?: JoinOptions): Promise<void>;
  168. /**
  169. * 离开房间
  170. * @example
  171. * ```js
  172. * client
  173. * .leave()
  174. * .then(() => {
  175. * console.log(`离开房间成功`);
  176. * })
  177. * .catch((err) => {
  178. * console.log(`离开房间失败 ${err}`);
  179. * });
  180. * ```
  181. */
  182. leave(): Promise<void>;
  183. /**
  184. * 监听 Client 对象的事件
  185. * @param type - 事件类型
  186. * @param listener - 事件监听函数
  187. * @example
  188. * ```js
  189. * const handleStreamAdded = (event) => {
  190. * client
  191. * .subscribe(event.data)
  192. * .catch((err) => {
  193. * console.log(`订阅失败 ${err}`);
  194. * });
  195. * }
  196. * client.on('stream-added', handleStreamAdded);
  197. * ```
  198. * @throws {@link RtcError}
  199. */
  200. on<T extends RtcEventType>(type: T, listener: Listener<T>): Client;
  201. /**
  202. * 取消监听 Client 对象的事件
  203. * @param type - 事件类型,特别的,可以使用 * 来一次性取消对所有事件的监听
  204. * @param listener - 事件监听函数
  205. * @example
  206. * ```js
  207. * client.off('stream-added', handleStreamAdded);
  208. * ```
  209. *
  210. * **特别地,一次性取消对所有事件的监听**
  211. * @example
  212. * ```js
  213. * client.off('*');
  214. * ```
  215. * @throws {@link RtcError}
  216. */
  217. off<T extends RtcEventType | '*'>(type: T, listener?: Listener<T>): Client;
  218. /**
  219. * 发布一条本地流
  220. * @param stream - 需要被发布的本地流
  221. * @example
  222. * ```js
  223. * client
  224. * .publish(localStream)
  225. * .catch((err) => {
  226. * console.log(`发布失败 ${err}`);
  227. * });
  228. * ```
  229. * @reject {@link RtcError}
  230. */
  231. publish(stream: LocalStream): Promise<void>;
  232. /**
  233. * 取消发布一条本地流
  234. * @param stream - 需要取消发布的本地流
  235. * @example
  236. * ```js
  237. * client
  238. * .unpublish(localStream)
  239. * .then(() => {
  240. * console.log('取消发布成功');
  241. * // localStream.destroy();
  242. * })
  243. * .catch((err) => {
  244. * console.log(`取消发布失败 ${err}`);
  245. * });
  246. * ```
  247. * @reject {@link RtcError}
  248. */
  249. unpublish(stream: LocalStream): Promise<void>;
  250. /**
  251. * 订阅一条远端流
  252. * @param stream - 需要被订阅的远端流
  253. * @example
  254. * ```js
  255. * client
  256. * .subscribe(remoteStream)
  257. * .catch((err) => {
  258. * console.log(`订阅失败 ${err}`);
  259. * });
  260. * ```
  261. * @reject {@link RtcError}
  262. */
  263. subscribe(stream: RemoteStream): Promise<void>;
  264. /**
  265. * 取消订阅一条远端流
  266. * @param stream - 需要取消订阅的远端流
  267. * @example
  268. * ```js
  269. * client
  270. * .unsubscribe(remoteStream)
  271. * .catch((err) => {
  272. * console.log(`取消订阅失败 ${err}`);
  273. * });
  274. * ```
  275. * @reject {@link RtcError}
  276. */
  277. unsubscribe(stream: RemoteStream): Promise<void>;
  278. /**
  279. * 修改用户角色
  280. * @param role - 用户角色
  281. * @example
  282. * ```js
  283. * client.setRole('push');
  284. * ```
  285. * @throws {@link RtcError}
  286. */
  287. setRole(role: RoleType): void;
  288. }
  289. }
  290. declare module '__@urtc/sdk-web/stream/local-stream' {
  291. import { Stream } from '__@urtc/sdk-web/stream/stream';
  292. import { PlayOptions } from '__@urtc/sdk-web/types';
  293. import { SwitchDeviceType } from '__@urtc/sdk-web/stream/types';
  294. import { VideoProfile, ScreenProfile, CustomVideoProfile } from '__@urtc/sdk-web/stream/profile';
  295. import { StreamPlugin } from '__@urtc/sdk-web/plugin';
  296. /**
  297. * 创建本地流的参数
  298. * @public
  299. */
  300. export interface LocalStreamOptions {
  301. /**
  302. * 是否读取麦克风设备来初始化本地流的音频
  303. */
  304. audio: boolean;
  305. /**
  306. * 选传,读取指定设备ID的麦克风
  307. */
  308. microphoneId?: string;
  309. /**
  310. * 是否读取摄像头设备来初始化本地流的视频
  311. */
  312. video: boolean;
  313. /**
  314. * 选传,读取指定设备ID的摄像头
  315. */
  316. cameraId?: string;
  317. /**
  318. * 是否使用屏幕共享的画面来初始化本地流
  319. */
  320. screen: boolean;
  321. /**
  322. * 选传,是否读取屏幕共享的音频,默认: false
  323. * 注:仅部分浏览器支持,如 Chrome 74,且不同系统表现不同,如 windows 会读取桌面音频,macOS 只支持读取浏览器 tab 中的音频,
  324. */
  325. screenAudio?: boolean;
  326. /**
  327. * 选传,在移动设备上,可以设置该参数选择使用前置或后置摄像头,其中,FacingMode 为 'user'(前置摄像头)或 'environment'(后置摄像头)
  328. */
  329. facingMode?: 'user' | 'environment';
  330. /**
  331. * 选传,使用图片初始化本地流的视频。
  332. * 注:若指定,将直接采用图片生成的视频作为本地流的视频源,不再按 video 设置的读取摄像头作为视频源,或 screen 设置的读取屏幕共享的画面作为视频源。
  333. */
  334. file?: string | File;
  335. /**
  336. * 选传,指定本地流的 ID,请注意创建多条流时,不可传入重复值
  337. */
  338. id?: string;
  339. /**
  340. * 选传,指定本地流的 userId
  341. */
  342. userId?: string;
  343. /**
  344. * 选传,音频轨道,参见 {@link https://developer.mozilla.org/zh-CN/docs/Web/API/MediaStreamTrack | MediaStreamTrack},指定本地流的音频源。
  345. * 注:若指定,将直接采用该音频轨道作为本地流的音频源,不再按 audio 设置的读取麦克风作为音频源,或 screenAudio 设置的读取屏幕共享的音频作为音频源。
  346. */
  347. audioSource?: MediaStreamTrack;
  348. /**
  349. * 选传,视频轨道,参见 {@link https://developer.mozilla.org/zh-CN/docs/Web/API/MediaStreamTrack | MediaStreamTrack},指定本地流的视频源。
  350. * 注:若指定,将直接采用该视频轨道作为本地流的视频源,不再按 video 设置的读取摄像头作为视频源,或 screen 设置的读取屏幕共享的画面作为视频源,或 file 设置的使用图片生成视频源。
  351. */
  352. videoSource?: MediaStreamTrack;
  353. }
  354. /**
  355. * 本地流,可用于本地预览,也可用 client 进行发布
  356. * @public
  357. */
  358. export class LocalStream extends Stream {
  359. /**
  360. * 加载流插件,使用插件功能
  361. * @param plugin - 插件
  362. * @param options - 插件初始化参数
  363. */
  364. static use(plugin: StreamPlugin, options?: any): void;
  365. /**
  366. * 初始化本地流对象,将读取麦克风、摄像头、屏幕共享等来初始化媒体流
  367. * @example
  368. * ```js
  369. * const stream = createStream({audio: true, video: true, screen: false});
  370. * stream
  371. * .init()
  372. * .then(() => {
  373. * client.publish(stream); // 发布本地流
  374. * })
  375. * .catch((err) => {
  376. * console.log(`初始化本地流失败 ${err}`);
  377. * })
  378. * ```
  379. */
  380. init(): Promise<void>;
  381. /**
  382. * 添加一条媒体轨道(音轨或视轨)到当前流
  383. * 注:
  384. * 1. 若创建本地流时,audio 为 false,不可添加音轨,video 为 false 时,不可添加视轨
  385. * @param track - 媒体轨道
  386. * @example
  387. * ```js
  388. * stream.addTrack(track);
  389. * ```
  390. */
  391. addTrack(track: MediaStreamTrack): void;
  392. /**
  393. * 从当前流中删除一条媒体轨道(音轨或视轨)
  394. * @param track - 媒体轨道
  395. * @example
  396. * ```js
  397. * stream.removeTrack(track);
  398. * ```
  399. */
  400. removeTrack(track: MediaStreamTrack): void;
  401. /**
  402. * 替换当前流中的媒体轨道
  403. * 注:
  404. * 1. 替换视频时,请使用与原轨道相同的分辨率的媒体轨道
  405. * 2. 返回值为当前流中相同类型的媒体轨道,此媒体轨道仍可用(占用音频设备或视频设备),请自行决定是否调用其 stop 方法释放设备
  406. * @param track - 新媒体轨道
  407. * @example
  408. * ```js
  409. * const oldTrack = stream.replaceTrack(track);
  410. * oldTrack.stop();
  411. * ```
  412. */
  413. replaceTrack(track: MediaStreamTrack): MediaStreamTrack | undefined;
  414. /**
  415. * 播放当前流
  416. * @param container - 播放音视频时,包裹 video 标签所用的容器元素或容器元素的 ID
  417. * @param opts - 其他播放参数,参见{@link PlayOptions}
  418. * @example
  419. * ```js
  420. * const container = 'xxx'; // 比如 id 为 xxx 的 div 元素
  421. * stream
  422. * .play(container)
  423. * .catch((err) => {
  424. * console.log(`播放失败: ${err}`); // 一般由于浏览器对自动播放的限制导致播放失败
  425. * });
  426. * ```
  427. * @reject {@link RtcError}
  428. */
  429. play(container: HTMLElement | string, opts?: PlayOptions): Promise<void>;
  430. /**
  431. * 设置当前流视频的 Profile,默认 '480p'
  432. * @param profile - 视频 Profile
  433. * @example
  434. * ```js
  435. * stream
  436. * .setVideoProfile('720p')
  437. * .then(() => {
  438. * console.log('set video profile success');
  439. * })
  440. * .catch((err) => {
  441. * console.log('set video profile failed ', err);
  442. * });
  443. * ```
  444. * 或
  445. * ```js
  446. * stream
  447. * .setVideoProfile({width: 640, height: 480, framerate: 15, bitrate: 500});
  448. * .then(() => {
  449. * console.log('set video profile success');
  450. * })
  451. * .catch((err) => {
  452. * console.log('set video profile failed ', err);
  453. * });
  454. * ```
  455. */
  456. setVideoProfile(profile: VideoProfile | CustomVideoProfile): Promise<void>;
  457. /**
  458. * 设置当前流(屏幕共享时)视频的 Profile,默认 '1080p'
  459. * 注:请务必在调用 init 方法之前,设置屏幕共享流的 Profile,否则无法生效。
  460. * @param profile - 视频 Profile
  461. * @example
  462. * ```js
  463. * stream.setScreenProfile('720p');
  464. * stream.init().catch((err) => {
  465. * console.log(`初始化屏幕共享流失败 ${err}`);
  466. * });
  467. * ```
  468. */
  469. setScreenProfile(profile: ScreenProfile | CustomVideoProfile): void;
  470. /**
  471. * 切换音视频设备
  472. * @param type - 设备类型
  473. * @param deviceId - 设备 ID
  474. * @example
  475. * ```js
  476. * stream.switchDevice('audio', 'xxxxxxx')
  477. * .then(() => {
  478. * console.log('切换设备成功');
  479. * })
  480. * .catch((err) => {
  481. * console.log(`切换设备失败:${err}`);
  482. * });
  483. * ```
  484. * @reject {@link RtcError}
  485. */
  486. switchDevice(type: SwitchDeviceType, deviceId: string): Promise<void>;
  487. /**
  488. * 切换图片 - 使用图片生成视频,并将当前流的视频使用其代替
  489. * @param file - 图片地址或图片文件
  490. * @example
  491. * ```js
  492. * const imgAddr = 'https://a.b.c/d.jpg';
  493. * stream.switchImage(imgAddr)
  494. * .then(() => {
  495. * console.log('切换图片成功')
  496. * })
  497. * .catch((err) => {
  498. * console.error(`切换图片失败:${err}`);
  499. * });
  500. * ```
  501. * @reject {@link RtcError}
  502. */
  503. switchImage(file: string | File): Promise<void>;
  504. }
  505. }
  506. declare module '__@urtc/sdk-web/utils/token' {
  507. /**
  508. * 根据 AppId,AppKey,RoomId,UserId 生成 token,用于开发阶段临时快速的加入房间并验证功能,由于 AppKey 不可暴露于公网,因此生产环境中不建议使用此方法生成 token。
  509. * @param appId - 应用 ID,可在控制台查看
  510. * @param appKey - 应用密钥,可在控制台查看
  511. * @param roomId - 房间 ID
  512. * @param userId - 用户 ID
  513. * @public
  514. * @example
  515. * ```js
  516. * const token = generateToken('appId', 'appKey', 'roomId', 'userId');
  517. * client.join('roomId', 'userId', token);
  518. * ```
  519. */
  520. export function generateToken(appId: string, appKey: string, roomId: string, userId: string): string;
  521. }
  522. declare module '__@urtc/sdk-web/types' {
  523. import { AudioCodec, VideoCodec } from '__@urtc/sdk-web/stream/types';
  524. /**
  525. * 视频播放时的显示模式
  526. * - cover 模式:优先保证视窗被填满。
  527. * - contain 模式:优先保证视频内容全部显示。
  528. * 播放摄像头视频流默认使用 cover 模式,屏幕共享视频流默认使用 contain 模式。
  529. * @public
  530. */
  531. export type PlayerVideoFitType = 'cover' | 'contain';
  532. /**
  533. * 视频播放时 audio / video 的控制面板的显示模式
  534. * - show 模式:一直显示
  535. * - hide 模式:一直隐藏
  536. * - auto 模式:自动判断
  537. * @public
  538. */
  539. export type PlayControlsType = 'show' | 'hide' | 'auto';
  540. /**
  541. * 播放器播放属性
  542. * @public
  543. */
  544. export interface PlayOptions {
  545. /**
  546. * 是否静音播放
  547. */
  548. mute: boolean;
  549. /**
  550. * 是否镜像播放
  551. */
  552. mirror?: boolean;
  553. /**
  554. * 视频播放时的{@link PlayerVideoFitType | 显示模式},默认 'cover',屏幕共享时默认使用 'contain'
  555. */
  556. fit?: PlayerVideoFitType;
  557. /**
  558. * 视频播放时 audio / video 的控制面板的显示模式,默认自动判断(播放失败时显示,播放成功时隐藏)
  559. */
  560. controls?: PlayControlsType;
  561. }
  562. export { /*AudioProfile,*/ VideoProfile, ScreenProfile } from '__@urtc/sdk-web/stream/profile';
  563. /**
  564. * 房间类型
  565. * @public
  566. */
  567. export type RoomType = 'conference' | 'live';
  568. /**
  569. * 用户角色
  570. * @public
  571. */
  572. export type RoleType = 'pull' | 'push' | 'push-and-pull';
  573. /**
  574. * 定义客户端的属性
  575. * @public
  576. */
  577. export interface ClientOptions {
  578. /**
  579. * 客户端{@link VideoCodec | 视频编码格式},默认 'vp8'
  580. */
  581. codec?: VideoCodec;
  582. }
  583. /**
  584. * 加入房间的属性
  585. * @public
  586. */
  587. export interface JoinOptions {
  588. /**
  589. * 加入房间的{@link RoomType | 房间类型},默认 'conference'
  590. */
  591. type?: RoomType;
  592. /**
  593. * 加入房间的{@link RoleType | 角色},默认 'push-and-pull'
  594. */
  595. role?: RoleType;
  596. }
  597. /**
  598. * 支持的音频、视频编解码格式
  599. * @public
  600. */
  601. export interface Codecs {
  602. /**
  603. * 音频编解码格式
  604. */
  605. audio: AudioCodec[];
  606. /**
  607. * 视频编解码格式
  608. */
  609. video: VideoCodec[];
  610. }
  611. /**
  612. * 截屏参数
  613. * @public
  614. */
  615. export interface SnapshotOptions {
  616. /**
  617. * 选填,是否将截屏保存为图片并下载,默认 false
  618. */
  619. download?: boolean;
  620. /**
  621. * 选填,将截屏保存为图片时指定的文件名
  622. * 当传入文件名时,将按指定的文件名保存图片,否则文件名将自动生成
  623. * 特别地,当传入文件名时,即使 download 指定为 false,也将按指定的文件名保存图片并下载
  624. */
  625. filename?: string;
  626. }
  627. }
  628. declare module '__@urtc/sdk-web/logger' {
  629. /**
  630. * 日志级别
  631. */
  632. export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
  633. }
  634. declare module '__@urtc/sdk-web/devices' {
  635. import { Codecs } from '__@urtc/sdk-web/types';
  636. /**
  637. * 获取音视频输入/输出设备列表,点击 [MediaDeviceInfo](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo) 查看详情
  638. * @public
  639. * @example
  640. * ```js
  641. * getDevices()
  642. * .then(devices => {
  643. * console.log(`获取设备列表成功:`, devices);
  644. * })
  645. * .catch(err => {
  646. * console.log(`获取设备列表失败:${err}`);
  647. * });
  648. * ```
  649. * @reject {@link RtcError}
  650. */
  651. export function getDevices(): Promise<MediaDeviceInfo[]>;
  652. /**
  653. * 获取摄像头设备列表,点击 [MediaDeviceInfo](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo) 查看详情
  654. * @public
  655. * @example
  656. * ```js
  657. * getCameras()
  658. * .then(devices => {
  659. * console.log(`获取设备列表成功:`, devices);
  660. * })
  661. * .catch(err => {
  662. * console.log(`获取设备列表失败:${err}`);
  663. * });
  664. * ```
  665. * @reject {@link RtcError}
  666. */
  667. export function getCameras(): Promise<MediaDeviceInfo[]>;
  668. /**
  669. * 获取麦克风设备列表,点击 [MediaDeviceInfo](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo) 查看详情
  670. * @public
  671. * @example
  672. * ```js
  673. * getMicrophones()
  674. * .then(devices => {
  675. * console.log(`获取设备列表成功:`, devices);
  676. * })
  677. * .catch(err => {
  678. * console.log(`获取设备列表失败:${err}`);
  679. * });
  680. * ```
  681. * @reject {@link RtcError}
  682. */
  683. export function getMicrophones(): Promise<MediaDeviceInfo[]>;
  684. /**
  685. * 获取扬声器设备列表,点击 [MediaDeviceInfo](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo) 查看详情
  686. * @public
  687. * @example
  688. * ```js
  689. * getLoudspeakers()
  690. * .then(devices => {
  691. * console.log(`获取设备列表成功:`, devices);
  692. * })
  693. * .catch(err => {
  694. * console.log(`获取设备列表失败:${err}`);
  695. * });
  696. * ```
  697. * @reject {@link RtcError}
  698. */
  699. export function getLoudspeakers(): Promise<MediaDeviceInfo[]>;
  700. /**
  701. * 设备检测选项
  702. * @public
  703. */
  704. export interface DeviceDetectionOptions {
  705. /**
  706. * 必填,指定是还检测麦克风设备
  707. */
  708. audio: boolean;
  709. /**
  710. * 必填,指定是否检测摄像头设备
  711. */
  712. video: boolean;
  713. /**
  714. * 选填,指定需要检测的麦克风设备的ID,可通过 getMicrophones 方法查询获得该ID,不填时,将检测默认的麦克风设备
  715. */
  716. microphoneId?: string;
  717. /**
  718. * 选填,指定需要检测的摄像头设备的ID,可以通过 getCameras 方法查询获得该ID,不填时,将检测默认的摄像头设备
  719. */
  720. cameraId?: string;
  721. }
  722. /**
  723. * 设备可用性检测 - 创建包含麦克风音频或摄像头视频的本地流时,有可能因为麦克风或摄像头设备问题(如驱动问题,或未经授权等),导致无法正确创建。此方法可用于设备检测,根据检测结果,再决定创建本地流时启用麦克风或摄像头或麦克风和摄像头
  724. * @param options - 需指定设备时,请传入设备 ID
  725. * @public
  726. * @example
  727. * ```js
  728. * deviceDetection({audio: true, video: true})
  729. * .then(() => {
  730. * console.log('设备可用');
  731. * })
  732. * .catch(err => {
  733. * console.log(`设备不可用,${err}`);
  734. * });
  735. * ```
  736. * @reject {@link RtcError}
  737. */
  738. export function deviceDetection(options: DeviceDetectionOptions): Promise<void>;
  739. /**
  740. * 检测浏览器是否完全(可访问本地音视频设备)支持 WebRTC。
  741. * @public
  742. * @example
  743. * ```js
  744. * if (!isSupportWebRTC()) {
  745. * console.log(`当前浏览器不完全支持 WebRTC,建议使用 Chrome 浏览器,iOS 系统建议使用 Safari 浏览器`);
  746. * }
  747. * ```
  748. */
  749. export function isSupportWebRTC(): boolean;
  750. /**
  751. * 检测浏览器是否支持屏幕共享
  752. * @public
  753. * @example
  754. * ```js
  755. * if (!isSupportScreenShare()) {
  756. * console.log(`当前浏览器不支持屏幕共享`);
  757. * }
  758. * ```
  759. */
  760. export function isSupportScreenShare(): boolean;
  761. /**
  762. * 检测浏览器支持的音视频编解码格式
  763. * @public
  764. * @example
  765. * ```js
  766. * getSupportedCodec()
  767. * .then((codecs) => {
  768. * console.log(`浏览器支持的音频编解码格式有 ${codecs.audio},视频编解码格式有 ${codecs.video}`);
  769. * })
  770. * .catch((err) => {
  771. * console.log(`浏览器获取音视频编解码格式失败,${err}`);
  772. * });
  773. * ```
  774. */
  775. export function getSupportedCodec(): Promise<Codecs>;
  776. }
  777. declare module '__@urtc/sdk-web/event' {
  778. import { User } from '__@urtc/sdk-web/user/user';
  779. import { Stream } from '__@urtc/sdk-web/stream/stream';
  780. import { ConnectionStates } from '__@urtc/sdk-web/connection/types';
  781. import { LocalStream } from '__@urtc/sdk-web/stream/local-stream';
  782. import { RemoteStream } from '__@urtc/sdk-web/stream/remote-stream';
  783. import { NetworkQualities } from '__@urtc/sdk-web/stream/types';
  784. /**
  785. * Rtc 用户事件类型:
  786. *
  787. * {@link RtcUserEvent 用户事件}
  788. * - user-joined - 有用户加入房间
  789. * - user-left - 有用户离开房间
  790. * - kick-off - 当前用户被踢出房间
  791. * @public
  792. * @example
  793. * ```js
  794. * client.on('user-joined', (event) => {
  795. * console.log(`用户 ${event.data.id} 加入`);
  796. * });
  797. * ```
  798. */
  799. export type RtcUserEventType = 'user-joined' | 'user-left' | 'kick-off';
  800. /**
  801. * Rtc 流事件类型:
  802. *
  803. * {@link RtcStreamEvent 流事件}
  804. * - stream-added - 有远端流加入,此时事件中的 data 为 {@link RemoteStream} 远端流
  805. * - stream-removed - 有远端流移除,此时事件中的 data 为 {@link RemoteStream} 远端流
  806. * - stream-subscribed - 远端流订阅完成,此时事件中的 data 为 {@link RemoteStream} 远端流
  807. * - stream-published - 本地流发布完成,此时事件中的 data 为 {@link LocalStream} 本地流
  808. * - mute-audio - 流的音频被 mute
  809. * - unmute-audio - 流的音频被取消 mute
  810. * - mute-video - 流的视频被 mute
  811. * - unmute-video - 流的视频被取消 mute
  812. * @public
  813. * @example
  814. * ```js
  815. * client.on('stream-add', (event) => {
  816. * client.subscribe(event.data);
  817. * });
  818. * ```
  819. *
  820. * **特别地,以下事件需在单条流上进行监听**
  821. * - screenshare-stopped - 屏幕共享流被中止,此时事件中的 data 为 {@link LocalStream} 本地流
  822. * - first-key-frame - 接收到远端流的首帧
  823. * @example
  824. * ```js
  825. * localStream.on('screenshare-stopped', (event) => {
  826. * // 此事件只针对本地流有效,若本地流已发布,监听到此事件后,可以决定要不要取消发布
  827. * client.unpublish(event.data);
  828. * event.data.destroy();
  829. * });
  830. * ```
  831. * @example
  832. * ```js
  833. * stream.on('first-key-frame', (event) => {
  834. * console.log(`stream ${event.data} got first key frame`);
  835. * });
  836. * ```
  837. */
  838. export type RtcStreamEventType = 'stream-added' | 'stream-removed' | 'stream-subscribed' | 'stream-published' | 'mute-audio' | 'unmute-audio' | 'mute-video' | 'unmute-video' | 'first-key-frame' | 'screenshare-stopped';
  839. /**
  840. * Rtc 播放器事件类型:
  841. *
  842. * {@link RtcPlayerEvent 播放器事件}
  843. * - player-status-change - 流播放器状态改变
  844. * **注,此事件需在单条流上进行监听**
  845. * @public
  846. * @example
  847. * ```js
  848. * stream.on('player-status-change', (event) => {
  849. * const { data } = event;
  850. * const { type, status } = data;
  851. * console.log(`stream's ${type} status changed to ${status}`);
  852. * });
  853. * ```
  854. */
  855. export type RtcPlayerEventType = 'player-status-change';
  856. /**
  857. * 播放状态改变事件对应数据
  858. * @public
  859. */
  860. interface PlayerEventData {
  861. /**
  862. * 类型,音频/视频
  863. */
  864. type: 'audio' | 'video';
  865. /**
  866. * 状态
  867. */
  868. status: 'playing' | 'paused';
  869. /**
  870. * 对应的流
  871. */
  872. stream: Stream;
  873. }
  874. /**
  875. * Rtc 客户端连接事件类型:
  876. *
  877. * {@link RtcConnectionEvent 连接事件}
  878. * - connection-state-changed - 连接状态改变
  879. * - network-quality - 上/下行网络质量
  880. * @public
  881. * @example
  882. * ```js
  883. * client.on('connection-state-changed', (event) => {
  884. * console.log(`连接状态:${event.data.previous} => ${event.data.current}`);
  885. * });
  886. * ```
  887. * ```js
  888. * client.on('network-quality', (event) => {
  889. * console.log(`上行 / 下行网络质量:${event.data.uplink} / ${event.data.downlink}`);
  890. * });
  891. * ```
  892. */
  893. export type RtcConnectionEventType = 'connection-state-changed' | 'network-quality';
  894. /**
  895. * Rtc 事件类型
  896. * @public
  897. */
  898. export type RtcEventType = RtcUserEventType | RtcStreamEventType | RtcConnectionEventType | RtcPlayerEventType;
  899. /**
  900. * Rtc 事件
  901. *
  902. * 当 type - T 为 {@link RtcUserEventType} 事件时,data - S 为 {@link User} 类型
  903. * 当 type - T 为 {@link RtcStreamEventType} 事件时,data - S 为 {@link LocalStream} | {@link RemoteStream} 类型
  904. * 当 type - T 为 {@link RtcConnectionEventType } 事件时,data - S 为 {@link ConnectionStates } 类型
  905. * @public
  906. */
  907. export interface RtcEvent<T, S> {
  908. type: T;
  909. data: S;
  910. }
  911. /**
  912. * Rtc 用户事件,事件类型参见 {@link RtcUserEventType}
  913. * @public
  914. */
  915. export type RtcUserEvent = RtcEvent<RtcUserEventType, User>;
  916. /**
  917. * Rtc 流事件,事件类型参见 {@link RtcStreamEventType}
  918. * @public
  919. */
  920. export type RtcStreamEvent = RtcEvent<RtcStreamEventType, Stream | LocalStream | RemoteStream>;
  921. /**
  922. * Rtc 连接事件,事件类型参见 {@link RtcConnectionEventType}
  923. * @public
  924. */
  925. export type RtcConnectionEvent = RtcEvent<RtcConnectionEventType, ConnectionStates | NetworkQualities>;
  926. /**
  927. * Rtc 连接事件,事件类型参见 {@link RtcPlayerEventType}
  928. * @public
  929. */
  930. export type RtcPlayerEvent = RtcEvent<RtcPlayerEventType, PlayerEventData>;
  931. export {};
  932. }
  933. declare module '__@urtc/sdk-web/error' {
  934. /**
  935. * RTC 错误信息
  936. * 错误代码参见 {@link ErrorCode}
  937. * @public
  938. */
  939. export class RtcError extends Error {
  940. constructor(code: ErrorCode, message: string);
  941. code: ErrorCode;
  942. toString(): string;
  943. /**
  944. * 1000 - 非法参数
  945. */
  946. static readonly INVALID_PARAMETER = "1000";
  947. /**
  948. * 1001 - 非法操作
  949. */
  950. static readonly INVALID_OPERATION = "1001";
  951. /**
  952. * 1002 - 不支持
  953. */
  954. static readonly NOT_SUPPORT = "1002";
  955. /**
  956. * 1003 - 不存在
  957. */
  958. static readonly NOT_EXISTS = "1003";
  959. /**
  960. * 1004 - 请求失败
  961. */
  962. static readonly BAD_REQUEST = "1004";
  963. /**
  964. * 1999 - 其他错误
  965. */
  966. static readonly OTHERS = "1999";
  967. /**
  968. * 2000 - 网关不可达
  969. */
  970. static readonly GW_UNREACHABLE = "2000";
  971. /**
  972. * 2001 - 获取 Access Token 失败
  973. */
  974. static readonly GET_ACCESS_TOKEN_FAILED = "2001";
  975. /**
  976. * 2002 - Access Token 非法
  977. */
  978. static readonly ACCESS_TOKEN_INVALID = "2002";
  979. /**
  980. * 2003 - Websocket 连接失败
  981. */
  982. static readonly CONNECTION_FAILED = "2003";
  983. /**
  984. * 2004 - 加入房间失败
  985. */
  986. static readonly JOIN_FAILED = "2004";
  987. /**
  988. * 2005 - 未加入房间
  989. */
  990. static readonly NOT_JOIN = "2005";
  991. /**
  992. * 2006 - 正在加入房间
  993. */
  994. static readonly IS_JOINING = "2006";
  995. /**
  996. * 2007 - 正在离开房间
  997. */
  998. static readonly IS_LEAVING = "2007";
  999. /**
  1000. * 2008 - 角色类型不匹配
  1001. */
  1002. static readonly ROLE_TYPE_NOT_MATCH = "2008";
  1003. /**
  1004. * 2009 - 信令服务器地址错误
  1005. */
  1006. static readonly SIGNAL_ADDRESS_INVALID = "2009";
  1007. /**
  1008. * 3000 - 流不存在
  1009. */
  1010. static readonly STREAM_NOT_EXISTS = "3000";
  1011. /**
  1012. * 3001 - 同类型的流已存在
  1013. */
  1014. static readonly STREAM_EXISTS = "3001";
  1015. /**
  1016. * 3002 - 音频不存在
  1017. */
  1018. static readonly AUDIO_NOT_EXISTS = "3002";
  1019. /**
  1020. * 3003 - 视频不存在
  1021. */
  1022. static readonly VIDEO_NOT_EXISTS = "3003";
  1023. /**
  1024. * 3004 - [中止错误] 尽管用户和操作系统都授予了访问设备硬件的权利,而且未出现可能抛出NotReadableError异常的硬件问题,但仍然有一些问题的出现导致了设备无法被使用。
  1025. */
  1026. static readonly ABORT_ERROR = "3004";
  1027. /**
  1028. * 3005 - [拒绝错误] 用户拒绝了当前的浏览器实例的访问请求;或者用户拒绝了当前会话的访问;或者用户在全局范围内拒绝了所有媒体访问请求。
  1029. */
  1030. static readonly NOT_ALLOWED_ERROR = "3005";
  1031. /**
  1032. * 3006 - [找不到错误] 找不到满足请求参数的媒体类型。
  1033. */
  1034. static readonly NOT_FOUND_ERROR = "3006";
  1035. /**
  1036. * 3007 - [无法读取错误] 尽管用户已经授权使用相应的设备,操作系统上某个硬件、浏览器或者网页层面发生的错误导致设备无法被访问。
  1037. */
  1038. static readonly NOT_READABLE_ERROR = "3007";
  1039. /**
  1040. * 3008 - [无法满足要求错误] 指定的要求无法被设备满足。
  1041. */
  1042. static readonly OVER_CONSTRAINED_ERROR = "3008";
  1043. /**
  1044. * 3009 - 流连接失败
  1045. */
  1046. static readonly PEERCONNECTION_FAILED = "3009";
  1047. /**
  1048. * 3010 - 流正在重连
  1049. */
  1050. static readonly IS_RECONNECTING = "3010";
  1051. /**
  1052. * 3011 - 流尚未发布
  1053. */
  1054. static readonly IS_UNPUBLISHED = "3011";
  1055. /**
  1056. * 3012 - 流正在发布
  1057. */
  1058. static readonly IS_PUBLISHING = "3012";
  1059. /**
  1060. * 3013 - 流正在取消发布
  1061. */
  1062. static readonly IS_UNPUBLISHING = "3013";
  1063. /**
  1064. * 3014 - 流已经发布
  1065. */
  1066. static readonly IS_PUBLISHED = "3014";
  1067. /**
  1068. * 3015 - 流尚未订阅
  1069. */
  1070. static readonly IS_UNSUBSCRIBED = "3015";
  1071. /**
  1072. * 3016 - 流正在订阅
  1073. */
  1074. static readonly IS_SUBSCRIBING = "3016";
  1075. /**
  1076. * 3017 - 流正在取消订阅
  1077. */
  1078. static readonly IS_UNSUBSCRIBING = "3017";
  1079. /**
  1080. * 3018 - 流已经订阅
  1081. */
  1082. static readonly IS_SUBSCRIBED = "3018";
  1083. /**
  1084. * 3019 - 自动播放被禁止错误
  1085. */
  1086. static readonly PLAY_NOT_ALLOWED = "3019";
  1087. /**
  1088. * 3020 - 视频数据异常,未成功播放
  1089. */
  1090. static readonly PLAY_PENDING = "3020";
  1091. /**
  1092. * 3021 - 因未曾调用或调用 play 方法失败,故不可恢复播放
  1093. */
  1094. static readonly RESUME_NOT_ALLOWED = "3021";
  1095. }
  1096. /**
  1097. * RTC 错误代码
  1098. *
  1099. * 通用错误及代码
  1100. * - 1000 - 非法参数
  1101. * - 1001 - 非法操作
  1102. * - 1002 - 不支持
  1103. * - 1003 - 不存在
  1104. * - 1004 - 请求失败
  1105. * - 1999 - 其他错误
  1106. *
  1107. * 房间相关错误及代码
  1108. * - 2000 - 网关不可达
  1109. * - 2001 - 获取 Access Token 失败
  1110. * - 2002 - Access Token 非法
  1111. * - 2003 - Websocket 连接失败
  1112. * - 2004 - 加入房间失败
  1113. * - 2005 - 未加入房间
  1114. * - 2006 - 正在加入房间
  1115. * - 2007 - 正在离开房间
  1116. * - 2008 - 角色类型不匹配
  1117. * - 2009 - 信令服务器地址错误
  1118. *
  1119. * 流相关错误及代码
  1120. * - 3000 - 流不存在
  1121. * - 3001 - 同类型的流已存在
  1122. * - 3002 - 音频不存在
  1123. * - 3003 - 视频不存在
  1124. * - 3004 - [中止错误] 尽管用户和操作系统都授予了访问设备硬件的权利,而且未出现可能抛出NotReadableError异常的硬件问题,但仍然有一些问题的出现导致了设备无法被使用。
  1125. * - 3005 - [拒绝错误] 用户拒绝了当前的浏览器实例的访问请求;或者用户拒绝了当前会话的访问;或者用户在全局范围内拒绝了所有媒体访问请求。
  1126. * - 3006 - [找不到错误] 找不到满足请求参数的媒体类型。
  1127. * - 3007 - [无法读取错误] 尽管用户已经授权使用相应的设备,操作系统上某个硬件、浏览器或者网页层面发生的错误导致设备无法被访问。
  1128. * - 3008 - [无法满足要求错误] 指定的要求无法被设备满足。
  1129. * - 3009 - 流连接失败
  1130. * - 3010 - 流正在重连
  1131. * - 3011 - 流尚未发布
  1132. * - 3012 - 流正在发布
  1133. * - 3013 - 流正在取消发布
  1134. * - 3014 - 流已经发布
  1135. * - 3015 - 流尚未订阅
  1136. * - 3016 - 流正在订阅
  1137. * - 3017 - 流正在取消订阅
  1138. * - 3018 - 流已经订阅
  1139. * - 3019 - 自动播放被禁止错误
  1140. * - 3020 - 视频数据异常,未成功播放
  1141. * - 3021 - 因未曾调用或调用 play 方法失败,故不可恢复播放
  1142. * @public
  1143. */
  1144. export type ErrorCode = typeof RtcError[Exclude<keyof typeof RtcError, 'prototype' | 'getCode' | 'stackTraceLimit' | 'prepareStackTrace' | 'captureStackTrace'>];
  1145. }
  1146. declare module '__@urtc/sdk-web/user/user' {
  1147. /**
  1148. * 用户信息
  1149. * @public
  1150. */
  1151. export class User {
  1152. /**
  1153. * 用户ID
  1154. */
  1155. id: string;
  1156. }
  1157. }
  1158. declare module '__@urtc/sdk-web/stream/types' {
  1159. /**
  1160. * 音频编解码格式
  1161. * @public
  1162. */
  1163. export type AudioCodec = 'opus';
  1164. /**
  1165. * 视频编解码格式
  1166. * @public
  1167. * @note 'h265' 目前仅部分浏览器在开启试验性功能时才支持,如 Safari 开启 `WebRTC H265 codec`
  1168. */
  1169. export type VideoCodec = 'vp8' | 'h264' | 'h265';
  1170. /**
  1171. * 流的音频的统计数据
  1172. * @public
  1173. */
  1174. export interface AudioStats {
  1175. /**
  1176. * 音频码率
  1177. */
  1178. bitrate: number;
  1179. /**
  1180. * 音频丢包率
  1181. */
  1182. packetLossRate: number;
  1183. /**
  1184. * 音频音量
  1185. */
  1186. volume: number;
  1187. /**
  1188. * 音频编码格式
  1189. */
  1190. codec: AudioCodec;
  1191. }
  1192. /**
  1193. * 流的视频的统计数据
  1194. * @public
  1195. */
  1196. export interface VideoStats {
  1197. /**
  1198. * 视频码率
  1199. */
  1200. bitrate: number;
  1201. /**
  1202. * 视频丢包率
  1203. */
  1204. packetLossRate: number;
  1205. /**
  1206. * 视频帧率
  1207. */
  1208. framerate: number;
  1209. /**
  1210. * 视频宽
  1211. */
  1212. width: number;
  1213. /**
  1214. * 视频高
  1215. */
  1216. height: number;
  1217. /**
  1218. * 视频编码格式
  1219. */
  1220. codec: VideoCodec;
  1221. }
  1222. /**
  1223. * 流的网络连接统计数据
  1224. * @public
  1225. */
  1226. export interface NetworkStats {
  1227. /**
  1228. * 网络往返时间
  1229. */
  1230. rtt: number;
  1231. }
  1232. /**
  1233. * 已发布/已订阅流的统计数据
  1234. * @public
  1235. */
  1236. export interface StreamStats {
  1237. /**
  1238. * 流包含音频时,音频统计数据
  1239. */
  1240. audio?: AudioStats;
  1241. /**
  1242. * 流包含视频时,视频统计数据
  1243. */
  1244. video?: VideoStats;
  1245. /**
  1246. * 流的网络连接统计数据
  1247. */
  1248. network?: NetworkStats;
  1249. }
  1250. /**
  1251. * 流的媒体类型, main - 主视频流,screen - 辅助视频流,通常是一个屏幕分享流
  1252. * @public
  1253. */
  1254. export type MediaType = 'camera' | 'screen';
  1255. /**
  1256. * 切换设备的类型
  1257. * @public
  1258. */
  1259. export type SwitchDeviceType = 'audio' | 'video';
  1260. /**
  1261. * 流的网络质量评分,有 '0' | '1' | '2' | '3' | '4' | '5' | '6'
  1262. * - '0': 网络质量未知
  1263. * - '1': 网络质量优秀
  1264. * - '2': 网络质量良好
  1265. * - '3': 网络质量一般
  1266. * - '4': 网络质量较差
  1267. * - '5': 网络质量糟糕
  1268. * - '6': 网络连接断开
  1269. * @public
  1270. */
  1271. export type NetworkQuality = '0' | '1' | '2' | '3' | '4' | '5' | '6';
  1272. /**
  1273. * 推(上行)/拉(下行)流的网络质量
  1274. * @public
  1275. */
  1276. export interface NetworkQualities {
  1277. /**
  1278. * 推(上行)流的网络质量
  1279. */
  1280. uplink: NetworkQuality;
  1281. /**
  1282. * 拉(下行)流的网络质量
  1283. */
  1284. downlink: NetworkQuality;
  1285. }
  1286. }
  1287. declare module '__@urtc/sdk-web/stream/stream' {
  1288. import { EventEmitter } from '__@urtc/sdk-web/event-emitter';
  1289. import { PlayOptions, SnapshotOptions } from '__@urtc/sdk-web/types';
  1290. import { MediaType, StreamStats } from '__@urtc/sdk-web/stream/types';
  1291. /**
  1292. * LocalStream 和 RemoteStream 的基类
  1293. * @public
  1294. */
  1295. export class Stream extends EventEmitter {
  1296. /**
  1297. * 当前流ID
  1298. */
  1299. id: string;
  1300. /**
  1301. * 当前流所属用户的ID
  1302. * 注:若创建本地流时指定的 userId 与 join 时指定的 userId 不同,那么发布本条流时,流的 userId 将会自动被自动更新为 join 时指定的 userId
  1303. */
  1304. userId: string;
  1305. /**
  1306. * 当前流包含的媒体流,关于媒体流,请详见 [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream)。
  1307. */
  1308. readonly mediaStream: MediaStream;
  1309. /**
  1310. * 获取流的媒体类型
  1311. * @example
  1312. * ```js
  1313. * const type = stream.getMediaType();
  1314. * ```
  1315. */
  1316. getMediaType(): MediaType;
  1317. /**
  1318. * 当前流是否 mute 了音频
  1319. */
  1320. audioMuted: boolean;
  1321. /**
  1322. * 当前流是否 mute 了视频
  1323. */
  1324. videoMuted: boolean;
  1325. /**
  1326. * 判断当前流是否有音频
  1327. * @example
  1328. * ```js
  1329. * const result = stream.hasAudio();
  1330. * ```
  1331. */
  1332. hasAudio(): boolean;
  1333. /**
  1334. * 判断当前流是否有视频
  1335. * @example
  1336. * ```js
  1337. * const result = stream.hasVideo();
  1338. * ```
  1339. */
  1340. hasVideo(): boolean;
  1341. /**
  1342. * mute 当前流的音频
  1343. * * 本地流调用此方法时,将不向服务器推送音频数据,远端用户将收到 `mute-audio` 的事件通知
  1344. * * 远端流调用此方法时,仅为不从服务器拉取音频数据,并无事件通知远端用户
  1345. * @example
  1346. * ```js
  1347. * const result = stream.muteAudio();
  1348. * console.log(`stream'audio is muted ${stream.audioMuted}`);
  1349. * ```
  1350. * @returns 操作是否成功
  1351. */
  1352. muteAudio(): boolean;
  1353. /**
  1354. * unmute 当前流的音频
  1355. * * 本地流调用此方法时,将向服务器推送音频数据,远端用户将收到 `unmute-audio` 的事件通知
  1356. * * 远端流调用此方法时,会从服务器拉取音频数据,并无事件通知远端用户
  1357. * @example
  1358. * ```js
  1359. * const result = stream.unmuteAudio();
  1360. * console.log(`stream's audio is muted ${stream.audioMuted}`);
  1361. * ```
  1362. * @returns 操作是否成功
  1363. */
  1364. unmuteAudio(): boolean;
  1365. /**
  1366. * mute 当前流的视频
  1367. * * 本地流调用此方法时,将不向服务器推送视频数据,远端用户将收到 `mute-video` 的事件通知
  1368. * * 远端流调用此方法时,仅为不从服务器拉取视频数据,并无事件通知远端用户
  1369. * @example
  1370. * ```js
  1371. * const result = stream.muteVideo();
  1372. * console.log(`stream's video is muted ${stream.videoMuted}`);
  1373. * ```
  1374. * @returns 操作是否成功
  1375. */
  1376. muteVideo(): boolean;
  1377. /**
  1378. * unmute 当前流的视频
  1379. * * 本地流调用此方法时,将向服务器推送视频数据,远端用户将收到 `unmute-video` 的事件通知
  1380. * * 远端流调用此方法时,会从服务器拉取视频数据,并无事件通知远端用户
  1381. * @example
  1382. * ```js
  1383. * const result = stream.unmuteVideo();
  1384. * console.log(`stream's video is muted ${stream.videoMuted}`);
  1385. * ```
  1386. * @returns 操作是否成功
  1387. */
  1388. unmuteVideo(): boolean;
  1389. /**
  1390. * 播放当前流
  1391. * @param container - 播放音视频时,包裹 video 标签所用的容器元素或容器元素的 ID
  1392. * @param opts - 其他播放参数,参见{@link PlayOptions}
  1393. * @example
  1394. * ```js
  1395. * const container = 'xxx'; // 比如 id 为 xxx 的 div 元素
  1396. * stream
  1397. * .play(container)
  1398. * .catch((err) => {
  1399. * console.log(`播放失败: ${err}`); // 一般由于浏览器对自动播放的限制导致播放失败
  1400. * });
  1401. * ```
  1402. * @reject {@link RtcError}
  1403. */
  1404. play(container: HTMLElement | string, opts?: PlayOptions): Promise<void>;
  1405. /**
  1406. * 恢复播放流,一般由于浏览器限制无法自动播放时,可提示用户手动触发该方法进行恢复播放
  1407. * @example
  1408. * ```js
  1409. * stream
  1410. * .resume()
  1411. * .catch((err) => {
  1412. * console.log(`恢复播放失败:${err}`);
  1413. * });
  1414. * ```
  1415. */
  1416. resume(): Promise<void>;
  1417. /**
  1418. * 停止播放当前流
  1419. * @example
  1420. * ```js
  1421. * stream.stop();
  1422. * ```
  1423. */
  1424. stop(): void;
  1425. /**
  1426. * 获取当前流的音量大小,只有当本地流或远端流中有音频数据才有效。
  1427. * @example
  1428. * ```js
  1429. * setInterval(() => {
  1430. * const level = stream.getAudioLevel();
  1431. * if (level > 0) {
  1432. * console.log(`user ${stream.userId} is speaking`);
  1433. * }
  1434. * }, 200);
  1435. * ```
  1436. */
  1437. getAudioLevel(): number;
  1438. /**
  1439. * 销毁当前流,一般在本地流不再被使用时,可调用此方法销毁,解除摄像头或麦克风设备的占用。
  1440. * 注:远端流,不需要手动调用此方法
  1441. * @example
  1442. * ```js
  1443. * stream.destroy();
  1444. * ```
  1445. */
  1446. destroy(): void;
  1447. /**
  1448. * 获取流发布或订阅后的统计数据
  1449. * @example
  1450. * ```js
  1451. * stream
  1452. * .getStats()
  1453. * .then((stats) => {
  1454. * console.log('当前流的统计数据为: ', stats);
  1455. * });
  1456. * ```
  1457. */
  1458. getStats(): Promise<StreamStats>;
  1459. /**
  1460. * 对当前流进行截屏,可用于页面展示或下载保存
  1461. * @param opts - 截屏参数,选传,参见{@link SnapshotOptions}
  1462. * @example
  1463. * ```js
  1464. * stream.snapshot({filename: 'xxx.jpg'})
  1465. * .then((pic) => {
  1466. * console.log('截屏图像', pic);
  1467. * })
  1468. * .catch((err) => {
  1469. * console.log('截屏失败', err);
  1470. * });
  1471. * ```
  1472. */
  1473. snapshot(opts?: SnapshotOptions): Promise<string>;
  1474. }
  1475. }
  1476. declare module '__@urtc/sdk-web/stream/remote-stream' {
  1477. import { Stream } from '__@urtc/sdk-web/stream/stream';
  1478. import { StreamPlugin } from '__@urtc/sdk-web/plugin';
  1479. /**
  1480. * 远端流,房间内其他用户发布的流,可通过 client 进行订阅
  1481. * @public
  1482. */
  1483. export class RemoteStream extends Stream {
  1484. /**
  1485. * 加载流插件,使用插件功能
  1486. * @param plugin - 插件
  1487. * @param options - 插件初始化参数
  1488. */
  1489. static use(plugin: StreamPlugin, options?: any): void;
  1490. /**
  1491. * 音频源是否已 mute,当源端 mute/unmute 音频时,本端将收到 `mute-audio` 或 `unmute-audio` 事件的通知,同时此值将变为对应值
  1492. */
  1493. sourceAudioMuted: boolean;
  1494. /**
  1495. * 视频源是否已 mute,当源端 mute/unmute 视频时,本端将收到 `mute-video` 或 `unmute-video` 事件的通知,同时此值将变为对应值
  1496. */
  1497. sourceVideoMuted: boolean;
  1498. /**
  1499. * 设置输出音量,默认为 100
  1500. * @param volume - 音量大小, 可设范围[0-100]
  1501. * @throws RtcError
  1502. * @example
  1503. * ```js
  1504. * stream.setAudioVolume(50);
  1505. * ```
  1506. */
  1507. setAudioVolume(volume: number): void;
  1508. }
  1509. }
  1510. declare module '__@urtc/sdk-web/connection/types' {
  1511. /**
  1512. * 连接状态类型:
  1513. * - OPEN - 已连接
  1514. * - CONNECTING - 连接中
  1515. * - CLOSING - 断开中
  1516. * - RECONNECTING - 重连中
  1517. * - CLOSED - 已断开
  1518. * @public
  1519. */
  1520. export type ConnectionState = 'OPEN' | 'CONNECTING' | 'CLOSING' | 'RECONNECTING' | 'CLOSED';
  1521. /**
  1522. * 客户端(Client)与服务器之间的{@link ConnectionState 连接状态}
  1523. * @public
  1524. */
  1525. export interface ConnectionStates {
  1526. /**
  1527. * 当前连接状态
  1528. */
  1529. current: ConnectionState;
  1530. /**
  1531. * 之前连接状态
  1532. */
  1533. previous: ConnectionState;
  1534. }
  1535. }
  1536. declare module '__@urtc/sdk-web/server' {
  1537. /**
  1538. * 服务器配置,可设置置网关(gateway)、信令(signal)、日志(log)服务器地址
  1539. * 注:
  1540. * 1. gateway 和 signal 须二选一进行设置
  1541. * 2. 没有日志服务器时,log 可不设
  1542. * @public
  1543. */
  1544. export interface ServerConfig {
  1545. /**
  1546. * 网关地址,如 'https://my-rtc.com.cn'
  1547. */
  1548. gateway?: string;
  1549. /**
  1550. * 信令服务器地址,如 'wss://my-rtc.com.cn:5005'
  1551. */
  1552. signal?: string;
  1553. /**
  1554. * 日志服务器地址,如 'https://log.my-rtc.com.cn'
  1555. */
  1556. log?: string;
  1557. }
  1558. /**
  1559. * 用于私有化部署时,指定部署的服务器地址
  1560. * @param conf - 服务器配置,具体描述参见 ServerConfig 的说明
  1561. * @public
  1562. * @example
  1563. * ```js
  1564. * setServers({
  1565. * gateway: 'https://my-rtc.com', // 指定网关
  1566. * log: 'https://log.my-rtc.com', // 指定日志服务器
  1567. * });
  1568. * ```
  1569. *
  1570. * **特别地,单信令服务器时,不需要网关进行分配信令服务器,可以直接指定信令服务器**
  1571. * ```js
  1572. * setServers({
  1573. * signal: 'wss://my-rtc.com:5005', // 直接指定信令服务器
  1574. * log: 'https://log.my-rtc.com', // 指定日志服务器
  1575. * });
  1576. * ```
  1577. * @throws {@link RtcError}
  1578. */
  1579. export function setServers(conf: ServerConfig): void;
  1580. }
  1581. declare module '__@urtc/sdk-web/plugin' {
  1582. /**
  1583. * @public
  1584. */
  1585. export interface StreamPlugin {
  1586. name: string;
  1587. install: Function;
  1588. }
  1589. /**
  1590. * @public
  1591. */
  1592. export interface ClientPlugin {
  1593. name: string;
  1594. install: Function;
  1595. }
  1596. }
  1597. declare module '__@urtc/sdk-web/version' {
  1598. /**
  1599. * 当前 sdk 的版本号
  1600. * @public
  1601. */
  1602. export const version: string;
  1603. }
  1604. declare module '__@urtc/sdk-web/event-emitter' {
  1605. import { RtcEventType, RtcUserEventType, RtcUserEvent, RtcStreamEvent, RtcConnectionEventType, RtcConnectionEvent, RtcStreamEventType, RtcPlayerEventType, RtcPlayerEvent } from '__@urtc/sdk-web/event';
  1606. /**
  1607. * 事件监听函数
  1608. * 其中 T 为 RtcEvent 泛型
  1609. * @private
  1610. */
  1611. export type RtcEventInstance<T> = T extends RtcUserEventType ? RtcUserEvent : T extends RtcStreamEventType ? RtcStreamEvent : T extends RtcConnectionEventType ? RtcConnectionEvent : T extends RtcPlayerEventType ? RtcPlayerEvent : never;
  1612. /**
  1613. * 事件监听函数
  1614. * 其中 RtcEventInstance 为事件实例
  1615. * > 注:使用 typescript 时,会根据 T {@link RtcEventType} 类型自动推断 {@link RtcEvent} 的类型。
  1616. */
  1617. export interface Listener<T> {
  1618. (event: RtcEventInstance<T>): void;
  1619. }
  1620. /**
  1621. * @private
  1622. */
  1623. export class EventEmitter {
  1624. /**
  1625. * 监听流对象事件
  1626. * @param type - 流事件类型
  1627. * @param listener - 流事件监听函数
  1628. */
  1629. on<T extends RtcEventType>(type: T, listener: Listener<T>): EventEmitter;
  1630. /**
  1631. * 取消监听流对象事件
  1632. * @param type - 流对象事件类型,特别的,当为 '*' 时,取消监听所有事件
  1633. * @param listener - 流对象事件监听函数
  1634. */
  1635. off<T extends RtcEventType | '*'>(type: T, listener: Listener<T>): EventEmitter;
  1636. }
  1637. }
  1638. declare module '__@urtc/sdk-web/stream/profile' {
  1639. /**
  1640. * 预设的视频 Profile
  1641. *
  1642. * 名称 | 视频宽 | 视频高 | 帧率 (fps) | 码率 (kbps)
  1643. * :-: | :-: | :-: | :-: | :-:
  1644. * 180p | 240 | 180 | 15 | 200
  1645. * 180p_2 | 320 | 180 | 15 | 300
  1646. * 240p | 320 | 240 | 15 | 400
  1647. * 360p | 480 | 360 | 15 | 400
  1648. * 360p_2 | 640 | 360 | 15 | 500
  1649. * 480p | 640 | 480 | 15 | 600
  1650. * 720p | 1280 | 720 | 15 | 1000
  1651. * 720p_2 | 1280 | 720 | 15 | 1500
  1652. * 720p_3 | 1280 | 720 | 30 | 2000
  1653. * 1080p | 1920 | 1080 | 15 | 1500
  1654. * 1080p_2 | 1920 | 1080 | 15 | 2000
  1655. * 1080p_3 | 1920 | 1080 | 30 | 2500
  1656. */
  1657. export type VideoProfile = '180p' | '180p_2' | '240p' | '360p' | '360p_2' | '480p' | '720p' | '720p_2' | '720p_3' | '1080p' | '1080p_2' | '1080p_3';
  1658. /**
  1659. * 预设的屏幕共享视频 Profile
  1660. *
  1661. * 名称 | 视频宽 | 视频高 | 帧率 (fps) | 码率 (kbps)
  1662. * :-: | :-: | :-: | :-: | :-:
  1663. * 480p | 640 | 480 | 5 | 600
  1664. * 480p_2 | 640 | 480 | 30 | 1000
  1665. * 720p | 1280 | 720 | 5 | 1000
  1666. * 720p_2 | 1280 | 720 | 30 | 2000
  1667. * 1080p | 1920 | 1080 | 5 | 1500
  1668. * 1080p_2 | 1920 | 1080 | 30 | 2500
  1669. */
  1670. export type ScreenProfile = '480p' | '480p_2' | '720p' | '720p_2' | '1080p' | '1080p_2';
  1671. /**
  1672. * 自定义视频 Profile,请根据实际使用场景及网络环境,合理的设置
  1673. * @public
  1674. * @example
  1675. * ```js
  1676. * { width: 640, height: 480, framerate: 15, bitrate: 500 }
  1677. * ```
  1678. */
  1679. export interface CustomVideoProfile {
  1680. /**
  1681. * 视频宽,如:640
  1682. */
  1683. width: number;
  1684. /**
  1685. * 视频高,如:480
  1686. */
  1687. height: number;
  1688. /**
  1689. * 帧率 (fps),如:15
  1690. */
  1691. framerate: number;
  1692. /**
  1693. * 码率 (kbps),如:500
  1694. */
  1695. bitrate: number;
  1696. }
  1697. }