index.d.ts 58 KB

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