import EventEmitter from "./event-emitter";
import WebsocketHeartbeatJs from "websocket-heartbeat-js";
export type SocketConfig = Partial<{
    url: string;
    protocols: string | string[];
    pingTimeout: number;
    pongTimeout: number;
    reconnectTimeout: number;
    pingMsg: any;
    repeatLimit: null | number;
    interceptor: {
        request?: InterceptorRequest;
        response?: InterceptorResponse;
    };
}>;
/**
 * 日志消息体-操作类型
 */
declare const enum RuntimeLogActionType {
    /**
     * 空间启动
     */
    START = "start",
    /**
     * 空间停止
     */
    STOP = "stop",
    /**
     * 属性
     */
    PROPERTY = "property",
    /**
     * 规则
     */
    RULE = "rule",
    /**
     * 事件
     */
    EVENT = "event",
    /**
     * 计划
     */
    TASK = "task",
    /**
     * 模式
     */
    PATTERN = "pattern",
    /**
     * 指令
     */
    COMMAND = "command"
}
/**
 * 消息推送响应消息类型
 */
export declare const enum SocketResponseType {
    heartbeat = "SPACE_SUBSCRIBE_HEARTBEAT",//"心跳检测"
    spaceResourceDetail = "SPACE_RESOURCE_DETAIL",//空间资源操作详细
    spaceResourceChange = "SPACE_RESOURCE_CHANGE",// 空间资源变更推送
    spaceInfo = "SPACE_INFO",//空间基本信息
    spaceDeviceBind = "SPACE_DEVICE_BIND",// 空间设备绑定
    spaceDeviceOnoffline = "SPACE_DEVICE_ONOFFLINE",//空间设备上下线
    deviceProperty = "DEVICE_PROPERTY",// 设备属性推送
    deviceInfoChange = "DEVICE_INFO_CHANGE",// 设备信息变更推送
    runtimeLog = "RUNTIME_LOG",// 空间运行日志
    spaceEvent = "SPACE_EVENT",// 空间事件
    spaceProperty = "SPACE_PROPERTY",// 空间属性
    spaceInstanceInfo = "SPACE_INSTANCE_INFO",// 空间信息
    spaceNodeInfo = "SPACE_NODE_INFO",// 空间节点信息
    spaceMessagePlugin = "SPACE_MESSAGE_PLUGIN",// 空间插件消息
    spaceInstanceInit = "SPACE_INSTANCE_INIT"
}
export type PayloadMap = {
    [SocketResponseType.runtimeLog]: any;
    [SocketResponseType.spaceNodeInfo]: any;
    [SocketResponseType.spaceMessagePlugin]: any;
    [SocketResponseType.spaceInstanceInit]: any;
    [SocketResponseType.spaceProperty]: any;
    [SocketResponseType.deviceInfoChange]: DeviceInfoChangePayload;
    [SocketResponseType.deviceProperty]: DevicePropertyPayload;
    [SocketResponseType.spaceDeviceBind]: SpaceDeviceBindPayload;
    [SocketResponseType.spaceDeviceOnoffline]: SpaceDeviceStatusPayload;
    [SocketResponseType.spaceEvent]: SpaceEventPayload;
    [SocketResponseType.spaceInstanceInfo]: SpaceInstanceInfoPayload;
    [SocketResponseType.spaceInfo]: SpaceInfoPaylod;
    [SocketResponseType.spaceResourceChange]: SpaceResourceChangePayload;
};
export type SocketResponseBody<T extends keyof PayloadMap, D = PayloadMap[T]> = {
    event: string;
    type?: string;
    /** 消息id */
    messageId?: string;
    /** 消息类型 */
    messageType?: T;
    /** 数据载荷 */
    data?: SocketResponsePayload<D>[];
};
export type SocketResponsePayload<D> = D & {
    spaceId: string;
    spaceName: string;
    traceId: string;
};
/** 设备信息变更消息体 */
export type DeviceInfoChangePayload = {
    /** 设备id */
    deviceId: string;
    /** 产品id */
    prodId: string;
    /** 设备创建、删除时间 */
    time: any;
    /** 应用标记或tacosID */
    source: string;
    /** 操作类型 */
    actionType: "DEVICE_CREATED" | "DEVICE_REMOVED";
    /** iot消息信息 */
    iotMsgInfo: any;
};
/**
 * 设备属性消息体
 */
export type DevicePropertyPayload = {
    /** 动作类型 */
    actionType: "DEVICE_PROPERTIES";
    /** 设备id */
    deviceId: string;
    /** 设备属性 */
    property: Record<string, any>;
    /** 所有设备属性 */
    allProperty: Record<string, any>;
    /** 产品id */
    prodId: string;
    /** 时间戳  */
    timestamp: any;
    /** iot消息信息 */
    iotMsgInfo: any;
};
/** 空间设备绑定日志消息体 */
export type SpaceDeviceBindPayload = {
    spaceId: string;
    deviceId: string;
    actionType: "DEVICE_BIND" | "DEVICE_UNBIND";
};
/**空间设备在离线消息体 */
export type SpaceDeviceStatusPayload = {
    spaceId: string;
    deviceId: string;
    actionType: "DEVICE_ONLINE" | "DEVICE_OFFLINE";
};
/** 空间事件消息体 */
export type SpaceEventPayload = {
    /** 序列化id */
    serialVersionUID: number;
    /** 事件标识符 */
    identifier: string;
    /** 事件来源 */
    source: any;
    /** 事件名称 */
    name: string;
    /** 事件输出 */
    outputs: Record<string, any>;
    /** 事件类型 */
    actionType: "EVENT";
};
/** 空间信息变化消息体 */
export type SpaceInstanceInfoPayload = {
    actionType: "SPACE_ADD" | "SPACE_EDIT" | "SPACE_DELETE";
};
/** 空间属性消息体 */
export type SpaceInfoPaylod = {
    /** 空间属性 */
    property: Record<string, any>;
    /** 全部空间属性 */
    allProperty: Record<string, any>;
    timestamp: any;
    actionType: "SPACE_PROPERTIES";
};
/** 空间资源变化消息体 */
export type SpaceResourceChangePayload = {
    /** 资源类型 */
    resourceType: "device" | "plan" | "rule" | "event" | "mode" | "metrics";
    changeType: "add" | "edit" | "disable" | "enable";
    identifier: string;
};
/**
 * 空间日志消息体
 */
export type RuntimeLogPayload = {
    /**
     * 操作类型
     */
    actionType: RuntimeLogActionType;
    result: boolean;
    desc: string;
};
export type SocketResponse = {
    /** 消息id */
    id: string;
    spaceId: string;
    spaceName: string;
    traceId: string;
    time: any;
    /** 消息类型 */
    type: SocketResponseType;
    /** 数据载荷 */
    payload: Omit<SocketResponsePayload<Exclude<SocketResponseType, "heartbeat">>, "spaceId" | "spaceName" | "traceId">;
};
export type InterceptorRequest = (appCode: string, config: SocketConfig) => SocketConfig;
export type InterceptorResponse = (res: SocketResponse) => SocketResponse;
export declare class SocketInterceptor {
    requestList: Array<InterceptorRequest>;
    responseList: Array<InterceptorResponse>;
    constructor(config?: SocketConfig);
    request(handler: InterceptorRequest): void;
    response(handler: InterceptorResponse): void;
    merge(interceptor: SocketInterceptor): this;
}
declare class Socket extends EventEmitter {
    protected ws: WebsocketHeartbeatJs | undefined;
    config: SocketConfig;
    interceptor: SocketInterceptor | undefined;
    channelId: string | undefined;
    appCode: string;
    AllowEmpty: boolean;
    constructor(appCode: string, config: SocketConfig, interceptor?: SocketInterceptor);
    /**
     * 删除指定监听
     * @param event
     * @param listener
     */
    removeListener(event: string, listener: Function): void;
    /**
     * 删除所有监听或者指定的所有监听
     * @param event
     */
    removeAllListener(event?: string): void;
    /**
     * 注册监听
     * @param event
     * @param listener
     */
    addListener(event: string, listener: Function): this;
    /**
     * 触发监听的事件
     * emit event
     * @param event
     * @param args
     */
    emit(event: string, ...args: any[]): void;
    /**
     * 尝试建立连接
     */
    connect(): void;
    send(data: any): void;
    /**
     * 关闭连接
     */
    close(): void;
}
export default Socket;
/**
 * 拦截器：基于websocket连接进行数字签名处理
 * @param appCode 应用编码
 * @param secret 数字签名私钥
 */
/**
 * 拦截器：基于websocket连接进行数字签名处理（已废弃：默认将appCode透传至protocols子协议字段请求头中）
 * @param appCode 应用编码
 */
export declare function socketSignInterceptor(): (appCode: string, config: SocketConfig) => Partial<{
    url: string;
    protocols: string | string[];
    pingTimeout: number;
    pongTimeout: number;
    reconnectTimeout: number;
    pingMsg: any;
    repeatLimit: null | number;
    interceptor: {
        request?: InterceptorRequest;
        response?: InterceptorResponse;
    };
}>;
