UNPKG

doorbird

Version:

Node JS library for the Doorbird LAN API.

454 lines (453 loc) 12.2 kB
type Enumerate<N extends number, Acc extends number[] = []> = Acc["length"] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc["length"]]>; type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>; /** * Utility method to retrieve the Doorstation's self signed certificate in PEM representation. * @param host host to retrieve the certificate for */ export declare function getDoorstationCertificate(host: string): Promise<string>; /** * Scheme for API communication with the door station. */ export declare enum Scheme { http = "http", https = "https" } /** * Options to initialize the Doorbird client. */ export interface DoorbirdOptions { /** * Scheme to connect to the Doorbid Door Station. */ scheme: Scheme; /** * Host / IP of the Door Station. */ host: string; /** * Username to access the API. */ username: string; /** * Password to access the API. */ password: string; /** * Provide the Doorstation's TLS certificate to avoid general acceptance of self-signed certificates. If you do not * provide a certificate, but specifiy 'https' as scheme, the certificate will be loaded from the configured host. */ certificate?: string; } /** * Generic response wrapper of the Doorbird API. */ export interface Response<Type> { BHA: Type; } /** * Basic BHA object for responses. */ export interface BaseBHA { RETURNCODE: string; } /** * Specific BHA object for session responses. */ export interface SessionBHA extends BaseBHA { SESSIONID: string; NOTIFICATION_ENCRYPTION_KEY: string; } /** * Specific BHA object for info responses. */ export interface DoorbirdInfoBHA extends BaseBHA { VERSION: DoorbirdInfoBHAVersion[]; } /** * Doorbird info object. */ export interface DoorbirdInfoBHAVersion { FIRMWARE: string; BUILD_NUMBER: string; WIFI_MAC_ADDR: string; RELAYS: string[]; "DEVICE-TYPE": string; } /** * Type for Doorbird favorites. */ export declare enum FavoriteType { sip = "sip", http = "http" } /** * Doorbird favorites. */ export type Favorites = { sip?: Favorite; http?: Favorite; }; /** * A single Doorbird favorite. */ export type Favorite = { [id: string]: FavoriteInfo; }; /** * Information on a Doorbird favorite. */ export interface FavoriteInfo { title: string; value: string; } /** * A schedule is an array of ScheduleEntries. */ export type Schedule = ScheduleEntry[]; /** * A single entry of a schedule. */ export interface ScheduleEntry { input: "doorbell" | "motion" | "rfid"; param?: string; output: ScheduleEntryOutput[]; } /** * Output of a schedule entry. */ export interface ScheduleEntryOutput { event: "notify" | "sip" | "relay" | "http"; param?: string; schedule: "once" | ScheduleEntrySchedule; } /** * Specific schedule for a schedule entry. */ export interface ScheduleEntrySchedule { "from-to"?: FromTo[]; weekdays?: FromTo[]; } /** * Object that defines a timespan. */ export interface FromTo { from: string; to: string; } /** * Specific BHA for SIP status. */ export interface SipStatusBHA extends BaseBHA { SIP: SipStatus[]; } /** * SIP status object. */ export interface SipStatus { ENABLE: string; PRIORITIZE_APP: string; REGISTER_URL: string; REGISTER_USER: string; REGISTER_AUTH_ID: string; REGISTER_PASSWORD: string; AUTOCALL_MOTIONSENSOR_URL: string; AUTOCALL_DOORBELL_URL: string; SPK_VOLUME: string; MIC_VOLUME: string; DTMF: string; "relais:1": string; "relais:2": string; LIGHT_PASSCODE: string; HANGUP_ON_BUTTON_PRESS: string; INCOMING_CALL_ENABLE: string; INCOMING_CALL_USER: string; ANC: string; LASTERRORCODE: string; LASTERRORTEXT: string; RING_TIME_LIMIT: string; CALL_TIME_LIMIT: string; } /** * Event object for doorbell rings. */ export interface RingEvent { intercomId: string; event: string; timestamp: Date; } /** * Event object for motion detection. */ export interface MotionEvent { intercomId: string; timestamp: Date; } /** * Callback for ring events. */ export type RingCallback = (event: RingEvent) => void; /** * Callback for motion events. */ export type MotionCallback = (event: MotionEvent) => void; /** * Wrapper class for a UDP socket, that is capable to handle Doorbird's UDP messages. */ export declare class DoorbirdUdpSocket { private username; private password; private client; private suppressBurst; private debug; private server; private lastEventTimestamp; private ringListeners; private motionListeners; private notificationEncryptionKey; /** * Construct a new DoorbirdUdpSocket * * @param port Doorbird sends to ports 6524 and 35344. * @param username username of the Doorbird user. * @param password password of the Doorbird user. * @param client the parent instance of the Doorbird api. * @param suppressBurst flag to suppress multiple burst messages (callback is only called once) */ constructor(port: 6524 | 35344, username: string, password: string, client: Doorbird, suppressBurst?: boolean, debug?: boolean); private log; private strech; private onMessage; private handleV1; private handleV2; private decryptV1; private decryptV2; private getNotificationEncryptionKey; /** * Register a ring listener. * * @param listener ring listener */ registerRingListener(listener: RingCallback): void; /** * Register a motion listner. * * @param listener motion listener */ registerMotionListener(listener: MotionCallback): void; /** * Close the UDP socket. */ close(): void; } /** * Doorbird client class. */ export default class Doorbird { private options; private http; /** * Construct a Doorbird client. * * @param options options for the Doorbird client */ constructor(options: DoorbirdOptions); /** * Initialize a session. * * @returns session response */ initializeSession(): Promise<Response<SessionBHA>>; /** * Destroy a session. * * @param session session response or id * @returns session response */ destroySession(session: Response<SessionBHA> | string): Promise<Response<SessionBHA>>; /** * Get info of the Doorbird installation. * * @returns Doorbird info response */ getInfo(): Promise<Response<DoorbirdInfoBHA>>; /** * Opens a door via a relay of your doorbird system. * * @deprecated use toggleRelay instead * @param relay the relay that opens the door * @returns http response of the call */ openDoor(relay: string): Promise<Response<BaseBHA>>; /** * Toggle a relay. * * @param relay the ID of the relay to be toggled * @returns base response */ toggleRelay(relay: string): Promise<Response<BaseBHA>>; /** * Enable the infra red lights of the door station. * * @returns base response */ lightOn(): Promise<Response<BaseBHA>>; /** * Get a list of favorites. * * @returns favorites list */ listFavorites(): Promise<Favorites>; /** * Create a new favorite. * * @param type new favorite type * @param favoriteInfo favorite info * @returns empty promise */ createFavorite(type: FavoriteType, favoriteInfo: FavoriteInfo): Promise<string>; /** * Update a favorite. * * @param id id of the favorite to be updated * @param type type of the favorite to be updated * @param favoriteInfo new favorite info * @returns empty promise */ updateFavorite(id: string, type: FavoriteType, favoriteInfo: FavoriteInfo): Promise<string>; private doCreateUpdateFavorite; /** * Delete a favorite. * * @param id id of the favorite to be deleted * @param type type of the favorite to be deleted * @returns empty promise */ deleteFavorite(id: string, type: FavoriteType): Promise<void>; /** * Get the schedule of the Doorbird system. * * @returns schedule response */ getSchedule(): Promise<Schedule>; /** * Create a schedule entry. * * @param scheduleEntry new schedule entry * @returns empty promise */ createScheduleEntry(scheduleEntry: ScheduleEntry): Promise<void>; /** * Update a schedule entry. * * @param scheduleEntry updated schedule entry * @returns empty promise */ updateScheduleEntry(scheduleEntry: ScheduleEntry): Promise<void>; /** * Delete a schedule entry. * * @param input input type of the entry to be deleted * @param param param of the entry to be deleted * @returns empty promise */ deleteScheduleEntry(input: "doorbell" | "motion" | "rfid", param: string | null): Promise<void>; /** * Restart the door station. * * @returns empty promise */ restart(): Promise<void>; /** * Create a SIP registration. * * @param user user for the sip registration * @param password password for the sip registration * @param url url for the sip registration * @returns empty promise */ sipRegistration(user: string, password: string, url: string): Promise<void>; /** * Initiate a SIP call. * * @param url url for the SIP call * @returns empty promise */ sipCall(url: string): Promise<void>; /** * End a SIP call. * * @returns empty promise */ sipHangup(): Promise<void>; /** * Update SIP settings. * * @param enable enable or disable SIP registration after device reboot * @param mic_volume microphone volume (1-100) * @param spk_volume speaker volume (1-100) * @param dtmf enable or disable DTMF support * @param relay1_passcode pincode for triggering the door open relay * @param incoming_call_enable enable or disable incoming calls * @param incoming_call_user Allowed SIP user which will be authenticated for Doorbird * @param anc enable or disable acoustic noise cancellation * @returns empty promise */ sipSettings(enable: 0 | 1, mic_volume: IntRange<1, 100>, spk_volume: IntRange<1, 100>, dtmf: 0 | 1, relay1_passcode: number, incoming_call_enable: 0 | 1, incoming_call_user: string, anc: 0 | 1, ringTimeLimit?: IntRange<10, 300>, callTimeLimit?: IntRange<30, 300>): Promise<void>; /** * Get the SIP status. * * @returns Specific BHA for SIP status */ sipStatus(): Promise<Response<SipStatusBHA>>; /** * Reset the SIP settings. * * @returns empty promise */ sipSettingsReset(): Promise<void>; /** * Start a UDP socket. * * @param port port to listen on * @param suppressBurst suppress multiple UDP messages into a single callback * @returns DoorbirdUdpSocket object */ startUdpSocket(port: 6524 | 35344, suppressBurst?: boolean, debug?: boolean): DoorbirdUdpSocket; /** * Get the Doorbird image url. * * @returns image url */ getImageUrl(): string; /** * Get the current image. * * @returns buffer with image data */ getImage(): Promise<Buffer>; /** * Get the Doorbird live audio url. * * ATTENTION: if you do not provide a session id or object, the URL will contain sensitive credentials. * * @param session session object or id * * @returns audio url */ getAudioUrl(session?: SessionBHA | string): string; /** * Get the Doorbird video url. * * ATTENTION: if you do not provide a session id or object, the URL will contain sensitive credentials. * * @param session session object or id * * @returns video url */ getVideoUrl(session?: SessionBHA | string): string; private getHttp; private uri; private baseUri; private authHeader; } export {};