index.d.ts 56 KB

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