| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789 |
- // Generated by dts-bundle v0.7.3
- declare module '@urtc/sdk-web' {
- import { Client } from '__@urtc/sdk-web/client';
- import { LocalStream, LocalStreamOptions } from '__@urtc/sdk-web/stream/local-stream';
- import { RemoteStream } from '__@urtc/sdk-web/stream/remote-stream';
- import { generateToken } from '__@urtc/sdk-web/utils/token';
- import { ClientOptions } from '__@urtc/sdk-web/types';
- import { LogLevel } from '__@urtc/sdk-web/logger';
- /**
- * 创建客户端
- * @param appId - 应用 ID,可在控制台查看
- * @param opts - 定义客户端的属性
- * @public
- * @example
- * ```js
- * const client = createClient('AppID');
- * client
- * .join('roomId', 'userId', 'token')
- * .then(() => {
- * client.publish(localStream);
- * })
- * .catch((err) => {
- * console.log(`加入房间失败 ${err}`);
- * });
- * ```
- * @throws {@link RtcError}
- */
- export function createClient(appId: string, opts?: ClientOptions): Client;
- /**
- * 创建本地流
- * @param opts - 必传,定义本地音视频流的属性
- * 注:
- * 1. video, screen 不可同时为 true
- * 2. audio, video, screen 不可同时为 false
- * 3. 若指定了 file,则 init 时将优先使用 file 来创建初始化本地流的视频
- * 4. screenAudio 在不同浏览器上表现不同,参见 {@link LocalStreamOptions}
- * @public
- * @example
- * ```js
- * const localStream = createStream({ audio: true, video: true, screen: false });
- * localStream
- * .init()
- * .then(() => {
- * localStream
- * .play(container)
- * .catch((err) => {console.log(`播放失败: ${err}`)});
- * })
- * .catch((err) => {
- * console.log(`本地流初始化失败 ${err}`);
- * });
- * ```
- * @throws {@link RtcError}
- */
- export function createStream(opts: LocalStreamOptions): LocalStream;
- /**
- * 设置日志打印级别,用于打印出更多日志来调试或定位问题,默认 warn 级别
- * @param level - 日志级别,有 'debug', 'info', 'warn', 'error' 级别;
- * @public
- * @example
- * ```js
- * setLogLevel('info');
- * ```
- */
- export function setLogLevel(level: LogLevel): void;
- /**
- * 开启日志(操作/错误/状态)的上报,默认开启
- * @public
- * @example
- * ```js
- * enableUploadLog();
- * ```
- */
- export function enableUploadLog(): void;
- /**
- * 关闭日志(操作/错误/状态)的上报
- * 注:若无特殊原因,不建议关闭日志上报,关闭后,在线上出现错误时,将无法根据日志定位问题
- * @public
- * @example
- * ```js
- * disableUploadLog();
- * ```
- */
- export function disableUploadLog(): void;
- export { generateToken };
- export * from '__@urtc/sdk-web/devices';
- export * from '__@urtc/sdk-web/client';
- export * from '__@urtc/sdk-web/types';
- export * from '__@urtc/sdk-web/event';
- export * from '__@urtc/sdk-web/error';
- export * from '__@urtc/sdk-web/user';
- export * from '__@urtc/sdk-web/stream/stream';
- export * from '__@urtc/sdk-web/stream/local-stream';
- export * from '__@urtc/sdk-web/stream/remote-stream';
- export * from '__@urtc/sdk-web/server';
- export * from '__@urtc/sdk-web/plugin';
- export * from '__@urtc/sdk-web/version';
- /************** 4 plugin ****************/
- export { Client };
- export { LocalStream };
- export { RemoteStream };
- }
- declare module '__@urtc/sdk-web/client' {
- import { RtcEventType } from '__@urtc/sdk-web/event';
- import { Listener } from '__@urtc/sdk-web/event-emitter';
- import { LocalStream } from '__@urtc/sdk-web/stream/local-stream';
- import { RemoteStream } from '__@urtc/sdk-web/stream/remote-stream';
- import { User } from '__@urtc/sdk-web/user';
- import { JoinOptions, RoleType } from '__@urtc/sdk-web/types';
- /**
- * RTC 客户端,可进行加入、离开房间,发布、订阅流等操作。
- * @public
- */
- export class Client {
- /**
- * 获取远端用户信息
- * @example
- * ```js
- * const users = client.getRemoteUsers();
- * ```
- */
- getRemoteUsers(): User[];
- /**
- * 获取当前 Client 已发布的本地流
- * @example
- * ```js
- * const localStreams = client.getLocalStreams();
- * ```
- */
- getLocalStreams(): LocalStream[];
- /**
- * 获取当前 Client 已接收到的远端流(包含已订阅或未订阅的远端流)
- * @example
- * ```js
- * const remoteStreams = client.getRemoteStreams();
- * ```
- */
- getRemoteStreams(): RemoteStream[];
- /**
- * 加入房间
- * @param roomId - 房间ID
- * @param userId - 用户ID
- * @param token - 由 AppId,AppKey,RoomId,UserId 生成的令牌
- * @param opts - 其他选项
- * @example
- * ```js
- * const remoteStreams = client.getRemoteStreams();
- * client
- * .join('roomIdxxx', 'userIdxxx', 'tokenxxx')
- * .then(() => {
- * console.log(`加入房间成功`);
- * // client.publish(localStream);
- * })
- * .catch((err) => {
- * console.log(`加入房间失败 ${err}`);
- * });
- * ```
- * @reject {@link RtcError}
- */
- join(roomId: string, userId: string, token: string, opts?: JoinOptions): Promise<void>;
- /**
- * 离开房间
- * @example
- * ```js
- * client
- * .leave()
- * .then(() => {
- * console.log(`离开房间成功`);
- * })
- * .catch((err) => {
- * console.log(`离开房间失败 ${err}`);
- * });
- * ```
- */
- leave(): Promise<void>;
- /**
- * 监听 Client 对象的事件
- * @param type - 事件类型
- * @param listener - 事件监听函数
- * @example
- * ```js
- * const handleStreamAdded = (event) => {
- * client
- * .subscribe(event.data)
- * .catch((err) => {
- * console.log(`订阅失败 ${err}`);
- * });
- * }
- * client.on('stream-added', handleStreamAdded);
- * ```
- * @throws {@link RtcError}
- */
- on<T extends RtcEventType>(type: T, listener: Listener<T>): Client;
- /**
- * 取消监听 Client 对象的事件
- * @param type - 事件类型,特别的,可以使用 * 来一次性取消对所有事件的监听
- * @param listener - 事件监听函数
- * @example
- * ```js
- * client.off('stream-added', handleStreamAdded);
- * ```
- *
- * **特别地,一次性取消对所有事件的监听**
- * @example
- * ```js
- * client.off('*');
- * ```
- * @throws {@link RtcError}
- */
- off<T extends RtcEventType | '*'>(type: T, listener?: Listener<T>): Client;
- /**
- * 发布一条本地流
- * @param stream - 需要被发布的本地流
- * @example
- * ```js
- * client
- * .publish(localStream)
- * .catch((err) => {
- * console.log(`发布失败 ${err}`);
- * });
- * ```
- * @reject {@link RtcError}
- */
- publish(stream: LocalStream): Promise<void>;
- /**
- * 取消发布一条本地流
- * @param stream - 需要取消发布的本地流
- * @example
- * ```js
- * client
- * .unpublish(localStream)
- * .then(() => {
- * console.log('取消发布成功');
- * // localStream.destroy();
- * })
- * .catch((err) => {
- * console.log(`取消发布失败 ${err}`);
- * });
- * ```
- * @reject {@link RtcError}
- */
- unpublish(stream: LocalStream): Promise<void>;
- /**
- * 订阅一条远端流
- * @param stream - 需要被订阅的远端流
- * @example
- * ```js
- * client
- * .subscribe(remoteStream)
- * .catch((err) => {
- * console.log(`订阅失败 ${err}`);
- * });
- * ```
- * @reject {@link RtcError}
- */
- subscribe(stream: RemoteStream): Promise<void>;
- /**
- * 取消订阅一条远端流
- * @param stream - 需要取消订阅的远端流
- * @example
- * ```js
- * client
- * .unsubscribe(remoteStream)
- * .catch((err) => {
- * console.log(`取消订阅失败 ${err}`);
- * });
- * ```
- * @reject {@link RtcError}
- */
- unsubscribe(stream: RemoteStream): Promise<void>;
- /**
- * 修改用户角色
- * @param role - 用户角色
- * @example
- * ```js
- * client.setRole('push');
- * ```
- * @throws {@link RtcError}
- */
- setRole(role: RoleType): void;
- }
- }
- declare module '__@urtc/sdk-web/stream/local-stream' {
- import { Stream } from '__@urtc/sdk-web/stream/stream';
- import { SwitchDeviceType } from '__@urtc/sdk-web/stream/types';
- import { VideoProfile, ScreenProfile, CustomVideoProfile } from '__@urtc/sdk-web/stream/profile';
- /**
- * 指定使用前置或后置摄像头,'user'(前置摄像头)或 'environment'(后置摄像头)
- */
- export type FacingMode = 'user' | 'environment';
- /**
- * 创建本地流的参数
- */
- export interface LocalStreamOptions {
- /**
- * 是否读取麦克风设备来初始化本地流的音频
- */
- audio: boolean;
- /**
- * 选传,读取指定设备ID的麦克风
- */
- microphoneId?: string;
- /**
- * 是否读取摄像头设备来初始化本地流的视频
- */
- video: boolean;
- /**
- * 选传,读取指定设备ID的摄像头
- */
- cameraId?: string;
- /**
- * 是否使用屏幕共享的画面来初始化本地流
- */
- screen: boolean;
- /**
- * 选传,是否读取屏幕共享的音频,默认: false
- * > 注:仅部分浏览器支持,如 Chrome 74,且不同系统表现不同,如 windows 会读取桌面音频,macOS 只支持读取浏览器 tab 中的音频。
- */
- screenAudio?: boolean;
- /**
- * 选传,在移动设备上,可以设置该参数选择使用前置或后置摄像头,其中,FacingMode 为 'user'(前置摄像头)或 'environment'(后置摄像头)
- */
- facingMode?: FacingMode;
- /**
- * 选传,使用图片初始化本地流的视频。
- * 注:若指定,将直接采用图片生成的视频作为本地流的视频源,不再按 video 设置的读取摄像头作为视频源,或 screen 设置的读取屏幕共享的画面作为视频源。
- */
- file?: string | File;
- /**
- * 选传,指定本地流的 ID,请注意创建多条流时,不可传入重复值
- */
- id?: string;
- /**
- * 选传,指定本地流的 userId
- */
- userId?: string;
- /**
- * 选传,音频轨道,参见 {@link https://developer.mozilla.org/zh-CN/docs/Web/API/MediaStreamTrack | MediaStreamTrack},指定本地流的音频源。
- * 注:若指定,将直接采用该音频轨道作为本地流的音频源,不再按 audio 设置的读取麦克风作为音频源,或 screenAudio 设置的读取屏幕共享的音频作为音频源。
- */
- audioSource?: MediaStreamTrack;
- /**
- * 选传,视频轨道,参见 {@link https://developer.mozilla.org/zh-CN/docs/Web/API/MediaStreamTrack | MediaStreamTrack},指定本地流的视频源。
- * 注:若指定,将直接采用该视频轨道作为本地流的视频源,不再按 video 设置的读取摄像头作为视频源,或 screen 设置的读取屏幕共享的画面作为视频源,或 file 设置的使用图片生成视频源。
- */
- videoSource?: MediaStreamTrack;
- }
- /**
- * 本地流,可用于本地预览,也可用 client 进行发布
- */
- export class LocalStream extends Stream {
- /**
- * 判断当前流是否有音频
- * @example
- * ```js
- * const result = stream.hasAudio();
- * ```
- */
- hasAudio(): boolean;
- /**
- * 判断当前流是否有视频
- * @example
- * ```js
- * const result = stream.hasVideo();
- * ```
- */
- hasVideo(): boolean;
- /**
- * 初始化本地流对象,将读取麦克风、摄像头、屏幕共享等来初始化媒体流
- * @example
- * ```js
- * const stream = createStream({audio: true, video: true, screen: false});
- * stream
- * .init()
- * .then(() => {
- * client.publish(stream); // 发布本地流
- * })
- * .catch((err) => {
- * console.log(`初始化本地流失败 ${err}`);
- * })
- * ```
- */
- init(): Promise<void>;
- /**
- * 添加一条媒体轨道(音轨或视轨)到当前流
- * > 注:
- * > 1. 若创建本地流时,audio 为 false,不可添加音轨,video 为 false 时,不可添加视轨
- * @param track - 媒体轨道
- * @example
- * ```js
- * stream.addTrack(track);
- * ```
- */
- addTrack(track: MediaStreamTrack): void;
- /**
- * 从当前流中删除一条媒体轨道(音轨或视轨)
- * @param track - 媒体轨道
- * @example
- * ```js
- * stream.removeTrack(track);
- * ```
- */
- removeTrack(track: MediaStreamTrack): void;
- /**
- * 替换当前流中的媒体轨道
- * > 注:
- * > 1. 替换视频时,建议使用与原轨道相同的分辨率的媒体轨道,若不相同,请在替换后及时设置流的 profile 来调整到合适的码率等
- * > 2. 返回值为当前流中相同类型的媒体轨道,此媒体轨道仍可用(占用音频设备或视频设备),请自行决定是否调用其 stop 方法释放设备
- * > 3. 若是切换不同的摄像头或麦克风设备,建议使用 switchDevice 方法,若是切换静态图片为视频流,建议使用 switchImage 方法
- * @param track - 新媒体轨道
- * @example
- * ```js
- * const oldTrack = stream.replaceTrack(track);
- * oldTrack.stop();
- * ```
- */
- replaceTrack(track: MediaStreamTrack): MediaStreamTrack | undefined;
- /**
- * 设置音频能量大小,默认 100
- * @param level - 能量大小,取值范围 [0-300]
- */
- setAudioLevel(level: number): void;
- /**
- * 设置当前流视频的 Profile,默认 '360p_2'
- * @param profile - 视频 Profile
- * @example
- * ```js
- * stream
- * .setVideoProfile('720p')
- * .then(() => {
- * console.log('set video profile success');
- * })
- * .catch((err) => {
- * console.log('set video profile failed ', err);
- * });
- * ```
- * 或
- * ```js
- * stream
- * .setVideoProfile({width: 640, height: 480, framerate: 15, bitrate: 500});
- * .then(() => {
- * console.log('set video profile success');
- * })
- * .catch((err) => {
- * console.log('set video profile failed ', err);
- * });
- * ```
- */
- setVideoProfile(profile: VideoProfile | CustomVideoProfile): Promise<void>;
- /**
- * 设置当前流(屏幕共享流)视频的 Profile,默认 '1080p'
- * 注:请务必在调用 init 方法之前,设置屏幕共享流的 Profile,否则无法生效。
- * @param profile - 视频 Profile
- * @example
- * ```js
- * stream.setScreenProfile('720p');
- * stream.init().catch((err) => {
- * console.log(`初始化屏幕共享流失败 ${err}`);
- * });
- * ```
- */
- setScreenProfile(profile: ScreenProfile | CustomVideoProfile): void;
- /**
- * 切换音视频设备
- * @param type - 设备类型
- * @param deviceId - 设备 ID
- * @example
- * ```js
- * stream.switchDevice('audio', 'xxxxxxx')
- * .then(() => {
- * console.log('切换设备成功');
- * })
- * .catch((err) => {
- * console.log(`切换设备失败:${err}`);
- * });
- * ```
- * @reject {@link RtcError}
- */
- switchDevice(type: SwitchDeviceType, deviceId: string): Promise<void>;
- /**
- * 切换图片 - 使用图片生成视频,并将当前流的视频使用其代替
- * @param file - 图片地址或图片文件
- * @example
- * ```js
- * const imgAddr = 'https://a.b.c/d.jpg';
- * stream.switchImage(imgAddr)
- * .then(() => {
- * console.log('切换图片成功')
- * })
- * .catch((err) => {
- * console.error(`切换图片失败:${err}`);
- * });
- * ```
- * @reject {@link RtcError}
- */
- switchImage(file: string | File): Promise<void>;
- /**
- * 销毁当前流,一般在本地流不再被使用时,可调用此方法销毁,解除摄像头或麦克风设备的占用。
- * @example
- * ```js
- * stream.destroy();
- * ```
- */
- destroy(): void;
- }
- }
- declare module '__@urtc/sdk-web/stream/remote-stream' {
- import { Stream } from '__@urtc/sdk-web/stream/stream';
- /**
- * 远端流,房间内其他用户发布的流,可通过 client 进行订阅
- */
- export class RemoteStream extends Stream {
- /**
- * 音频源是否已 mute,当源端 mute/unmute 音频时,本端将收到 `mute-audio` 或 `unmute-audio` 事件的通知,同时此值将变为对应值
- */
- sourceAudioMuted: boolean;
- /**
- * 视频源是否已 mute,当源端 mute/unmute 视频时,本端将收到 `mute-video` 或 `unmute-video` 事件的通知,同时此值将变为对应值
- */
- sourceVideoMuted: boolean;
- /**
- * 设置输出音量,默认为 100
- * @param volume - 音量大小, 可设范围[0-100]
- * @throws RtcError
- * @example
- * ```js
- * stream.setAudioVolume(50);
- * ```
- */
- setAudioVolume(volume: number): void;
- }
- }
- declare module '__@urtc/sdk-web/utils/token' {
- /**
- * 根据 AppId,AppKey,RoomId,UserId 生成 token,用于开发阶段临时快速的加入房间并验证功能,由于 AppKey 不可暴露于公网,因此生产环境中不建议使用此方法生成 token。
- * @param appId - 应用 ID,可在控制台查看
- * @param appKey - 应用密钥,可在控制台查看
- * @param roomId - 房间 ID
- * @param userId - 用户 ID
- * @public
- * @example
- * ```js
- * const token = generateToken('appId', 'appKey', 'roomId', 'userId');
- * client.join('roomId', 'userId', token);
- * ```
- */
- export function generateToken(appId: string, appKey: string, roomId: string, userId: string): string;
- }
- declare module '__@urtc/sdk-web/types' {
- import { AudioCodec, VideoCodec } from '__@urtc/sdk-web/stream/types';
- /**
- * 视频播放时的显示模式
- * - cover 模式:优先保证视窗被填满。
- * - contain 模式:优先保证视频内容全部显示。
- * 播放摄像头视频流默认使用 cover 模式,屏幕共享视频流默认使用 contain 模式。
- * @public
- */
- export type PlayerVideoFitType = 'cover' | 'contain';
- /**
- * 视频播放时 audio / video 的控制面板的显示模式
- * - show 模式:一直显示
- * - hide 模式:一直隐藏
- * - auto 模式:自动判断
- * @public
- */
- export type PlayControlsType = 'show' | 'hide' | 'auto';
- /**
- * 播放器播放属性
- * @public
- */
- export interface PlayOptions {
- /**
- * 是否静音播放
- */
- mute: boolean;
- /**
- * 是否镜像播放
- */
- mirror?: boolean;
- /**
- * 视频播放时的{@link PlayerVideoFitType | 显示模式},默认 'cover',屏幕共享时默认使用 'contain'
- */
- fit?: PlayerVideoFitType;
- /**
- * 视频播放时 audio / video 的控制面板的显示模式,默认自动判断(播放失败时显示,播放成功时隐藏)
- */
- controls?: PlayControlsType;
- }
- export { /*AudioProfile,*/ VideoProfile, ScreenProfile, CustomVideoProfile } from '__@urtc/sdk-web/stream/profile';
- /**
- * 房间类型:'conference' | 'live',分别对应会议模式 | 直播模式。
- * 注:
- * 会议模式:房间内用户数较少,各用户均会推流,并拉其他用户的流。
- * 直播模式:房间内用户数较多,个别用户会推流,大部分用户只拉流观看。
- */
- export type RoomType = 'conference' | 'live';
- /**
- * 用户角色,'audience' | 'speaker' 分别为观众,主讲。
- * @public
- */
- export type RoleType = 'audience' | 'speaker';
- /**
- * 定义客户端的属性
- * @public
- */
- export interface ClientOptions {
- /**
- * 客户端{@link VideoCodec | 视频编码格式},默认 'vp8'
- */
- codec?: VideoCodec;
- }
- /**
- * 加入房间的属性
- * @public
- */
- export interface JoinOptions {
- /**
- * 加入房间的{@link RoomType | 房间类型},默认 'conference'
- */
- type?: RoomType;
- /**
- * 加入房间的{@link RoleType | 角色},默认 'speaker'
- */
- role?: RoleType;
- }
- /**
- * 支持的音频、视频编解码格式
- * @public
- */
- export interface Codecs {
- /**
- * 音频编解码格式
- */
- audio: AudioCodec[];
- /**
- * 视频编解码格式
- */
- video: VideoCodec[];
- }
- /**
- * 截屏参数
- * @public
- */
- export interface SnapshotOptions {
- /**
- * 选填,是否将截屏保存为图片并下载,默认 false
- */
- download?: boolean;
- /**
- * 选填,将截屏保存为图片时指定的文件名
- * 当传入文件名时,将按指定的文件名保存图片,否则文件名将自动生成
- * 特别地,当传入文件名时,即使 download 指定为 false,也将按指定的文件名保存图片并下载
- */
- filename?: string;
- }
- export * from '__@urtc/sdk-web/stream/types';
- export * from '__@urtc/sdk-web/connection/types';
- }
- declare module '__@urtc/sdk-web/logger' {
- /**
- * 日志级别
- */
- export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
- }
- declare module '__@urtc/sdk-web/devices' {
- import { Codecs } from '__@urtc/sdk-web/types';
- /**
- * 获取音视频输入/输出设备列表参数
- */
- export interface GetDevicesOptions {
- /**
- * 获取音频输入/输出设备列表
- */
- audio: boolean;
- /**
- * 获取视频输入设备列表
- */
- video: boolean;
- }
- /**
- * 获取音视频输入/输出设备列表,点击 [MediaDeviceInfo](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo) 查看详情
- * @public
- * @example
- * ```js
- * getDevices()
- * .then(devices => {
- * console.log(`获取设备列表成功:`, devices);
- * })
- * .catch(err => {
- * console.log(`获取设备列表失败:${err}`);
- * });
- * ```
- * @reject {@link RtcError}
- */
- export function getDevices(opts?: GetDevicesOptions): Promise<MediaDeviceInfo[]>;
- /**
- * 获取摄像头设备列表,点击 [MediaDeviceInfo](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo) 查看详情
- * @public
- * @example
- * ```js
- * getCameras()
- * .then(devices => {
- * console.log(`获取设备列表成功:`, devices);
- * })
- * .catch(err => {
- * console.log(`获取设备列表失败:${err}`);
- * });
- * ```
- * @reject {@link RtcError}
- */
- export function getCameras(): Promise<MediaDeviceInfo[]>;
- /**
- * 获取麦克风设备列表,点击 [MediaDeviceInfo](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo) 查看详情
- * @public
- * @example
- * ```js
- * getMicrophones()
- * .then(devices => {
- * console.log(`获取设备列表成功:`, devices);
- * })
- * .catch(err => {
- * console.log(`获取设备列表失败:${err}`);
- * });
- * ```
- * @reject {@link RtcError}
- */
- export function getMicrophones(): Promise<MediaDeviceInfo[]>;
- /**
- * 获取扬声器设备列表,点击 [MediaDeviceInfo](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo) 查看详情
- * @public
- * @example
- * ```js
- * getLoudspeakers()
- * .then(devices => {
- * console.log(`获取设备列表成功:`, devices);
- * })
- * .catch(err => {
- * console.log(`获取设备列表失败:${err}`);
- * });
- * ```
- * @reject {@link RtcError}
- */
- export function getLoudspeakers(): Promise<MediaDeviceInfo[]>;
- /**
- * 设备检测选项
- * @public
- */
- export interface DeviceDetectionOptions {
- /**
- * 必填,指定是还检测麦克风设备
- */
- audio: boolean;
- /**
- * 必填,指定是否检测摄像头设备
- */
- video: boolean;
- /**
- * 选填,指定需要检测的麦克风设备的ID,可通过 getMicrophones 方法查询获得该ID,不填时,将检测默认的麦克风设备
- */
- microphoneId?: string;
- /**
- * 选填,指定需要检测的摄像头设备的ID,可以通过 getCameras 方法查询获得该ID,不填时,将检测默认的摄像头设备
- */
- cameraId?: string;
- }
- /**
- * 设备可用性检测 - 创建包含麦克风音频或摄像头视频的本地流时,有可能因为麦克风或摄像头设备问题(如驱动问题,或未经授权等),导致无法正确创建。此方法可用于设备检测,根据检测结果,再决定创建本地流时启用麦克风或摄像头或麦克风和摄像头
- * @param options - 需指定设备时,请传入设备 ID
- * @public
- * @example
- * ```js
- * deviceDetection({audio: true, video: true})
- * .then(() => {
- * console.log('设备可用');
- * })
- * .catch(err => {
- * console.log(`设备不可用,${err}`);
- * });
- * ```
- * @reject {@link RtcError}
- */
- export function deviceDetection(options: DeviceDetectionOptions): Promise<void>;
- /**
- * 检测浏览器是否完全(可访问本地音视频设备)支持 WebRTC。
- * @public
- * @example
- * ```js
- * if (!isSupportWebRTC()) {
- * console.log(`当前浏览器不完全支持 WebRTC,建议使用 Chrome 浏览器,iOS 系统建议使用 Safari 浏览器`);
- * }
- * ```
- */
- export function isSupportWebRTC(): boolean;
- /**
- * 检测浏览器是否支持屏幕共享
- * @public
- * @example
- * ```js
- * if (!isSupportScreenShare()) {
- * console.log(`当前浏览器不支持屏幕共享`);
- * }
- * ```
- */
- export function isSupportScreenShare(): boolean;
- /**
- * 检测浏览器支持的音视频编解码格式
- * @public
- * @example
- * ```js
- * getSupportedCodec()
- * .then((codecs) => {
- * console.log(`浏览器支持的音频编解码格式有 ${codecs.audio},视频编解码格式有 ${codecs.video}`);
- * })
- * .catch((err) => {
- * console.log(`浏览器获取音视频编解码格式失败,${err}`);
- * });
- * ```
- */
- export function getSupportedCodec(): Promise<Codecs>;
- }
- declare module '__@urtc/sdk-web/event' {
- import { User } from '__@urtc/sdk-web/user';
- import { Stream } from '__@urtc/sdk-web/stream/stream';
- import { ConnectionStates } from '__@urtc/sdk-web/connection/types';
- import { LocalStream } from '__@urtc/sdk-web/stream/local-stream';
- import { RemoteStream } from '__@urtc/sdk-web/stream/remote-stream';
- import { NetworkQualities } from '__@urtc/sdk-web/stream/types';
- import { RtcError } from '__@urtc/sdk-web/error';
- /**
- * Rtc 用户事件类型:
- *
- * {@link RtcUserEvent 用户事件}
- * - user-joined - 有用户加入房间
- * - user-left - 有用户离开房间
- * - kick-off - 当前用户被踢出房间
- * @public
- * @example
- * ```js
- * client.on('user-joined', (event) => {
- * console.log(`用户 ${event.data.id} 加入`);
- * });
- * ```
- */
- export type RtcUserEventType = 'user-joined' | 'user-left' | 'kick-off';
- /**
- * Rtc 流事件类型:
- *
- * {@link RtcStreamEvent 流事件}
- * - stream-added - 有远端流加入,此时事件中的 data 为 {@link RemoteStream} 远端流
- * - stream-removed - 有远端流移除,此时事件中的 data 为 {@link RemoteStream} 远端流
- * - stream-subscribed - 远端流订阅完成,此时事件中的 data 为 {@link RemoteStream} 远端流
- * - stream-published - 本地流发布完成,此时事件中的 data 为 {@link LocalStream} 本地流
- * - stream-reconnecting - 流正在重连(本地流重新发布/远端流重新订阅),此时事件中的 data 为 {@link LocalStream} 本地流或 {@link RemoteStream} 远端流
- * - stream-reconnected - 流已重连(本地流已重新发布/远端流已重新订阅),此时事件中的 data 为 {@link LocalStream} 本地流或 {@link RemoteStream} 远端流
- * - mute-audio - 流的音频被 mute
- * - unmute-audio - 流的音频被取消 mute
- * - mute-video - 流的视频被 mute
- * - unmute-video - 流的视频被取消 mute
- * @public
- * @example
- * ```js
- * client.on('stream-add', (event) => {
- * client.subscribe(event.data);
- * });
- * ```
- *
- * **特别地,以下事件需在单条流上进行监听**
- * - screen-sharing-stopped - 屏幕共享流被中止,此时事件中的 data 为 {@link LocalStream} 本地流
- * - audio-track-ended - 音频被中止,此时事件中的 data 为 {@link LocalStream} 本地流
- * - first-key-frame - 接收到远端流的首帧
- * @example
- * ```js
- * localStream.on('screen-sharing-stopped', (event) => {
- * // 此事件只针对本地流有效,若本地流已发布,监听到此事件后,可以决定要不要取消发布
- * client.unpublish(event.data);
- * event.data.destroy();
- * });
- * ```
- * @example
- * ```js
- * stream.on('first-key-frame', (event) => {
- * console.log(`stream ${event.data} got first key frame`);
- * });
- * ```
- */
- 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';
- /**
- * Rtc 播放器事件类型:
- *
- * {@link RtcPlayerEvent 播放器事件}
- * - player-status-change - 流播放器状态改变
- * **注,此事件需在单条流上进行监听**
- * @public
- * @example
- * ```js
- * stream.on('player-status-change', (event) => {
- * const { data } = event;
- * const { type, status } = data;
- * console.log(`stream's ${type} status changed to ${status}`);
- * });
- * ```
- */
- export type RtcPlayerEventType = 'player-status-change';
- /**
- * 播放状态改变事件对应数据
- * @public
- */
- export interface PlayerEventData {
- /**
- * 类型,音频/视频
- */
- type: 'audio' | 'video';
- /**
- * 状态
- */
- status: 'playing' | 'paused';
- /**
- * 对应的流
- */
- stream: Stream;
- }
- /**
- * Rtc 客户端连接状态事件类型:
- *
- * {@link RtcConnectionStateEvent 连接状态事件}
- * - connection-state-changed - 连接状态改变
- * @public
- * @example
- * ```js
- * client.on('connection-state-changed', (event) => {
- * console.log(`连接状态:${event.data.previous} => ${event.data.current}`);
- * });
- * ```
- */
- export type RtcConnectionStateEventType = 'connection-state-changed';
- /**
- * Rtc 网络连接质量类型:
- *
- * {@link RtcNetworkQualityEvent 网络连接质量事件}
- * - network-quality - 上/下行网络质量
- * @public
- * @example
- * ```js
- * client.on('network-quality', (event) => {
- * console.log(`上行 / 下行网络质量:${event.data.uplink} / ${event.data.downlink}`);
- * });
- * ```
- */
- export type RtcNetworkQualityEventType = 'network-quality';
- /**
- * 设备变化事件
- * - device-changed - 设备变化(新增或移除)
- * @public
- * @example
- * ```js
- * client.on('device-changed', (event) => {
- * console.log(`${event.data.type} 设备已 ${event.data.status}`);
- * });
- * ```
- */
- export type RtcDeviceChangedEventType = 'device-changed';
- /**
- * 设备变化事件对应数据
- * @public
- */
- export interface DeviceChangedEventData {
- /**
- * 设备类型,麦克风/摄像头/扬声器
- */
- type: 'microphone' | 'camera' | 'loudspeaker';
- /**
- * 状态
- */
- status: 'remove' | 'add';
- /**
- * 对应的设备信息
- */
- device: MediaDeviceInfo;
- }
- /**
- * 错误事件
- * - error - 错误事件,当出现不可恢复错误后,会抛出此事件
- * @public
- * @example
- * ```js
- * client.on('error', (event) => {
- * console.log(`错误[${event.data.code}] - ${event.data.message}`);
- * });
- * ```
- */
- export type RtcErrorEventType = 'error';
- /**
- * Rtc 事件类型
- * @public
- */
- export type RtcEventType = RtcUserEventType | RtcStreamEventType | RtcConnectionStateEventType | RtcNetworkQualityEventType | RtcPlayerEventType | RtcDeviceChangedEventType | RtcErrorEventType;
- /**
- * Rtc 事件
- *
- * - 当 type - T 为 {@link RtcUserEventType} 事件时,data - S 为 {@link User} 类型
- * - 当 type - T 为 {@link RtcStreamEventType} 事件时,data - S 为 {@link LocalStream} 或 {@link RemoteStream} 类型
- * - 当 type - T 为 {@link RtcConnectionStateEventType} 事件时,data - S 为 {@link ConnectionStates} 类型
- * - 当 type - T 为 {@link RtcNetworkQualityEventType} 事件时,data - S 为 {@link NetworkQualities} 类型
- * - 当 type - T 为 {@link RtcPlayerEventType} 事件时,data - S 为 {@link PlayerEventData} 类型
- * - 当 type - T 为 {@link RtcDeviceChangedEventType} 事件时,data - S 为 {@link DeviceChangedEventData} 类型
- * - 当 type - T 为 {@link RtcErrorEventType} 事件时,data - S 为 {@link RtcError} 类型
- * @public
- */
- export interface RtcEvent<T, S> {
- type: T;
- data: S;
- }
- /**
- * Rtc 用户事件,事件类型参见 {@link RtcUserEventType}
- * @public
- */
- export type RtcUserEvent = RtcEvent<RtcUserEventType, User>;
- /**
- * Rtc 流事件,事件类型参见 {@link RtcStreamEventType}
- * @public
- */
- export type RtcStreamEvent = RtcEvent<RtcStreamEventType, Stream | LocalStream | RemoteStream>;
- /**
- * Rtc 连接状态事件,事件类型参见 {@link RtcConnectionStateEventType}
- * @public
- */
- export type RtcConnectionStateEvent = RtcEvent<RtcConnectionStateEventType, ConnectionStates>;
- /**
- * Rtc 网络连接质量事件,事件类型参见 {@link RtcNetworkQualityEventType}
- * @public
- */
- export type RtcNetworkQualityEvent = RtcEvent<RtcNetworkQualityEventType, NetworkQualities>;
- /**
- * Rtc 播放器事件,事件类型参见 {@link RtcPlayerEventType}
- * @public
- */
- export type RtcPlayerEvent = RtcEvent<RtcPlayerEventType, PlayerEventData>;
- /**
- * Rtc 设备列表变化事件,事件类型参见 {@link RtcDeviceChangeEventType}
- * @public
- */
- export type RtcDeviceChangedEvent = RtcEvent<RtcDeviceChangedEventType, DeviceChangedEventData>;
- /**
- * Rtc 错误事件,事件类型参见 {@link RtcErrorEventType}
- * @public
- */
- export type RtcErrorEvent = RtcEvent<RtcErrorEventType, RtcError>;
- }
- declare module '__@urtc/sdk-web/error' {
- /**
- * RTC 错误信息
- * 错误代码参见 {@link ErrorCode}
- * @public
- */
- export class RtcError extends Error {
- constructor(code: ErrorCode, message: string);
- /**
- * 错误码,参见 {@link ErrorCode}
- */
- code: ErrorCode;
- /**
- * 1000 - 非法参数
- */
- static readonly INVALID_PARAMETER = "1000";
- /**
- * 1001 - 非法操作
- */
- static readonly INVALID_OPERATION = "1001";
- /**
- * 1002 - 不支持
- */
- static readonly NOT_SUPPORT = "1002";
- /**
- * 1003 - 不存在
- */
- static readonly NOT_EXISTS = "1003";
- /**
- * 1004 - 请求失败
- */
- static readonly BAD_REQUEST = "1004";
- /**
- * 1999 - 其他错误
- */
- static readonly OTHERS = "1999";
- /**
- * 2000 - 网关不可达
- */
- static readonly GW_UNREACHABLE = "2000";
- /**
- * 2001 - 获取 Access Token 失败
- */
- static readonly GET_ACCESS_TOKEN_FAILED = "2001";
- /**
- * 2002 - Access Token 非法
- */
- static readonly ACCESS_TOKEN_INVALID = "2002";
- /**
- * 2003 - Websocket 连接失败
- */
- static readonly CONNECTION_FAILED = "2003";
- /**
- * 2004 - 加入房间失败
- */
- static readonly JOIN_FAILED = "2004";
- /**
- * 2005 - 未加入房间
- */
- static readonly NOT_JOIN = "2005";
- /**
- * 2006 - 正在加入房间
- */
- static readonly IS_JOINING = "2006";
- /**
- * 2007 - 正在离开房间
- */
- static readonly IS_LEAVING = "2007";
- /**
- * 2008 - 角色类型不匹配
- */
- static readonly ROLE_TYPE_NOT_MATCH = "2008";
- /**
- * 2009 - 信令服务器地址错误
- */
- static readonly SIGNAL_ADDRESS_INVALID = "2009";
- /**
- * 3000 - 流不存在
- */
- static readonly STREAM_NOT_EXISTS = "3000";
- /**
- * 3001 - 同类型的流已存在
- */
- static readonly STREAM_EXISTS = "3001";
- /**
- * 3002 - 音频不存在
- */
- static readonly AUDIO_NOT_EXISTS = "3002";
- /**
- * 3003 - 视频不存在
- */
- static readonly VIDEO_NOT_EXISTS = "3003";
- /**
- * 3004 - [中止错误] 尽管用户和操作系统都授予了访问设备硬件的权利,而且未出现可能抛出NotReadableError异常的硬件问题,但仍然有一些问题的出现导致了设备无法被使用。
- */
- static readonly ABORT_ERROR = "3004";
- /**
- * 3005 - [拒绝错误] 用户拒绝了当前的浏览器实例的访问请求;或者用户拒绝了当前会话的访问;或者用户在全局范围内拒绝了所有媒体访问请求。
- */
- static readonly NOT_ALLOWED_ERROR = "3005";
- /**
- * 3006 - [找不到错误] 找不到满足请求参数的媒体类型。
- */
- static readonly NOT_FOUND_ERROR = "3006";
- /**
- * 3007 - [无法读取错误] 尽管用户已经授权使用相应的设备,操作系统上某个硬件、浏览器或者网页层面发生的错误导致设备无法被访问。
- */
- static readonly NOT_READABLE_ERROR = "3007";
- /**
- * 3008 - [无法满足要求错误] 指定的要求无法被设备满足。
- */
- static readonly OVER_CONSTRAINED_ERROR = "3008";
- /**
- * 3009 - 流连接失败
- */
- static readonly PEERCONNECTION_FAILED = "3009";
- /**
- * 3010 - 流正在重连
- */
- static readonly IS_RECONNECTING = "3010";
- /**
- * 3011 - 流尚未发布
- */
- static readonly IS_UNPUBLISHED = "3011";
- /**
- * 3012 - 流正在发布
- */
- static readonly IS_PUBLISHING = "3012";
- /**
- * 3013 - 流正在取消发布
- */
- static readonly IS_UNPUBLISHING = "3013";
- /**
- * 3014 - 流已经发布
- */
- static readonly IS_PUBLISHED = "3014";
- /**
- * 3015 - 流尚未订阅
- */
- static readonly IS_UNSUBSCRIBED = "3015";
- /**
- * 3016 - 流正在订阅
- */
- static readonly IS_SUBSCRIBING = "3016";
- /**
- * 3017 - 流正在取消订阅
- */
- static readonly IS_UNSUBSCRIBING = "3017";
- /**
- * 3018 - 流已经订阅
- */
- static readonly IS_SUBSCRIBED = "3018";
- /**
- * 3019 - 自动播放被禁止错误
- */
- static readonly PLAY_NOT_ALLOWED = "3019";
- /**
- * 3020 - 音视频数据异常,未成功播放(一般为网络原因导致,拉流时音视频数据加载过慢)
- */
- static readonly PLAY_PENDING = "3020";
- /**
- * 3021 - 因未曾调用或调用 play 方法失败,故不可恢复播放
- */
- static readonly RESUME_NOT_ALLOWED = "3021";
- /**
- * 3024 - ICE 建连失败
- */
- static readonly ICE_FAILED = "3024";
- }
- /**
- * RTC 错误代码
- *
- * 通用错误及代码
- * - 1000 - 非法参数
- * - 1001 - 非法操作
- * - 1002 - 不支持
- * - 1003 - 不存在
- * - 1004 - 请求失败
- * - 1999 - 其他错误
- *
- * 房间相关错误及代码
- * - 2000 - 网关不可达
- * - 2001 - 获取 Access Token 失败
- * - 2002 - Access Token 非法
- * - 2003 - Websocket 连接失败
- * - 2004 - 加入房间失败
- * - 2005 - 未加入房间
- * - 2006 - 正在加入房间
- * - 2007 - 正在离开房间
- * - 2008 - 角色类型不匹配
- * - 2009 - 信令服务器地址错误
- *
- * 流相关错误及代码
- * - 3000 - 流不存在
- * - 3001 - 同类型的流已存在
- * - 3002 - 音频不存在
- * - 3003 - 视频不存在
- * - 3004 - [中止错误] 尽管用户和操作系统都授予了访问设备硬件的权利,而且未出现可能抛出NotReadableError异常的硬件问题,但仍然有一些问题的出现导致了设备无法被使用。
- * - 3005 - [拒绝错误] 用户拒绝了当前的浏览器实例的访问请求;或者用户拒绝了当前会话的访问;或者用户在全局范围内拒绝了所有媒体访问请求。
- * - 3006 - [找不到错误] 找不到满足请求参数的媒体类型。
- * - 3007 - [无法读取错误] 尽管用户已经授权使用相应的设备,操作系统上某个硬件、浏览器或者网页层面发生的错误导致设备无法被访问。
- * - 3008 - [无法满足要求错误] 指定的要求无法被设备满足。
- * - 3009 - 流连接失败
- * - 3010 - 流正在重连
- * - 3011 - 流尚未发布
- * - 3012 - 流正在发布
- * - 3013 - 流正在取消发布
- * - 3014 - 流已经发布
- * - 3015 - 流尚未订阅
- * - 3016 - 流正在订阅
- * - 3017 - 流正在取消订阅
- * - 3018 - 流已经订阅
- * - 3019 - 自动播放被禁止错误
- * - 3020 - 音视频数据异常,未成功播放(一般为网络原因导致,拉流时音视频数据加载过慢)
- * - 3021 - 因未曾调用或调用 play 方法失败,故不可恢复播放
- * - 3024 - ICE 建连失败
- * @public
- */
- export type ErrorCode = typeof RtcError[Exclude<keyof typeof RtcError, 'prototype' | 'getCode' | 'stackTraceLimit' | 'prepareStackTrace' | 'captureStackTrace'>];
- }
- declare module '__@urtc/sdk-web/user' {
- /**
- * 用户信息
- * @public
- */
- export class User {
- /**
- * 用户ID
- */
- id: string;
- }
- }
- declare module '__@urtc/sdk-web/stream/stream' {
- import { EventEmitter } from '__@urtc/sdk-web/event-emitter';
- import { PlayOptions, SnapshotOptions } from '__@urtc/sdk-web/types';
- import { MediaType, StreamStats } from '__@urtc/sdk-web/stream/types';
- /**
- * LocalStream 和 RemoteStream 的基类
- * @public
- */
- export class Stream extends EventEmitter {
- /**
- * 当前流ID
- */
- id: string;
- /**
- * 当前流所属用户的ID
- * 注:若创建本地流时指定的 userId 与 join 时指定的 userId 不同,那么发布本条流时,流的 userId 将会自动被自动更新为 join 时指定的 userId
- */
- userId: string;
- /**
- * 是否为本地流
- */
- readonly isLocal: boolean;
- /**
- * 当前流包含的媒体流,关于媒体流,请详见 [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream)。
- */
- readonly mediaStream: MediaStream;
- /**
- * 获取流的媒体类型
- * @example
- * ```js
- * const type = stream.getMediaType();
- * ```
- */
- getMediaType(): MediaType;
- /**
- * 当前流是否 mute 了音频
- */
- audioMuted: boolean;
- /**
- * 当前流是否 mute 了视频
- */
- videoMuted: boolean;
- /**
- * 判断当前流是否有音频
- * @example
- * ```js
- * const result = stream.hasAudio();
- * ```
- */
- hasAudio(): boolean;
- /**
- * 判断当前流是否有视频
- * @example
- * ```js
- * const result = stream.hasVideo();
- * ```
- */
- hasVideo(): boolean;
- /**
- * mute 当前流的音频
- * * 本地流调用此方法时,将不向服务器推送音频数据,远端用户将收到 `mute-audio` 的事件通知
- * * 远端流调用此方法时,仅为不从服务器拉取音频数据,并无事件通知远端用户
- * @example
- * ```js
- * const result = stream.muteAudio();
- * console.log(`stream's audio is muted ${stream.audioMuted}`);
- * ```
- * @returns 操作是否成功
- */
- muteAudio(): boolean;
- /**
- * unmute 当前流的音频
- * * 本地流调用此方法时,将向服务器推送音频数据,远端用户将收到 `unmute-audio` 的事件通知
- * * 远端流调用此方法时,会从服务器拉取音频数据,并无事件通知远端用户
- * @example
- * ```js
- * const result = stream.unmuteAudio();
- * console.log(`stream's audio is muted ${stream.audioMuted}`);
- * ```
- * @returns 操作是否成功
- */
- unmuteAudio(): boolean;
- /**
- * mute 当前流的视频
- * * 本地流调用此方法时,将不向服务器推送视频数据,远端用户将收到 `mute-video` 的事件通知
- * * 远端流调用此方法时,仅为不从服务器拉取视频数据,并无事件通知远端用户
- * @example
- * ```js
- * const result = stream.muteVideo();
- * console.log(`stream's video is muted ${stream.videoMuted}`);
- * ```
- * @returns 操作是否成功
- */
- muteVideo(): boolean;
- /**
- * unmute 当前流的视频
- * * 本地流调用此方法时,将向服务器推送视频数据,远端用户将收到 `unmute-video` 的事件通知
- * * 远端流调用此方法时,会从服务器拉取视频数据,并无事件通知远端用户
- * @example
- * ```js
- * const result = stream.unmuteVideo();
- * console.log(`stream's video is muted ${stream.videoMuted}`);
- * ```
- * @returns 操作是否成功
- */
- unmuteVideo(): boolean;
- /**
- * 播放当前流
- * @param container - 播放音视频时,包裹 video 标签所用的容器元素或容器元素的 ID
- * @param opts - 其他播放参数,参见{@link PlayOptions}
- * @example
- * ```js
- * const container = 'xxx'; // 比如 id 为 xxx 的 div 元素
- * stream
- * .play(container)
- * .catch((err) => {
- * console.log(`播放失败: ${err}`); // 一般由于浏览器对自动播放的限制导致播放失败
- * });
- * ```
- * @reject {@link RtcError}
- */
- play(container: HTMLElement | string, opts?: PlayOptions): Promise<void>;
- /**
- * 恢复播放流,一般由于浏览器限制无法自动播放时,可提示用户手动触发该方法进行恢复播放
- * @example
- * ```js
- * stream
- * .resume()
- * .catch((err) => {
- * console.log(`恢复播放失败:${err}`);
- * });
- * ```
- */
- resume(): Promise<void>;
- /**
- * 停止播放当前流
- * @example
- * ```js
- * stream.stop();
- * ```
- */
- stop(): void;
- /**
- * 获取当前流的音量大小,只有当本地流或远端流中有音频数据才有效。
- * @example
- * ```js
- * setInterval(() => {
- * const level = stream.getAudioLevel();
- * if (level > 0) {
- * console.log(`user ${stream.userId} is speaking`);
- * }
- * }, 200);
- * ```
- */
- getAudioLevel(): number;
- /**
- * 获取流发布或订阅后的统计数据
- * @example
- * ```js
- * stream
- * .getStats()
- * .then((stats) => {
- * console.log('当前流的统计数据为: ', stats);
- * });
- * ```
- */
- getStats(): Promise<StreamStats>;
- /**
- * 对当前流进行截屏,可用于页面展示或下载保存
- * @param opts - 截屏参数,选传,参见{@link SnapshotOptions}
- * @example
- * ```js
- * stream.snapshot({filename: 'xxx.jpg'})
- * .then((pic) => {
- * console.log('截屏图像', pic);
- * })
- * .catch((err) => {
- * console.log('截屏失败', err);
- * });
- * ```
- */
- snapshot(opts?: SnapshotOptions): Promise<string>;
- }
- }
- declare module '__@urtc/sdk-web/server' {
- /**
- * 服务器配置,可设置置网关(gateway)、信令(signal)、日志(log)服务器地址
- * 注:
- * 1. gateway 和 signal 须二选一进行设置
- * 2. 没有日志服务器时,log 可不设
- * @public
- */
- export interface ServerConfig {
- /**
- * 网关地址,如 'https://my-rtc.com.cn'
- */
- gateway?: string;
- /**
- * 信令服务器地址,如 'wss://my-rtc.com.cn:5005'
- */
- signal?: string;
- /**
- * 日志服务器地址,如 'https://log.my-rtc.com.cn'
- */
- log?: string;
- }
- /**
- * 用于私有化部署时,指定部署的服务器地址
- * @param conf - 服务器配置,具体描述参见 ServerConfig 的说明
- * @public
- * @example
- * ```js
- * setServers({
- * gateway: 'https://my-rtc.com', // 指定网关
- * log: 'https://log.my-rtc.com', // 指定日志服务器
- * });
- * ```
- *
- * **特别地,单信令服务器时,不需要网关进行分配信令服务器,可以直接指定信令服务器**
- * ```js
- * setServers({
- * signal: 'wss://my-rtc.com:5005', // 直接指定信令服务器
- * log: 'https://log.my-rtc.com', // 指定日志服务器
- * });
- * ```
- * @throws {@link RtcError}
- */
- export function setServers(conf: ServerConfig): void;
- }
- declare module '__@urtc/sdk-web/plugin' {
- /**
- * @public
- */
- export interface StreamPlugin {
- name: string;
- install: Function;
- }
- /**
- * @public
- */
- export interface ClientPlugin {
- name: string;
- install: Function;
- }
- }
- declare module '__@urtc/sdk-web/version' {
- /**
- * 当前 sdk 的版本号
- * @public
- */
- export const version: string;
- }
- declare module '__@urtc/sdk-web/event-emitter' {
- import { RtcEventType, RtcUserEventType, RtcUserEvent, RtcStreamEventType, RtcStreamEvent, RtcConnectionStateEventType, RtcConnectionStateEvent, RtcNetworkQualityEventType, RtcNetworkQualityEvent, RtcPlayerEventType, RtcPlayerEvent, RtcDeviceChangedEventType, RtcDeviceChangedEvent, RtcErrorEventType, RtcErrorEvent } from '__@urtc/sdk-web/event';
- /**
- * 事件监听函数
- * 其中 T 为 RtcEvent 泛型
- * @private
- */
- 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;
- /**
- * 事件监听函数
- * 其中 RtcEventInstance 为事件实例
- * > 注:使用 typescript 时,会根据 T {@link RtcEventType} 类型自动推断 {@link RtcEvent} 的类型。
- */
- export interface Listener<T> {
- (event: RtcEventInstance<T>): void;
- }
- /**
- * @private
- */
- export class EventEmitter {
- /**
- * 监听流对象事件
- * @param type - 流事件类型
- * @param listener - 流事件监听函数
- */
- on<T extends RtcEventType>(type: T, listener: Listener<T>): EventEmitter;
- /**
- * 取消监听流对象事件
- * @param type - 流对象事件类型,特别的,当为 '*' 时,取消监听所有事件
- * @param listener - 流对象事件监听函数
- */
- off<T extends RtcEventType | '*'>(type: T, listener: Listener<T>): EventEmitter;
- }
- }
- declare module '__@urtc/sdk-web/stream/types' {
- /**
- * 音频编解码格式
- */
- export type AudioCodec = 'opus';
- /**
- * 视频编解码格式
- * @note 'h265' 目前仅部分浏览器在开启试验性功能时才支持,如 Safari 开启 `WebRTC H265 codec`
- */
- export type VideoCodec = 'vp8' | 'h264' | 'h265';
- /**
- * 流的音频的统计数据
- */
- export interface AudioStats {
- /**
- * 音频码率,获取失败时为 -1
- */
- bitrate: number;
- /**
- * 音频丢包率,获取失败时为 -1
- */
- packetLossRate: number;
- /**
- * 音频音量,获取失败时为 -1
- */
- volume: number;
- /**
- * 音频编码格式,获取失败时为 ''
- */
- codec: AudioCodec;
- }
- /**
- * 流的视频的统计数据
- */
- export interface VideoStats {
- /**
- * 视频码率,获取失败时为 -1
- */
- bitrate: number;
- /**
- * 视频丢包率,获取失败时为 -1
- */
- packetLossRate: number;
- /**
- * 视频帧率,获取失败时为 -1
- */
- framerate: number;
- /**
- * 视频宽,获取失败时为 -1
- */
- width: number;
- /**
- * 视频高,获取失败时为 -1
- */
- height: number;
- /**
- * 视频编码格式,获取失败时为 ''
- */
- codec: VideoCodec;
- }
- /**
- * 流的网络连接统计数据
- */
- export interface NetworkStats {
- /**
- * 网络往返时间,获取失败时为 -1
- */
- rtt: number;
- }
- /**
- * 已发布/已订阅流的统计数据
- */
- export interface StreamStats {
- /**
- * 流包含音频时,音频统计数据
- */
- audio?: AudioStats;
- /**
- * 流包含视频时,视频统计数据
- */
- video?: VideoStats;
- /**
- * 流的网络连接统计数据
- */
- network?: NetworkStats;
- }
- /**
- * 流的媒体类型, camera - 主视频流,screen - 辅助视频流,通常是一个屏幕分享流
- */
- export type MediaType = 'camera' | 'screen';
- /**
- * 切换设备的类型
- */
- export type SwitchDeviceType = 'audio' | 'video';
- /**
- * 流的网络质量评分,有 '0' | '1' | '2' | '3' | '4' | '5' | '6'
- * - '0': 网络质量未知
- * - '1': 网络质量优秀
- * - '2': 网络质量良好
- * - '3': 网络质量一般
- * - '4': 网络质量较差
- * - '5': 网络质量糟糕
- * - '6': 网络连接断开
- */
- export type NetworkQuality = '0' | '1' | '2' | '3' | '4' | '5' | '6';
- /**
- * 推(上行)/拉(下行)流的网络质量
- */
- export interface NetworkQualities {
- /**
- * 推(上行)流的网络质量
- */
- uplink: NetworkQuality;
- /**
- * 拉(下行)流的网络质量
- */
- downlink: NetworkQuality;
- }
- }
- declare module '__@urtc/sdk-web/stream/profile' {
- /**
- * 预设的视频 Profile
- *
- * 名称 | 视频宽 | 视频高 | 帧率 (fps) | 码率 (kbps)
- * :-: | :-: | :-: | :-: | :-:
- * 180p | 240 | 180 | 15 | 200
- * 180p_2 | 320 | 180 | 15 | 300
- * 240p | 320 | 240 | 15 | 400
- * 360p | 480 | 360 | 15 | 400
- * 360p_2 | 640 | 360 | 15 | 500
- * 480p | 640 | 480 | 15 | 600
- * 720p | 1280 | 720 | 15 | 1000
- * 720p_2 | 1280 | 720 | 15 | 1500
- * 720p_3 | 1280 | 720 | 30 | 2000
- * 1080p | 1920 | 1080 | 15 | 1500
- * 1080p_2 | 1920 | 1080 | 15 | 2000
- * 1080p_3 | 1920 | 1080 | 30 | 2500
- */
- export type VideoProfile = '180p' | '180p_2' | '240p' | '360p' | '360p_2' | '480p' | '720p' | '720p_2' | '720p_3' | '1080p' | '1080p_2' | '1080p_3';
- /**
- * 预设的屏幕共享视频 Profile
- *
- * 名称 | 视频宽 | 视频高 | 帧率 (fps) | 码率 (kbps)
- * :-: | :-: | :-: | :-: | :-:
- * 480p | 640 | 480 | 5 | 600
- * 480p_2 | 640 | 480 | 30 | 1000
- * 720p | 1280 | 720 | 5 | 1000
- * 720p_2 | 1280 | 720 | 30 | 2000
- * 1080p | 1920 | 1080 | 5 | 1500
- * 1080p_2 | 1920 | 1080 | 30 | 2500
- */
- export type ScreenProfile = '480p' | '480p_2' | '720p' | '720p_2' | '1080p' | '1080p_2';
- /**
- * 自定义视频 Profile,请根据实际使用场景及网络环境,合理的设置
- * @example
- * ```js
- * { width: 640, height: 480, framerate: 15, bitrate: 500 }
- * ```
- */
- export interface CustomVideoProfile {
- /**
- * 视频宽,如:640
- */
- width: number;
- /**
- * 视频高,如:480
- */
- height: number;
- /**
- * 帧率 (fps),如:15
- */
- framerate: number;
- /**
- * 码率 (kbps),如:500
- */
- bitrate: number;
- }
- }
- declare module '__@urtc/sdk-web/connection/types' {
- /**
- * 连接状态类型:
- * - OPEN - 已连接
- * - CONNECTING - 连接中
- * - CLOSING - 断开中
- * - RECONNECTING - 重连中
- * - CLOSED - 已断开
- * @public
- */
- export type ConnectionState = 'OPEN' | 'CONNECTING' | 'CLOSING' | 'RECONNECTING' | 'CLOSED';
- /**
- * 客户端(Client)与服务器之间的{@link ConnectionState 连接状态}
- * @public
- */
- export interface ConnectionStates {
- /**
- * 当前连接状态
- */
- current: ConnectionState;
- /**
- * 之前连接状态
- */
- previous: ConnectionState;
- }
- }
|