绑定监听事件
stream.on(keyName: string, listenerFunction: () => {}): void
解除绑定监听事件
stream.off(keyName: string): void
切换扬声器设备
参数:
stream.setAudioOutput(deviceId: string): Promise<{ deviceId: string }>
切换摄像头、麦克风设备
参数:
stream.switchDevice(type: 'audio' | 'video', deviceId: string): Promise<boolean
关闭 stream 对象,销毁数据和事件
stream.close(): void
获取所有 mediaStream 数据
stream.getMediaStreams(): IGetMediaStreams;
interface IGetMediaStreams {
previewStreams: IStreamObj[];
streams: IStreamObj[];
pipelineStreams: IStreamObj[];
contentStreams: IStreamObj[];
}
interface IStreamObj {
stream: MediaStream | null;
domStream: TCustomStream[];
status: IStreamStatus;
// stream 类型
type: 'contentStream' | 'previewStream' | 'pipelineStream' | 'remoteStream';
// 分辨率
resolution: string;
}
初始化 stream 流对象,可配置初始选择的输出/输出设备
参数:
stream.init(config?: IStreamInitConfog = { devices: {} }): Promise<IResult>;
type IStreamInitConfog = {
devices: {
audioInputValue?: string;
videoInValue?: string;
audioOutputValue?: string;
};
};
interface IResult {
code: number;
msg: string;
detail: Object;
}
获取当前音量大小
参数:
stream.getAudioLevel(stream?: MediaStream): Promise<Number>
清理音量 context 对象,下次会重新实例化音量对象
stream.clearAudioLevel(): void
创建分享屏幕的流对象
兼容:v2.0.5+支持配置setting设置项;
stream.createContentStream(setting?: IContentSetting): Promise<IStreamObj[]>;
interface IContentSetting {
// 是否开启采集共享屏幕声音,默认是false,不采集声音;
screenAudio?: boolean;
}
interface IStreamObj {
stream: MediaStream | null;
status: IStreamStatus;
// stream 类型
type: 'contentStream' | 'previewStream' | 'pipelineStream' | 'remoteStream';
// 分辨率
resolution: string;
}
// Stream的状态:
// NORMAL:正常
// DOMSTRING:无流状态,定义domStream,用来创建流通道
// INVALID:已失效
export type IStreamStatus = 'NORMAL' | 'DOMSTRING' | 'INVALID'
获取 electron 平台上可分享的输入源列表:
stream.getElectronContentSources( desktopCapturer: desktopCapturer, types: any = ['window', 'screen']): Promise<ISource[]>;
interface ISource {
appIcon: any;
display_id: string;
id: string;
name: string;
// thumbnail type is NativeImage
thumbnail: any;
}
创建 electron 分享流
stream.createElectronContentStream(selectedSourceId: string): Promise<IStreamObj[]>;
// IStreamObj 同getElectronContentSources方法
获取用于预览的画面
stream.getPreviewStream( isVideo: boolean, isAudio: boolean, params = { video: {}, audio: {} }): Promise<MediaStream>
创建视频流的类型
stream.on("stream-status", (e: IStreamCurrent) => {}): void;
interface IStreamCurrent {
// NORMAL 采集正常
// SEND_ONLY 仅发送(无权限、无设备等无流入会情况)
// 其他异常,无法入会
type: 'NORMAL' | 'SEND_ONLY' | 'FAILED';
detail: string | IStreamError;
}
本地数据流监听,自定义 custom
布局需要处理此数据。用来匹配本地 video stream 流数据
stream.on("local-stream", (e: IStreamObj[]) => {});
interface IStreamObj {
// video stream
stream: MediaStream;
// 忽略
isSupport: boolean;
// stream 类型
type: string;
// 分辨率
resolution: string;
}
监听是否开始屏幕共享
stream.on('start-share-content', () => {
// 通过client对象推送contentStream屏幕共享流
client.publish(stream, { isShareContent: true });
}): void
监听是否结束屏幕共享
stream.on('stop-share-content', () => {
// 调用client对象的stop方法,停止关闭分享content
client.stopShareContent();
}): void