/// import { BeaconEvent, BeaconEventParam } from './types/beaconevent'; import { CommonFields } from './types/commonfields'; import { HttpRequest } from './transport/request'; import { BeaconInterceptor } from './interceptor/intercetpor'; import { RequestOptions } from 'http'; export interface BeaconOptions { /** 是否开启调试模式,如果开始调试模式,则可以使用灯塔的实时联调工具看到实时上报的日志 */ enableDebug?: boolean; /** 是否开启https,默认开启 */ enableHttps?: boolean; /** 是否开启自动重试,默认关闭(不确定灯塔的失败是不是保证原子性,即批量事件上报,失败即全部事件失败) */ enableRetry?: boolean; /** 是否使用自定义mac地址,如果不设置,则sdk自身会提供一个 */ mac?: string; /** 应用版本号 */ versionCode?: string; /** 批量上传事件的数量 */ sendBatchSize?: number; /** 代理 */ proxy?: string; } export interface BeaconOverview { pendingEventCount: number; failEventCount: number; sendedEventCount: number; requestCount: number; } export declare class Beacon { private static instance; /** 请求的HOST */ requestOption: RequestOptions; /** 批量上报事件的大小 */ sendBatchSize: number; /** 事件发送失败是否开启重试功能 */ enableRetry: boolean; /** 用于定时刷新事件的标志位 */ hasPendingFlushTask: boolean; /** 定时flush任务 */ flushTimeout: any; /** 请求格式要求的字段 */ commonFields: CommonFields; /** API模块 */ request: HttpRequest; /** beacon拦截器 */ beaconInterceptorList: BeaconInterceptor[]; /** 已有多少个事件上报,包含成功与失败的事件类型 */ sendedEventCount: number; /** 已发送过多少次请求,用于审计网络请求 */ requestCount: number; /** 等待上报的事件 */ pendingEventList: BeaconEvent[]; /** 上报失败的事件 */ failEventList: BeaconEvent[]; private constructor(); /** * 事件进入队列,判断队列是否已满,需要上报 * @param addedEvent */ private addEvent; /** * flush队列任务 */ private flush; /** * 调用API上报,如果失败,则把事件存储 * @param eventList */ private sendEvents; /** * 发送事件后,把请求情况发送给已注册的BeaconInterceptor * @param eventList */ private _sendEvents; /** * 初始化 * @param appKey 请在灯塔官方申请一个appkey * @param options 可选配置 */ static init(appKey: string, options?: BeaconOptions): void; /** * 添加监听上报概况的BeaconInterceptor,也可以通过这个接口给所有事件添加属性 * @param interceptor */ static addInterceptor(interceptor: BeaconInterceptor): void; /** * 立即上报事件 * @param eventName 事件名 * @param params 自定义参数 */ static onRealTimeEvent(eventName: string, params?: BeaconEventParam): void; /** * 上报事件 * @param eventName 事件名 * @param params 自定义参数 */ static onEvent(eventName: string, params?: BeaconEventParam): void; }