UNPKG

4.2 kBPlain TextView Raw
1import { IFrame } from './i-frame.js';
2import { IMessage } from './i-message.js';
3import { StompHeaders } from './stomp-headers.js';
4import { Versions } from './versions.js';
5
6/**
7 * This callback will receive a `string` as a parameter.
8 *
9 * Part of `@stomp/stompjs`.
10 */
11export type debugFnType = (msg: string) => void;
12
13/**
14 * This callback will receive a {@link IMessage} as parameter.
15 *
16 * Part of `@stomp/stompjs`.
17 */
18export type messageCallbackType = (message: IMessage) => void;
19
20/**
21 * This callback will receive a {@link IFrame} as parameter.
22 *
23 * Part of `@stomp/stompjs`.
24 */
25export type frameCallbackType = ((frame: IFrame) => void) | (() => void);
26
27/**
28 * This callback will receive a [CloseEvent]{@link https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent}
29 * as parameter.
30 *
31 * Part of `@stomp/stompjs`.
32 */
33export type closeEventCallbackType<T = any> = (evt: T) => void;
34
35/**
36 * This callback will receive an [Event]{@link https://developer.mozilla.org/en-US/docs/Web/API/Event}
37 * as parameter.
38 *
39 * Part of `@stomp/stompjs`.
40 */
41export type wsErrorCallbackType<T = any> = (evt: T) => void;
42
43/**
44 * Parameters for [Client#publish]{@link Client#publish}.
45 * Aliased as publishParams as well.
46 *
47 * Part of `@stomp/stompjs`.
48 */
49export interface IPublishParams {
50 /**
51 * destination end point
52 */
53 destination: string;
54 /**
55 * headers (optional)
56 */
57 headers?: StompHeaders;
58 /**
59 * body (optional)
60 */
61 body?: string;
62 /**
63 * binary body (optional)
64 */
65 binaryBody?: Uint8Array;
66 /**
67 * By default, a `content-length` header will be added in the Frame to the broker.
68 * Set it to `true` for the header to be skipped.
69 */
70 skipContentLengthHeader?: boolean;
71}
72
73/**
74 * Backward compatibility, switch to {@link IPublishParams}.
75 */
76export type publishParams = IPublishParams;
77
78/**
79 * Used in {@link IRawFrameType}
80 *
81 * Part of `@stomp/stompjs`.
82 *
83 * @internal
84 */
85export type RawHeaderType = [string, string];
86
87/**
88 * The parser yield frames in this structure
89 *
90 * Part of `@stomp/stompjs`.
91 *
92 * @internal
93 */
94export interface IRawFrameType {
95 command: string | undefined;
96 headers: RawHeaderType[];
97 binaryBody: Uint8Array | undefined;
98}
99
100/**
101 * @internal
102 */
103export interface IStompSocketMessageEvent {
104 data?: string | ArrayBuffer;
105}
106
107/**
108 * Copied from Websocket interface to avoid dom typelib dependency.
109 *
110 * @internal
111 */
112export interface IStompSocket {
113 url: string;
114 onclose: ((ev?: any) => any) | undefined | null;
115 onerror: ((ev: any) => any) | undefined | null;
116 onmessage: ((ev: IStompSocketMessageEvent) => any) | undefined | null;
117 onopen: ((ev?: any) => any) | undefined | null;
118 terminate?: (() => any) | undefined | null;
119
120 /**
121 * Returns a string that indicates how binary data from the socket is exposed to scripts:
122 * We support only 'arraybuffer'.
123 */
124 binaryType?: string;
125
126 /**
127 * Returns the state of the socket connection. It can have the values of StompSocketState.
128 */
129 readonly readyState: number;
130
131 /**
132 * Closes the connection.
133 */
134 close(): void;
135 /**
136 * Transmits data using the connection. data can be a string or an ArrayBuffer.
137 */
138 send(data: string | ArrayBuffer): void;
139}
140
141/**
142 * Possible states for the IStompSocket
143 */
144export enum StompSocketState {
145 CONNECTING,
146 OPEN,
147 CLOSING,
148 CLOSED,
149}
150
151/**
152 * Possible activation state
153 */
154export enum ActivationState {
155 ACTIVE,
156 DEACTIVATING,
157 INACTIVE,
158}
159
160/**
161 * @internal
162 */
163export interface IStomptHandlerConfig {
164 debug: debugFnType;
165 stompVersions: Versions;
166 connectHeaders: StompHeaders;
167 disconnectHeaders: StompHeaders;
168 heartbeatIncoming: number;
169 heartbeatOutgoing: number;
170 splitLargeFrames: boolean;
171 maxWebSocketChunkSize: number;
172 forceBinaryWSFrames: boolean;
173 logRawCommunication: boolean;
174 appendMissingNULLonIncoming: boolean;
175 discardWebsocketOnCommFailure: boolean;
176 onConnect: frameCallbackType;
177 onDisconnect: frameCallbackType;
178 onStompError: frameCallbackType;
179 onWebSocketClose: closeEventCallbackType;
180 onWebSocketError: wsErrorCallbackType;
181 onUnhandledMessage: messageCallbackType;
182 onUnhandledReceipt: frameCallbackType;
183 onUnhandledFrame: frameCallbackType;
184}
185
\No newline at end of file