@citrineos/ocpprouter
Version:
The ocpprouter module for OCPP v2.0.1. This module is not intended to be used directly, but rather as a dependency for other modules.
57 lines (56 loc) • 3.63 kB
TypeScript
import type { OCPPVersionType } from '@citrineos/base';
import { MessageOrigin, MessageState } from '@citrineos/base';
import type { IOCPPMessageRepository, ISubscriptionRepository } from '@citrineos/data';
import { Subscription } from '@citrineos/data';
import type { ILogObj } from 'tslog';
import { Logger } from 'tslog';
export declare class WebhookDispatcher {
protected static readonly SUBSCRIPTION_REFRESH_INTERVAL_MS: number;
protected _logger: Logger<ILogObj>;
protected _ocppMessageRepository: IOCPPMessageRepository;
protected _subscriptionRepository: ISubscriptionRepository;
protected _identifiers: Set<string>;
protected _onConnectionCallbacks: Map<string, OnConnectionCallback[]>;
protected _onCloseCallbacks: Map<string, OnCloseCallback[]>;
protected _onMessageCallbacks: Map<string, OnMessageCallback[]>;
protected _sentMessageCallbacks: Map<string, OnSentMessageCallback[]>;
constructor(ocppMessageRepository: IOCPPMessageRepository, subscriptionRepository: ISubscriptionRepository, logger?: Logger<ILogObj>);
register(tenantId: number, stationId: string): Promise<void>;
deregister(tenantId: number, stationId: string): Promise<void>;
dispatchMessageReceivedUnparsed(tenantId: number, stationId: string, message: string, timestamp: string, protocol: OCPPVersionType, action: string, state: MessageState): Promise<void>;
dispatchMessageReceived(tenantId: number, stationId: string, timestamp: string, protocol: OCPPVersionType, action: string, state: MessageState, rpcMessage: any): Promise<void>;
dispatchMessageSent(identifier: string, action: string, state: MessageState, timestamp: string, protocol: OCPPVersionType, rpcMessage: any): Promise<void>;
protected _refreshSubscriptions(): Promise<void>;
/**
* Loads all subscriptions for a given connection into memory
*
* @param {number} tenantId
* @param {string} stationId
* @return {Promise<void>} a promise that resolves once all subscriptions are loaded
*/
protected _loadSubscriptionsForConnection(tenantId: number, stationId: string): Promise<void>;
protected _onConnectionCallback(subscription: Subscription): (info?: Map<string, string>) => Promise<boolean>;
protected _onCloseCallback(subscription: Subscription): (info?: Map<string, string>) => Promise<boolean>;
protected _onMessageReceivedCallback(subscription: Subscription): (message: string, info?: Map<string, string>) => Promise<boolean>;
protected _onMessageSentCallback(subscription: Subscription): (message: string, info?: Map<string, string>) => Promise<boolean>;
/**
* Sends a message to a given URL that has been subscribed to a station connection event
*
* @param {Object} requestBody - request body containing stationId, event, origin, message, error, and info
* @param {string} url - the URL to fetch data from
* @return {Promise<boolean>} a Promise that resolves to a boolean indicating success
*/
protected _subscriptionCallback(requestBody: {
stationId: string;
event: string;
origin?: MessageOrigin;
message?: string;
info?: {
[k: string]: string;
};
}, url: string): Promise<boolean>;
}
export type OnConnectionCallback = (info?: Map<string, string>) => Promise<boolean>;
export type OnCloseCallback = (info?: Map<string, string>) => Promise<boolean>;
export type OnMessageCallback = (message: string, info?: Map<string, string>) => Promise<boolean>;
export type OnSentMessageCallback = (message: string, info?: Map<string, string>) => Promise<boolean>;