index.d.ts 49 KB

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