index.d.ts 55 KB

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