index.d.ts 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789
  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, CustomVideoProfile } 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. * - audio-track-ended - 音频被中止,此时事件中的 data 为 {@link LocalStream} 本地流
  869. * - first-key-frame - 接收到远端流的首帧
  870. * @example
  871. * ```js
  872. * localStream.on('screen-sharing-stopped', (event) => {
  873. * // 此事件只针对本地流有效,若本地流已发布,监听到此事件后,可以决定要不要取消发布
  874. * client.unpublish(event.data);
  875. * event.data.destroy();
  876. * });
  877. * ```
  878. * @example
  879. * ```js
  880. * stream.on('first-key-frame', (event) => {
  881. * console.log(`stream ${event.data} got first key frame`);
  882. * });
  883. * ```
  884. */
  885. 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' | 'audio-track-ended' | 'screen-sharing-stopped';
  886. /**
  887. * Rtc 播放器事件类型:
  888. *
  889. * {@link RtcPlayerEvent 播放器事件}
  890. * - player-status-change - 流播放器状态改变
  891. * **注,此事件需在单条流上进行监听**
  892. * @public
  893. * @example
  894. * ```js
  895. * stream.on('player-status-change', (event) => {
  896. * const { data } = event;
  897. * const { type, status } = data;
  898. * console.log(`stream's ${type} status changed to ${status}`);
  899. * });
  900. * ```
  901. */
  902. export type RtcPlayerEventType = 'player-status-change';
  903. /**
  904. * 播放状态改变事件对应数据
  905. * @public
  906. */
  907. export interface PlayerEventData {
  908. /**
  909. * 类型,音频/视频
  910. */
  911. type: 'audio' | 'video';
  912. /**
  913. * 状态
  914. */
  915. status: 'playing' | 'paused';
  916. /**
  917. * 对应的流
  918. */
  919. stream: Stream;
  920. }
  921. /**
  922. * Rtc 客户端连接状态事件类型:
  923. *
  924. * {@link RtcConnectionStateEvent 连接状态事件}
  925. * - connection-state-changed - 连接状态改变
  926. * @public
  927. * @example
  928. * ```js
  929. * client.on('connection-state-changed', (event) => {
  930. * console.log(`连接状态:${event.data.previous} => ${event.data.current}`);
  931. * });
  932. * ```
  933. */
  934. export type RtcConnectionStateEventType = 'connection-state-changed';
  935. /**
  936. * Rtc 网络连接质量类型:
  937. *
  938. * {@link RtcNetworkQualityEvent 网络连接质量事件}
  939. * - network-quality - 上/下行网络质量
  940. * @public
  941. * @example
  942. * ```js
  943. * client.on('network-quality', (event) => {
  944. * console.log(`上行 / 下行网络质量:${event.data.uplink} / ${event.data.downlink}`);
  945. * });
  946. * ```
  947. */
  948. export type RtcNetworkQualityEventType = 'network-quality';
  949. /**
  950. * 设备变化事件
  951. * - device-changed - 设备变化(新增或移除)
  952. * @public
  953. * @example
  954. * ```js
  955. * client.on('device-changed', (event) => {
  956. * console.log(`${event.data.type} 设备已 ${event.data.status}`);
  957. * });
  958. * ```
  959. */
  960. export type RtcDeviceChangedEventType = 'device-changed';
  961. /**
  962. * 设备变化事件对应数据
  963. * @public
  964. */
  965. export interface DeviceChangedEventData {
  966. /**
  967. * 设备类型,麦克风/摄像头/扬声器
  968. */
  969. type: 'microphone' | 'camera' | 'loudspeaker';
  970. /**
  971. * 状态
  972. */
  973. status: 'remove' | 'add';
  974. /**
  975. * 对应的设备信息
  976. */
  977. device: MediaDeviceInfo;
  978. }
  979. /**
  980. * 错误事件
  981. * - error - 错误事件,当出现不可恢复错误后,会抛出此事件
  982. * @public
  983. * @example
  984. * ```js
  985. * client.on('error', (event) => {
  986. * console.log(`错误[${event.data.code}] - ${event.data.message}`);
  987. * });
  988. * ```
  989. */
  990. export type RtcErrorEventType = 'error';
  991. /**
  992. * Rtc 事件类型
  993. * @public
  994. */
  995. export type RtcEventType = RtcUserEventType | RtcStreamEventType | RtcConnectionStateEventType | RtcNetworkQualityEventType | RtcPlayerEventType | RtcDeviceChangedEventType | RtcErrorEventType;
  996. /**
  997. * Rtc 事件
  998. *
  999. * - 当 type - T 为 {@link RtcUserEventType} 事件时,data - S 为 {@link User} 类型
  1000. * - 当 type - T 为 {@link RtcStreamEventType} 事件时,data - S 为 {@link LocalStream} 或 {@link RemoteStream} 类型
  1001. * - 当 type - T 为 {@link RtcConnectionStateEventType} 事件时,data - S 为 {@link ConnectionStates} 类型
  1002. * - 当 type - T 为 {@link RtcNetworkQualityEventType} 事件时,data - S 为 {@link NetworkQualities} 类型
  1003. * - 当 type - T 为 {@link RtcPlayerEventType} 事件时,data - S 为 {@link PlayerEventData} 类型
  1004. * - 当 type - T 为 {@link RtcDeviceChangedEventType} 事件时,data - S 为 {@link DeviceChangedEventData} 类型
  1005. * - 当 type - T 为 {@link RtcErrorEventType} 事件时,data - S 为 {@link RtcError} 类型
  1006. * @public
  1007. */
  1008. export interface RtcEvent<T, S> {
  1009. type: T;
  1010. data: S;
  1011. }
  1012. /**
  1013. * Rtc 用户事件,事件类型参见 {@link RtcUserEventType}
  1014. * @public
  1015. */
  1016. export type RtcUserEvent = RtcEvent<RtcUserEventType, User>;
  1017. /**
  1018. * Rtc 流事件,事件类型参见 {@link RtcStreamEventType}
  1019. * @public
  1020. */
  1021. export type RtcStreamEvent = RtcEvent<RtcStreamEventType, Stream | LocalStream | RemoteStream>;
  1022. /**
  1023. * Rtc 连接状态事件,事件类型参见 {@link RtcConnectionStateEventType}
  1024. * @public
  1025. */
  1026. export type RtcConnectionStateEvent = RtcEvent<RtcConnectionStateEventType, ConnectionStates>;
  1027. /**
  1028. * Rtc 网络连接质量事件,事件类型参见 {@link RtcNetworkQualityEventType}
  1029. * @public
  1030. */
  1031. export type RtcNetworkQualityEvent = RtcEvent<RtcNetworkQualityEventType, NetworkQualities>;
  1032. /**
  1033. * Rtc 播放器事件,事件类型参见 {@link RtcPlayerEventType}
  1034. * @public
  1035. */
  1036. export type RtcPlayerEvent = RtcEvent<RtcPlayerEventType, PlayerEventData>;
  1037. /**
  1038. * Rtc 设备列表变化事件,事件类型参见 {@link RtcDeviceChangeEventType}
  1039. * @public
  1040. */
  1041. export type RtcDeviceChangedEvent = RtcEvent<RtcDeviceChangedEventType, DeviceChangedEventData>;
  1042. /**
  1043. * Rtc 错误事件,事件类型参见 {@link RtcErrorEventType}
  1044. * @public
  1045. */
  1046. export type RtcErrorEvent = RtcEvent<RtcErrorEventType, RtcError>;
  1047. }
  1048. declare module '__@urtc/sdk-web/error' {
  1049. /**
  1050. * RTC 错误信息
  1051. * 错误代码参见 {@link ErrorCode}
  1052. * @public
  1053. */
  1054. export class RtcError extends Error {
  1055. constructor(code: ErrorCode, message: string);
  1056. /**
  1057. * 错误码,参见 {@link ErrorCode}
  1058. */
  1059. code: ErrorCode;
  1060. /**
  1061. * 1000 - 非法参数
  1062. */
  1063. static readonly INVALID_PARAMETER = "1000";
  1064. /**
  1065. * 1001 - 非法操作
  1066. */
  1067. static readonly INVALID_OPERATION = "1001";
  1068. /**
  1069. * 1002 - 不支持
  1070. */
  1071. static readonly NOT_SUPPORT = "1002";
  1072. /**
  1073. * 1003 - 不存在
  1074. */
  1075. static readonly NOT_EXISTS = "1003";
  1076. /**
  1077. * 1004 - 请求失败
  1078. */
  1079. static readonly BAD_REQUEST = "1004";
  1080. /**
  1081. * 1999 - 其他错误
  1082. */
  1083. static readonly OTHERS = "1999";
  1084. /**
  1085. * 2000 - 网关不可达
  1086. */
  1087. static readonly GW_UNREACHABLE = "2000";
  1088. /**
  1089. * 2001 - 获取 Access Token 失败
  1090. */
  1091. static readonly GET_ACCESS_TOKEN_FAILED = "2001";
  1092. /**
  1093. * 2002 - Access Token 非法
  1094. */
  1095. static readonly ACCESS_TOKEN_INVALID = "2002";
  1096. /**
  1097. * 2003 - Websocket 连接失败
  1098. */
  1099. static readonly CONNECTION_FAILED = "2003";
  1100. /**
  1101. * 2004 - 加入房间失败
  1102. */
  1103. static readonly JOIN_FAILED = "2004";
  1104. /**
  1105. * 2005 - 未加入房间
  1106. */
  1107. static readonly NOT_JOIN = "2005";
  1108. /**
  1109. * 2006 - 正在加入房间
  1110. */
  1111. static readonly IS_JOINING = "2006";
  1112. /**
  1113. * 2007 - 正在离开房间
  1114. */
  1115. static readonly IS_LEAVING = "2007";
  1116. /**
  1117. * 2008 - 角色类型不匹配
  1118. */
  1119. static readonly ROLE_TYPE_NOT_MATCH = "2008";
  1120. /**
  1121. * 2009 - 信令服务器地址错误
  1122. */
  1123. static readonly SIGNAL_ADDRESS_INVALID = "2009";
  1124. /**
  1125. * 3000 - 流不存在
  1126. */
  1127. static readonly STREAM_NOT_EXISTS = "3000";
  1128. /**
  1129. * 3001 - 同类型的流已存在
  1130. */
  1131. static readonly STREAM_EXISTS = "3001";
  1132. /**
  1133. * 3002 - 音频不存在
  1134. */
  1135. static readonly AUDIO_NOT_EXISTS = "3002";
  1136. /**
  1137. * 3003 - 视频不存在
  1138. */
  1139. static readonly VIDEO_NOT_EXISTS = "3003";
  1140. /**
  1141. * 3004 - [中止错误] 尽管用户和操作系统都授予了访问设备硬件的权利,而且未出现可能抛出NotReadableError异常的硬件问题,但仍然有一些问题的出现导致了设备无法被使用。
  1142. */
  1143. static readonly ABORT_ERROR = "3004";
  1144. /**
  1145. * 3005 - [拒绝错误] 用户拒绝了当前的浏览器实例的访问请求;或者用户拒绝了当前会话的访问;或者用户在全局范围内拒绝了所有媒体访问请求。
  1146. */
  1147. static readonly NOT_ALLOWED_ERROR = "3005";
  1148. /**
  1149. * 3006 - [找不到错误] 找不到满足请求参数的媒体类型。
  1150. */
  1151. static readonly NOT_FOUND_ERROR = "3006";
  1152. /**
  1153. * 3007 - [无法读取错误] 尽管用户已经授权使用相应的设备,操作系统上某个硬件、浏览器或者网页层面发生的错误导致设备无法被访问。
  1154. */
  1155. static readonly NOT_READABLE_ERROR = "3007";
  1156. /**
  1157. * 3008 - [无法满足要求错误] 指定的要求无法被设备满足。
  1158. */
  1159. static readonly OVER_CONSTRAINED_ERROR = "3008";
  1160. /**
  1161. * 3009 - 流连接失败
  1162. */
  1163. static readonly PEERCONNECTION_FAILED = "3009";
  1164. /**
  1165. * 3010 - 流正在重连
  1166. */
  1167. static readonly IS_RECONNECTING = "3010";
  1168. /**
  1169. * 3011 - 流尚未发布
  1170. */
  1171. static readonly IS_UNPUBLISHED = "3011";
  1172. /**
  1173. * 3012 - 流正在发布
  1174. */
  1175. static readonly IS_PUBLISHING = "3012";
  1176. /**
  1177. * 3013 - 流正在取消发布
  1178. */
  1179. static readonly IS_UNPUBLISHING = "3013";
  1180. /**
  1181. * 3014 - 流已经发布
  1182. */
  1183. static readonly IS_PUBLISHED = "3014";
  1184. /**
  1185. * 3015 - 流尚未订阅
  1186. */
  1187. static readonly IS_UNSUBSCRIBED = "3015";
  1188. /**
  1189. * 3016 - 流正在订阅
  1190. */
  1191. static readonly IS_SUBSCRIBING = "3016";
  1192. /**
  1193. * 3017 - 流正在取消订阅
  1194. */
  1195. static readonly IS_UNSUBSCRIBING = "3017";
  1196. /**
  1197. * 3018 - 流已经订阅
  1198. */
  1199. static readonly IS_SUBSCRIBED = "3018";
  1200. /**
  1201. * 3019 - 自动播放被禁止错误
  1202. */
  1203. static readonly PLAY_NOT_ALLOWED = "3019";
  1204. /**
  1205. * 3020 - 音视频数据异常,未成功播放(一般为网络原因导致,拉流时音视频数据加载过慢)
  1206. */
  1207. static readonly PLAY_PENDING = "3020";
  1208. /**
  1209. * 3021 - 因未曾调用或调用 play 方法失败,故不可恢复播放
  1210. */
  1211. static readonly RESUME_NOT_ALLOWED = "3021";
  1212. /**
  1213. * 3024 - ICE 建连失败
  1214. */
  1215. static readonly ICE_FAILED = "3024";
  1216. }
  1217. /**
  1218. * RTC 错误代码
  1219. *
  1220. * 通用错误及代码
  1221. * - 1000 - 非法参数
  1222. * - 1001 - 非法操作
  1223. * - 1002 - 不支持
  1224. * - 1003 - 不存在
  1225. * - 1004 - 请求失败
  1226. * - 1999 - 其他错误
  1227. *
  1228. * 房间相关错误及代码
  1229. * - 2000 - 网关不可达
  1230. * - 2001 - 获取 Access Token 失败
  1231. * - 2002 - Access Token 非法
  1232. * - 2003 - Websocket 连接失败
  1233. * - 2004 - 加入房间失败
  1234. * - 2005 - 未加入房间
  1235. * - 2006 - 正在加入房间
  1236. * - 2007 - 正在离开房间
  1237. * - 2008 - 角色类型不匹配
  1238. * - 2009 - 信令服务器地址错误
  1239. *
  1240. * 流相关错误及代码
  1241. * - 3000 - 流不存在
  1242. * - 3001 - 同类型的流已存在
  1243. * - 3002 - 音频不存在
  1244. * - 3003 - 视频不存在
  1245. * - 3004 - [中止错误] 尽管用户和操作系统都授予了访问设备硬件的权利,而且未出现可能抛出NotReadableError异常的硬件问题,但仍然有一些问题的出现导致了设备无法被使用。
  1246. * - 3005 - [拒绝错误] 用户拒绝了当前的浏览器实例的访问请求;或者用户拒绝了当前会话的访问;或者用户在全局范围内拒绝了所有媒体访问请求。
  1247. * - 3006 - [找不到错误] 找不到满足请求参数的媒体类型。
  1248. * - 3007 - [无法读取错误] 尽管用户已经授权使用相应的设备,操作系统上某个硬件、浏览器或者网页层面发生的错误导致设备无法被访问。
  1249. * - 3008 - [无法满足要求错误] 指定的要求无法被设备满足。
  1250. * - 3009 - 流连接失败
  1251. * - 3010 - 流正在重连
  1252. * - 3011 - 流尚未发布
  1253. * - 3012 - 流正在发布
  1254. * - 3013 - 流正在取消发布
  1255. * - 3014 - 流已经发布
  1256. * - 3015 - 流尚未订阅
  1257. * - 3016 - 流正在订阅
  1258. * - 3017 - 流正在取消订阅
  1259. * - 3018 - 流已经订阅
  1260. * - 3019 - 自动播放被禁止错误
  1261. * - 3020 - 音视频数据异常,未成功播放(一般为网络原因导致,拉流时音视频数据加载过慢)
  1262. * - 3021 - 因未曾调用或调用 play 方法失败,故不可恢复播放
  1263. * - 3024 - ICE 建连失败
  1264. * @public
  1265. */
  1266. export type ErrorCode = typeof RtcError[Exclude<keyof typeof RtcError, 'prototype' | 'getCode' | 'stackTraceLimit' | 'prepareStackTrace' | 'captureStackTrace'>];
  1267. }
  1268. declare module '__@urtc/sdk-web/user' {
  1269. /**
  1270. * 用户信息
  1271. * @public
  1272. */
  1273. export class User {
  1274. /**
  1275. * 用户ID
  1276. */
  1277. id: string;
  1278. }
  1279. }
  1280. declare module '__@urtc/sdk-web/stream/stream' {
  1281. import { EventEmitter } from '__@urtc/sdk-web/event-emitter';
  1282. import { PlayOptions, SnapshotOptions } from '__@urtc/sdk-web/types';
  1283. import { MediaType, StreamStats } from '__@urtc/sdk-web/stream/types';
  1284. /**
  1285. * LocalStream 和 RemoteStream 的基类
  1286. * @public
  1287. */
  1288. export class Stream extends EventEmitter {
  1289. /**
  1290. * 当前流ID
  1291. */
  1292. id: string;
  1293. /**
  1294. * 当前流所属用户的ID
  1295. * 注:若创建本地流时指定的 userId 与 join 时指定的 userId 不同,那么发布本条流时,流的 userId 将会自动被自动更新为 join 时指定的 userId
  1296. */
  1297. userId: string;
  1298. /**
  1299. * 是否为本地流
  1300. */
  1301. readonly isLocal: boolean;
  1302. /**
  1303. * 当前流包含的媒体流,关于媒体流,请详见 [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream)。
  1304. */
  1305. readonly mediaStream: MediaStream;
  1306. /**
  1307. * 获取流的媒体类型
  1308. * @example
  1309. * ```js
  1310. * const type = stream.getMediaType();
  1311. * ```
  1312. */
  1313. getMediaType(): MediaType;
  1314. /**
  1315. * 当前流是否 mute 了音频
  1316. */
  1317. audioMuted: boolean;
  1318. /**
  1319. * 当前流是否 mute 了视频
  1320. */
  1321. videoMuted: boolean;
  1322. /**
  1323. * 判断当前流是否有音频
  1324. * @example
  1325. * ```js
  1326. * const result = stream.hasAudio();
  1327. * ```
  1328. */
  1329. hasAudio(): boolean;
  1330. /**
  1331. * 判断当前流是否有视频
  1332. * @example
  1333. * ```js
  1334. * const result = stream.hasVideo();
  1335. * ```
  1336. */
  1337. hasVideo(): boolean;
  1338. /**
  1339. * mute 当前流的音频
  1340. * * 本地流调用此方法时,将不向服务器推送音频数据,远端用户将收到 `mute-audio` 的事件通知
  1341. * * 远端流调用此方法时,仅为不从服务器拉取音频数据,并无事件通知远端用户
  1342. * @example
  1343. * ```js
  1344. * const result = stream.muteAudio();
  1345. * console.log(`stream's audio is muted ${stream.audioMuted}`);
  1346. * ```
  1347. * @returns 操作是否成功
  1348. */
  1349. muteAudio(): boolean;
  1350. /**
  1351. * unmute 当前流的音频
  1352. * * 本地流调用此方法时,将向服务器推送音频数据,远端用户将收到 `unmute-audio` 的事件通知
  1353. * * 远端流调用此方法时,会从服务器拉取音频数据,并无事件通知远端用户
  1354. * @example
  1355. * ```js
  1356. * const result = stream.unmuteAudio();
  1357. * console.log(`stream's audio is muted ${stream.audioMuted}`);
  1358. * ```
  1359. * @returns 操作是否成功
  1360. */
  1361. unmuteAudio(): boolean;
  1362. /**
  1363. * mute 当前流的视频
  1364. * * 本地流调用此方法时,将不向服务器推送视频数据,远端用户将收到 `mute-video` 的事件通知
  1365. * * 远端流调用此方法时,仅为不从服务器拉取视频数据,并无事件通知远端用户
  1366. * @example
  1367. * ```js
  1368. * const result = stream.muteVideo();
  1369. * console.log(`stream's video is muted ${stream.videoMuted}`);
  1370. * ```
  1371. * @returns 操作是否成功
  1372. */
  1373. muteVideo(): boolean;
  1374. /**
  1375. * unmute 当前流的视频
  1376. * * 本地流调用此方法时,将向服务器推送视频数据,远端用户将收到 `unmute-video` 的事件通知
  1377. * * 远端流调用此方法时,会从服务器拉取视频数据,并无事件通知远端用户
  1378. * @example
  1379. * ```js
  1380. * const result = stream.unmuteVideo();
  1381. * console.log(`stream's video is muted ${stream.videoMuted}`);
  1382. * ```
  1383. * @returns 操作是否成功
  1384. */
  1385. unmuteVideo(): boolean;
  1386. /**
  1387. * 播放当前流
  1388. * @param container - 播放音视频时,包裹 video 标签所用的容器元素或容器元素的 ID
  1389. * @param opts - 其他播放参数,参见{@link PlayOptions}
  1390. * @example
  1391. * ```js
  1392. * const container = 'xxx'; // 比如 id 为 xxx 的 div 元素
  1393. * stream
  1394. * .play(container)
  1395. * .catch((err) => {
  1396. * console.log(`播放失败: ${err}`); // 一般由于浏览器对自动播放的限制导致播放失败
  1397. * });
  1398. * ```
  1399. * @reject {@link RtcError}
  1400. */
  1401. play(container: HTMLElement | string, opts?: PlayOptions): Promise<void>;
  1402. /**
  1403. * 恢复播放流,一般由于浏览器限制无法自动播放时,可提示用户手动触发该方法进行恢复播放
  1404. * @example
  1405. * ```js
  1406. * stream
  1407. * .resume()
  1408. * .catch((err) => {
  1409. * console.log(`恢复播放失败:${err}`);
  1410. * });
  1411. * ```
  1412. */
  1413. resume(): Promise<void>;
  1414. /**
  1415. * 停止播放当前流
  1416. * @example
  1417. * ```js
  1418. * stream.stop();
  1419. * ```
  1420. */
  1421. stop(): void;
  1422. /**
  1423. * 获取当前流的音量大小,只有当本地流或远端流中有音频数据才有效。
  1424. * @example
  1425. * ```js
  1426. * setInterval(() => {
  1427. * const level = stream.getAudioLevel();
  1428. * if (level > 0) {
  1429. * console.log(`user ${stream.userId} is speaking`);
  1430. * }
  1431. * }, 200);
  1432. * ```
  1433. */
  1434. getAudioLevel(): number;
  1435. /**
  1436. * 获取流发布或订阅后的统计数据
  1437. * @example
  1438. * ```js
  1439. * stream
  1440. * .getStats()
  1441. * .then((stats) => {
  1442. * console.log('当前流的统计数据为: ', stats);
  1443. * });
  1444. * ```
  1445. */
  1446. getStats(): Promise<StreamStats>;
  1447. /**
  1448. * 对当前流进行截屏,可用于页面展示或下载保存
  1449. * @param opts - 截屏参数,选传,参见{@link SnapshotOptions}
  1450. * @example
  1451. * ```js
  1452. * stream.snapshot({filename: 'xxx.jpg'})
  1453. * .then((pic) => {
  1454. * console.log('截屏图像', pic);
  1455. * })
  1456. * .catch((err) => {
  1457. * console.log('截屏失败', err);
  1458. * });
  1459. * ```
  1460. */
  1461. snapshot(opts?: SnapshotOptions): Promise<string>;
  1462. }
  1463. }
  1464. declare module '__@urtc/sdk-web/server' {
  1465. /**
  1466. * 服务器配置,可设置置网关(gateway)、信令(signal)、日志(log)服务器地址
  1467. * 注:
  1468. * 1. gateway 和 signal 须二选一进行设置
  1469. * 2. 没有日志服务器时,log 可不设
  1470. * @public
  1471. */
  1472. export interface ServerConfig {
  1473. /**
  1474. * 网关地址,如 'https://my-rtc.com.cn'
  1475. */
  1476. gateway?: string;
  1477. /**
  1478. * 信令服务器地址,如 'wss://my-rtc.com.cn:5005'
  1479. */
  1480. signal?: string;
  1481. /**
  1482. * 日志服务器地址,如 'https://log.my-rtc.com.cn'
  1483. */
  1484. log?: string;
  1485. }
  1486. /**
  1487. * 用于私有化部署时,指定部署的服务器地址
  1488. * @param conf - 服务器配置,具体描述参见 ServerConfig 的说明
  1489. * @public
  1490. * @example
  1491. * ```js
  1492. * setServers({
  1493. * gateway: 'https://my-rtc.com', // 指定网关
  1494. * log: 'https://log.my-rtc.com', // 指定日志服务器
  1495. * });
  1496. * ```
  1497. *
  1498. * **特别地,单信令服务器时,不需要网关进行分配信令服务器,可以直接指定信令服务器**
  1499. * ```js
  1500. * setServers({
  1501. * signal: 'wss://my-rtc.com:5005', // 直接指定信令服务器
  1502. * log: 'https://log.my-rtc.com', // 指定日志服务器
  1503. * });
  1504. * ```
  1505. * @throws {@link RtcError}
  1506. */
  1507. export function setServers(conf: ServerConfig): void;
  1508. }
  1509. declare module '__@urtc/sdk-web/plugin' {
  1510. /**
  1511. * @public
  1512. */
  1513. export interface StreamPlugin {
  1514. name: string;
  1515. install: Function;
  1516. }
  1517. /**
  1518. * @public
  1519. */
  1520. export interface ClientPlugin {
  1521. name: string;
  1522. install: Function;
  1523. }
  1524. }
  1525. declare module '__@urtc/sdk-web/version' {
  1526. /**
  1527. * 当前 sdk 的版本号
  1528. * @public
  1529. */
  1530. export const version: string;
  1531. }
  1532. declare module '__@urtc/sdk-web/event-emitter' {
  1533. import { RtcEventType, RtcUserEventType, RtcUserEvent, RtcStreamEventType, RtcStreamEvent, RtcConnectionStateEventType, RtcConnectionStateEvent, RtcNetworkQualityEventType, RtcNetworkQualityEvent, RtcPlayerEventType, RtcPlayerEvent, RtcDeviceChangedEventType, RtcDeviceChangedEvent, RtcErrorEventType, RtcErrorEvent } from '__@urtc/sdk-web/event';
  1534. /**
  1535. * 事件监听函数
  1536. * 其中 T 为 RtcEvent 泛型
  1537. * @private
  1538. */
  1539. 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;
  1540. /**
  1541. * 事件监听函数
  1542. * 其中 RtcEventInstance 为事件实例
  1543. * > 注:使用 typescript 时,会根据 T {@link RtcEventType} 类型自动推断 {@link RtcEvent} 的类型。
  1544. */
  1545. export interface Listener<T> {
  1546. (event: RtcEventInstance<T>): void;
  1547. }
  1548. /**
  1549. * @private
  1550. */
  1551. export class EventEmitter {
  1552. /**
  1553. * 监听流对象事件
  1554. * @param type - 流事件类型
  1555. * @param listener - 流事件监听函数
  1556. */
  1557. on<T extends RtcEventType>(type: T, listener: Listener<T>): EventEmitter;
  1558. /**
  1559. * 取消监听流对象事件
  1560. * @param type - 流对象事件类型,特别的,当为 '*' 时,取消监听所有事件
  1561. * @param listener - 流对象事件监听函数
  1562. */
  1563. off<T extends RtcEventType | '*'>(type: T, listener: Listener<T>): EventEmitter;
  1564. }
  1565. }
  1566. declare module '__@urtc/sdk-web/stream/types' {
  1567. /**
  1568. * 音频编解码格式
  1569. */
  1570. export type AudioCodec = 'opus';
  1571. /**
  1572. * 视频编解码格式
  1573. * @note 'h265' 目前仅部分浏览器在开启试验性功能时才支持,如 Safari 开启 `WebRTC H265 codec`
  1574. */
  1575. export type VideoCodec = 'vp8' | 'h264' | 'h265';
  1576. /**
  1577. * 流的音频的统计数据
  1578. */
  1579. export interface AudioStats {
  1580. /**
  1581. * 音频码率,获取失败时为 -1
  1582. */
  1583. bitrate: number;
  1584. /**
  1585. * 音频丢包率,获取失败时为 -1
  1586. */
  1587. packetLossRate: number;
  1588. /**
  1589. * 音频音量,获取失败时为 -1
  1590. */
  1591. volume: number;
  1592. /**
  1593. * 音频编码格式,获取失败时为 ''
  1594. */
  1595. codec: AudioCodec;
  1596. }
  1597. /**
  1598. * 流的视频的统计数据
  1599. */
  1600. export interface VideoStats {
  1601. /**
  1602. * 视频码率,获取失败时为 -1
  1603. */
  1604. bitrate: number;
  1605. /**
  1606. * 视频丢包率,获取失败时为 -1
  1607. */
  1608. packetLossRate: number;
  1609. /**
  1610. * 视频帧率,获取失败时为 -1
  1611. */
  1612. framerate: number;
  1613. /**
  1614. * 视频宽,获取失败时为 -1
  1615. */
  1616. width: number;
  1617. /**
  1618. * 视频高,获取失败时为 -1
  1619. */
  1620. height: number;
  1621. /**
  1622. * 视频编码格式,获取失败时为 ''
  1623. */
  1624. codec: VideoCodec;
  1625. }
  1626. /**
  1627. * 流的网络连接统计数据
  1628. */
  1629. export interface NetworkStats {
  1630. /**
  1631. * 网络往返时间,获取失败时为 -1
  1632. */
  1633. rtt: number;
  1634. }
  1635. /**
  1636. * 已发布/已订阅流的统计数据
  1637. */
  1638. export interface StreamStats {
  1639. /**
  1640. * 流包含音频时,音频统计数据
  1641. */
  1642. audio?: AudioStats;
  1643. /**
  1644. * 流包含视频时,视频统计数据
  1645. */
  1646. video?: VideoStats;
  1647. /**
  1648. * 流的网络连接统计数据
  1649. */
  1650. network?: NetworkStats;
  1651. }
  1652. /**
  1653. * 流的媒体类型, camera - 主视频流,screen - 辅助视频流,通常是一个屏幕分享流
  1654. */
  1655. export type MediaType = 'camera' | 'screen';
  1656. /**
  1657. * 切换设备的类型
  1658. */
  1659. export type SwitchDeviceType = 'audio' | 'video';
  1660. /**
  1661. * 流的网络质量评分,有 '0' | '1' | '2' | '3' | '4' | '5' | '6'
  1662. * - '0': 网络质量未知
  1663. * - '1': 网络质量优秀
  1664. * - '2': 网络质量良好
  1665. * - '3': 网络质量一般
  1666. * - '4': 网络质量较差
  1667. * - '5': 网络质量糟糕
  1668. * - '6': 网络连接断开
  1669. */
  1670. export type NetworkQuality = '0' | '1' | '2' | '3' | '4' | '5' | '6';
  1671. /**
  1672. * 推(上行)/拉(下行)流的网络质量
  1673. */
  1674. export interface NetworkQualities {
  1675. /**
  1676. * 推(上行)流的网络质量
  1677. */
  1678. uplink: NetworkQuality;
  1679. /**
  1680. * 拉(下行)流的网络质量
  1681. */
  1682. downlink: NetworkQuality;
  1683. }
  1684. }
  1685. declare module '__@urtc/sdk-web/stream/profile' {
  1686. /**
  1687. * 预设的视频 Profile
  1688. *
  1689. * 名称 | 视频宽 | 视频高 | 帧率 (fps) | 码率 (kbps)
  1690. * :-: | :-: | :-: | :-: | :-:
  1691. * 180p | 240 | 180 | 15 | 200
  1692. * 180p_2 | 320 | 180 | 15 | 300
  1693. * 240p | 320 | 240 | 15 | 400
  1694. * 360p | 480 | 360 | 15 | 400
  1695. * 360p_2 | 640 | 360 | 15 | 500
  1696. * 480p | 640 | 480 | 15 | 600
  1697. * 720p | 1280 | 720 | 15 | 1000
  1698. * 720p_2 | 1280 | 720 | 15 | 1500
  1699. * 720p_3 | 1280 | 720 | 30 | 2000
  1700. * 1080p | 1920 | 1080 | 15 | 1500
  1701. * 1080p_2 | 1920 | 1080 | 15 | 2000
  1702. * 1080p_3 | 1920 | 1080 | 30 | 2500
  1703. */
  1704. export type VideoProfile = '180p' | '180p_2' | '240p' | '360p' | '360p_2' | '480p' | '720p' | '720p_2' | '720p_3' | '1080p' | '1080p_2' | '1080p_3';
  1705. /**
  1706. * 预设的屏幕共享视频 Profile
  1707. *
  1708. * 名称 | 视频宽 | 视频高 | 帧率 (fps) | 码率 (kbps)
  1709. * :-: | :-: | :-: | :-: | :-:
  1710. * 480p | 640 | 480 | 5 | 600
  1711. * 480p_2 | 640 | 480 | 30 | 1000
  1712. * 720p | 1280 | 720 | 5 | 1000
  1713. * 720p_2 | 1280 | 720 | 30 | 2000
  1714. * 1080p | 1920 | 1080 | 5 | 1500
  1715. * 1080p_2 | 1920 | 1080 | 30 | 2500
  1716. */
  1717. export type ScreenProfile = '480p' | '480p_2' | '720p' | '720p_2' | '1080p' | '1080p_2';
  1718. /**
  1719. * 自定义视频 Profile,请根据实际使用场景及网络环境,合理的设置
  1720. * @example
  1721. * ```js
  1722. * { width: 640, height: 480, framerate: 15, bitrate: 500 }
  1723. * ```
  1724. */
  1725. export interface CustomVideoProfile {
  1726. /**
  1727. * 视频宽,如:640
  1728. */
  1729. width: number;
  1730. /**
  1731. * 视频高,如:480
  1732. */
  1733. height: number;
  1734. /**
  1735. * 帧率 (fps),如:15
  1736. */
  1737. framerate: number;
  1738. /**
  1739. * 码率 (kbps),如:500
  1740. */
  1741. bitrate: number;
  1742. }
  1743. }
  1744. declare module '__@urtc/sdk-web/connection/types' {
  1745. /**
  1746. * 连接状态类型:
  1747. * - OPEN - 已连接
  1748. * - CONNECTING - 连接中
  1749. * - CLOSING - 断开中
  1750. * - RECONNECTING - 重连中
  1751. * - CLOSED - 已断开
  1752. * @public
  1753. */
  1754. export type ConnectionState = 'OPEN' | 'CONNECTING' | 'CLOSING' | 'RECONNECTING' | 'CLOSED';
  1755. /**
  1756. * 客户端(Client)与服务器之间的{@link ConnectionState 连接状态}
  1757. * @public
  1758. */
  1759. export interface ConnectionStates {
  1760. /**
  1761. * 当前连接状态
  1762. */
  1763. current: ConnectionState;
  1764. /**
  1765. * 之前连接状态
  1766. */
  1767. previous: ConnectionState;
  1768. }
  1769. }