index.d.ts 53 KB

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