index.d.ts 50 KB

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