hikvideoctrl
Version:
海康威视无插件视频播放 SDK 封装库,支持 TypeScript/ESM,提供设备管理、视频播放、PTZ控制、录像管理等完整功能。
520 lines (478 loc) • 13.1 kB
TypeScript
export declare const AudioErrorCode: {
AlreadyOpen: number;
AlreadyClosed: number;
};
declare interface CallbackOptions {
success?: (xmlDoc?: any) => void;
error?: (status?: number, xmlDoc?: any) => void;
timeout?: number;
}
export declare interface CaptureOptions {
windowIndex?: number;
fileName?: string;
format?: string;
callback?: (imageData: Uint8Array) => void;
}
/**
* 创建响应处理器
* @param successCallback 成功回调
* @param errorCallback 错误回调
* @returns 处理器对象
*/
export declare function createResponseHandler<T = any>(successCallback?: (data?: T) => void, errorCallback?: (status?: number, xmlDoc?: Document, error?: any) => void): {
success: (data?: T) => void;
error: (status?: number, xmlDoc?: Document, error?: any) => void;
};
export declare const DefaultPorts: {
HTTP: number;
HTTPS: number;
RTSP: number;
};
/**
* 延迟执行
* @param ms 延迟毫秒数
* @returns Promise
*/
export declare function delay(ms: number): Promise<void>;
export declare interface DeviceInfo {
ip: string;
port: number;
username: string;
password: string;
protocol?: number;
}
export declare interface DownloadRecordOptions {
useDateDir?: boolean;
}
/**
* HTML实体编码
* @param str 要编码的字符串
* @returns 编码后的字符串
*/
export declare function encodeString(str: string): string;
export declare const ErrorCodes: Record<number, string>;
declare interface EventCallback {
(data?: any): void;
}
export declare const FileFormat: {
readonly JPG: "jpg";
readonly JPEG: "jpeg";
readonly PNG: "png";
readonly BMP: "bmp";
};
/**
* 海康威视WebSDK工具函数库
*/
/**
* 格式化日期时间
* @param date 日期对象
* @param format 格式字符串
* @returns 格式化后的时间字符串
*/
export declare function formatDate(date: Date, format?: string): string;
/**
* 生成设备标识符
* @param ip IP地址
* @param port 端口号
* @returns 设备标识符
*/
export declare function generateDeviceIdentify(ip: string, port: number): string;
/**
* 生成唯一文件名
* @param prefix 文件名前缀
* @param extension 文件扩展名
* @returns 唯一文件名
*/
export declare function generateUniqueFileName(prefix: string, extension: string): string;
/**
* 获取当前时间字符串
* @param format 时间格式,默认为 'yyyy-MM-dd hh:mm:ss'
* @returns 当前时间字符串
*/
export declare function getCurrentTimeString(format?: string): string;
/**
* 获取今天的时间范围
* @returns 包含开始时间和结束时间的对象
*/
export declare function getTodayTimeRange(): {
startTime: string;
endTime: string;
};
/**
* 获取窗口尺寸
* @returns 包含宽度和高度的对象
*/
export declare function getWindowSize(): {
width: number;
height: number;
};
declare class HikVideoController {
private currentWindowIndex;
private callbacks;
private isInitialized;
constructor();
/**
* 检查浏览器是否支持无插件模式
*/
static isSupportNoPlugin(): boolean;
/**
* 初始化插件
*/
initPlugin(options: InitOptions): Promise<void>;
/**
* 登录设备
*/
login(deviceInfo: DeviceInfo): Promise<void>;
/**
* 登出设备
*/
logout(deviceId: string): Promise<void>;
/**
* 获取设备信息
*/
getDeviceInfo(deviceId: string): Promise<any>;
/**
* 获取设备端口信息
*/
getDevicePort(deviceId: string): any;
/**
* 获取通道信息
*/
getChannels(deviceId: string): Promise<any[]>;
/**
* 获取对讲通道信息
*/
getAudioInfo(deviceId: string): Promise<any>;
/**
* 开始预览
*/
startPreview(options: PreviewOptions): Promise<void>;
/**
* 停止预览
*/
stopPreview(windowIndex?: number): Promise<void>;
/**
* 停止所有预览
*/
stopAllPreview(): Promise<void>;
/**
* 开始回放
*/
startPlayback(options: PlaybackOptions): Promise<void>;
/**
* 暂停回放
*/
pausePlayback(): Promise<void>;
/**
* 恢复回放
*/
resumePlayback(): Promise<void>;
/**
* 快进
*/
playFast(): Promise<void>;
/**
* 慢放
*/
playSlow(): Promise<void>;
/**
* PTZ控制
*/
ptzControl(options: PTZOptions, stop?: boolean): Promise<void>;
/**
* 设置预置点
*/
setPreset(presetId: number): Promise<void>;
/**
* 调用预置点
*/
goPreset(presetId: number): Promise<void>;
/**
* 搜索录像
*/
searchRecord(options: SearchRecordOptions): Promise<any[]>;
/**
* 开始录像
*/
startRecord(options: RecordOptions): Promise<void>;
/**
* 停止录像
*/
stopRecord(): Promise<void>;
/**
* 抓图
*/
capturePicture(options: CaptureOptions): Promise<void>;
/**
* 打开声音
*/
openSound(): Promise<void>;
/**
* 关闭声音
*/
closeSound(): Promise<void>;
/**
* 设置音量
*/
setVolume(volume: number): Promise<void>;
/**
* 启用电子放大
*/
enableEZoom(): Promise<void>;
/**
* 禁用电子放大
*/
disableEZoom(): Promise<void>;
/**
* 启用3D放大
*/
enable3DZoom(windowIndex?: number, callback?: (zoomInfo: any) => void): Promise<void>;
/**
* 禁用3D放大
*/
disable3DZoom(): boolean;
/**
* 全屏显示
*/
fullScreen(): void;
/**
* 切换窗口数量
*/
changeWindowCount(windowType: number): void;
/**
* 设置码流加密秘钥
*/
setSecretKey(secretKey: string, windowIndex?: number): Promise<void>;
/**
* 获取OSD时间
*/
getOSDTime(): Promise<string>;
/**
* 获取窗口状态
*/
getWindowStatus(windowIndex?: number): any;
/**
* 获取本地配置
*/
getLocalConfig(): any;
/**
* 设置本地配置
*/
setLocalConfig(config: string): boolean;
/**
* 开始下载录像文件
*/
startDownloadRecord(deviceIdentify: string, playbackURI: string, fileName: string, options?: {
bDateDir?: boolean;
}): Promise<void>;
/**
* 按时间下载录像文件
*/
startDownloadRecordByTime(deviceIdentify: string, playbackURI: string, fileName: string, startTime: string, endTime: string, options?: {
bDateDir?: boolean;
}): Promise<void>;
/**
* 导出设备配置
*/
exportDeviceConfig(deviceIdentify: string, password: string): Promise<void>;
/**
* 导入设备配置
*/
importDeviceConfig(deviceIdentify: string, fileName: string, password: string, file: File): Promise<void>;
/**
* 重启设备
*/
restart(deviceIdentify: string, options?: CallbackOptions): Promise<void>;
/**
* 重新连接设备
*/
reconnect(deviceIdentify: string, options?: CallbackOptions): Promise<void>;
/**
* 恢复设备默认设置
*/
restoreDefault(deviceIdentify: string, mode: 'basic' | 'full', options?: CallbackOptions & {
timeout?: number;
}): Promise<void>;
/**
* 开始设备升级
*/
startUpgrade(deviceIdentify: string, fileName: string, file: File): Promise<void>;
/**
* 获取升级进度
*/
getUpgradeProgress(deviceIdentify: string): Promise<{
percent: number;
upgrading: boolean;
}>;
/**
* 打开文件选择对话框
*/
openFileDlg(type: 0 | 1): Promise<{
szFileName: string;
file: File;
}>;
/**
* 发送HTTP请求
*/
sendHTTPRequest(deviceIdentify: string, url: string, options: any): Promise<any>;
/**
* 获取文字叠加配置
*/
getTextOverlay(url: string, deviceIdentify: string, options?: CallbackOptions): Promise<any>;
/**
* 获取窗口集合
*/
getWndSet(): any[];
on(event: string, callback: EventCallback): void;
off(event: string, callback?: EventCallback): void;
private emit;
private initEventHandlers;
static formatDate: typeof formatDate;
static getCurrentTimeString: typeof getCurrentTimeString;
static getTodayTimeRange: typeof getTodayTimeRange;
static generateDeviceIdentify: typeof generateDeviceIdentify;
static parseDeviceIdentify: typeof parseDeviceIdentify;
static isValidIP: typeof isValidIP;
static isValidPort: typeof isValidPort;
static isValidTimeRange: typeof isValidTimeRange;
}
export { HikVideoController }
export default HikVideoController;
export declare interface InitOptions {
containerId: string;
width?: string;
height?: string;
windowType?: number;
packageType?: number;
noPlugin?: boolean;
onWindowSelect?: (windowIndex: number) => void;
onWindowDoubleClick?: (windowIndex: number, isFullScreen: boolean) => void;
onEvent?: (eventType: number, param1: number, param2: number) => void;
onError?: (windowIndex: number, errorCode: number, error: any) => void;
onPerformanceLack?: () => void;
onSecretKeyError?: (windowIndex: number) => void;
}
/**
* 验证IP地址格式
* @param ip IP地址字符串
* @returns 是否为有效的IP地址
*/
export declare function isValidIP(ip: string): boolean;
/**
* 验证端口号格式
* @param port 端口号
* @returns 是否为有效的端口号
*/
export declare function isValidPort(port: number): boolean;
/**
* 检查时间范围是否有效
* @param startTime 开始时间字符串
* @param endTime 结束时间字符串
* @returns 是否为有效的时间范围
*/
export declare function isValidTimeRange(startTime: string, endTime: string): boolean;
/**
* 加载XML字符串为XML文档对象
* @param xmlString XML字符串
* @returns XML文档对象或null
*/
export declare function loadXML(xmlString: string): Document | null;
/**
* 解析设备标识符
* @param deviceIdentify 设备标识符
* @returns 包含IP和端口的对象
*/
export declare function parseDeviceIdentify(deviceIdentify: string): {
ip: string;
port: number;
};
export declare interface PlaybackOptions extends PreviewOptions {
startTime: string;
endTime: string;
}
export declare interface PreviewOptions {
deviceId: string;
channelId: number;
streamType?: number;
windowIndex?: number;
isZeroChannel?: boolean;
useProxy?: boolean;
}
/**
* Promise化WebVideoCtrl方法
* @param method WebVideoCtrl方法
* @param args 方法参数
* @returns Promise
*/
export declare function promisify<T = any>(method: (...args: any[]) => any, ...args: any[]): Promise<T>;
export declare const ProtocolType: {
readonly HTTP: 1;
readonly HTTPS: 2;
};
export declare const PTZControlType: {
readonly Up: 1;
readonly Down: 2;
readonly Left: 3;
readonly Right: 4;
readonly UpLeft: 5;
readonly UpRight: 6;
readonly DownLeft: 7;
readonly DownRight: 8;
readonly Auto: 9;
readonly ZoomIn: 10;
readonly ZoomOut: 11;
readonly FocusIn: 12;
readonly FocusOut: 13;
readonly IrisIn: 14;
readonly IrisOut: 15;
};
export declare interface PTZOptions {
windowIndex?: number;
ptzIndex: number;
speed?: number;
}
export declare interface RecordOptions {
windowIndex?: number;
fileName?: string;
useDateDir?: boolean;
}
export declare const RecordType: {
readonly RealPlay: "realplay";
readonly Playback: "playback";
};
export declare const SEARCH_RECORDS_PER_PAGE = 40;
export declare interface SearchRecordOptions {
deviceId: string;
channelId: number;
startTime: string;
endTime: string;
streamType?: number;
}
export declare const StreamType: {
readonly MainStream: 1;
readonly SubStream: 2;
};
/**
* 将XML文档对象转换为XML字符串
* @param xmlDoc XML文档对象
* @returns XML字符串
*/
export declare function toXMLString(xmlDoc: Document): string;
/**
* 将Uint8Array转换为Base64字符串
* @param uint8Array Uint8Array数据
* @returns Promise<string> Base64字符串
*/
export declare function uint8ArrayToBase64(uint8Array: Uint8Array): Promise<string>;
export declare const WindowType: {
readonly Single: 1;
readonly Four: 4;
readonly Nine: 9;
readonly Sixteen: 16;
};
export { }
declare global {
interface Window {
WebVideoCtrl: any;
}
}