UNPKG

@komponent/unifi-protect-lib

Version:

Node library for connecting to Ubiquiti Unifi Protect controllers and listen for events

98 lines (97 loc) 2.67 kB
import { AxiosRequestConfig, AxiosResponse } from "axios"; import WebSocket from "ws"; import { Logger } from "../types/Logging"; import { ProtectNvrBootstrap } from "../types/ProtectTypes"; declare class UnifiApiClient { private apiErrorCount; private apiLastSuccess; private log; authUrl: string; bootstrapUrl: string; updatesUrl: string; camerasUrl: string; host: string; private password; private username; private loginTimestamp; private loggedIn; private headers; private httpsAgent; bootstrap: ProtectNvrBootstrap | null; nvrName: string; private eventHeartbeatTimer; eventListener: WebSocket | null; eventListenerConfigured: boolean; constructor(log: Logger, host: string, username: string, password: string); /** * Utility to check the heartbeat of our listener. * * @private * @memberof UnifiApiClient */ private heartbeatEventListener; /** * Identify which NVR device type we're logging into and acquire a CSRF token if needed. * * @private * @return {*} {Promise<boolean>} * @memberof ProtectApi */ private acquireToken; /** * Log into UniFi Protect. * * @return {*} {Promise<boolean>} * @memberof ProtectApi */ private login; /** * Gets the current token from the stored cookie * * @private * @return {*} {string} * @memberof UnifiApiClient */ private getToken; private clearLoginCredentials; /** * Get our UniFi Protect NVR configuration. * * @private * @return {*} {Promise<boolean>} * @memberof UnifiApiClient */ private bootstrapProtect; /** * Connect to the realtime update events API. * * @private * @return {*} {Promise<boolean>} * @memberof UnifiCameraHandler */ listen(): Promise<WebSocket | null>; /** * Utility to let us streamline error handling and return checking from the Protect API. * * @param {RequestInfo} url * @param {RequestInit} [options={ method: "GET" }] * @param {boolean} [ensureLoggedIn=true] * @return {*} {(Promise<Response | null>)} * @memberof ProtectApi */ fetch(url: string, options?: AxiosRequestConfig, ensureLoggedIn?: boolean): Promise<AxiosResponse | null>; /** * Prints the current status of the API client * * @return {*} {boolean} * @memberof UnifiApiClient */ status(): boolean; /** * Initializes the API client * * @memberof UnifiApiClient */ init(): Promise<any>; } export default UnifiApiClient;