index.d.ts 43 KB

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