index.d.ts 54 KB

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