UNPKG

@seriousme/opifex

Version:

MQTT client & server for Deno & NodeJS

45 lines 1.7 kB
import { type AnyPacket, type IPersistence, type IStore, MqttConn, type PublishPacket, type SockConn, type TAuthenticationResult, type Timer, type Topic } from "./deps.ts"; export type ClientId = string; export declare const SysPrefix = "$"; export declare const utf8Encoder: TextEncoder; /** * Handlers are hooks that the server will call * and let you influence the servers behaviour. * The following handlers can be configured: * - isAuthenticated() * - isAuthorizedToPublish() * - isAuthorizedToSubscribe() */ export type Handlers = { isAuthenticated?(ctx: Context, clientId: ClientId, username: string, password: Uint8Array): TAuthenticationResult; isAuthorizedToPublish?(ctx: Context, topic: Topic): boolean; isAuthorizedToSubscribe?(ctx: Context, topic: Topic): boolean; }; /** * The Context class is used to maintain state of a MQTT connection * It handles: * - connect/disconnect including broadcasting of these events * - publish * - persistence * - the will */ export declare class Context { connected: boolean; conn: SockConn; mqttConn: MqttConn; persistence: IPersistence; handlers: Handlers; static clientList: Map<ClientId, Context>; store?: IStore; will?: PublishPacket; timer?: Timer; constructor(persistence: IPersistence, conn: SockConn, handlers: Handlers); send(packet: AnyPacket): Promise<void>; connect(clientId: string, clean: boolean): void; doPublish(packet: PublishPacket): void; clean(clientId: string): void; close(executewill?: boolean): void; private handleWill; broadcast(topic: Topic, payload: string, retain?: boolean): void; } //# sourceMappingURL=context.d.ts.map