UNPKG

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