index.d.ts 49 KB

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