@mochabug/adapt-web
Version:
The client library to execute automations, without effort, in a browser environment
53 lines (52 loc) • 1.54 kB
TypeScript
import { ValueJson } from "@bufbuild/protobuf/wkt";
import { AutomationIdJson, SessionJson, UrlJson } from "./genproto/mochabugapis/adapt/automations/v1/automations_pb.js";
export interface Output {
vertex: string;
fork: string;
data: {
[key: string]: ValueJson;
};
created?: Date;
}
export interface MessageHandlers {
onOutput?: (output: Output) => void;
onSession?: (session: SessionJson) => void;
onUrl?: (url: UrlJson) => void;
}
export interface SubscriptionOptions extends MessageHandlers {
sessionToken: string;
automation: AutomationIdJson;
debug?: boolean;
}
export declare enum ConnectionState {
DISCONNECTED = "disconnected",
CONNECTING = "connecting",
CONNECTED = "connected",
CLOSING = "closing"
}
export declare class PubsubClient {
private state;
private sessionConfig;
private readonly logger;
private readonly ackTracker;
private readonly reconnectManager;
private readonly wsManager;
private messageProcessor;
private shouldReconnect;
private sessionComplete;
constructor(debug?: boolean);
subscribe(opts: SubscriptionOptions): Promise<void>;
unsubscribe(): Promise<void>;
isConnected(): boolean;
getConnectionState(): ConnectionState;
private connect;
private handleOpen;
private handleMessage;
private handleClose;
private handleError;
private analyzeCloseCode;
private scheduleReconnect;
private cleanup;
private isSameSession;
private updateHandlers;
}