index.d.ts 57 KB

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