1 | import { Client } from '../client';
|
2 | import { HeartbeatInfo } from './heartbeat-info';
|
3 | /**
|
4 | * Available for backward compatibility, please shift to using {@link Client}.
|
5 | *
|
6 | * **Deprecated**
|
7 | *
|
8 | * Part of `@stomp/stompjs`.
|
9 | *
|
10 | * To upgrade, please follow the [Upgrade Guide](../additional-documentation/upgrading.html)
|
11 | */
|
12 | export class CompatClient extends Client {
|
13 | /**
|
14 | * Available for backward compatibility, please shift to using {@link Client}
|
15 | * and [Client#webSocketFactory]{@link Client#webSocketFactory}.
|
16 | *
|
17 | * **Deprecated**
|
18 | *
|
19 | * @internal
|
20 | */
|
21 | constructor(webSocketFactory) {
|
22 | super();
|
23 | /**
|
24 | * It is no op now. No longer needed. Large packets work out of the box.
|
25 | */
|
26 | this.maxWebSocketFrameSize = 16 * 1024;
|
27 | this._heartbeatInfo = new HeartbeatInfo(this);
|
28 | this.reconnect_delay = 0;
|
29 | this.webSocketFactory = webSocketFactory;
|
30 | // Default from previous version
|
31 | this.debug = (...message) => {
|
32 | console.log(...message);
|
33 | };
|
34 | }
|
35 | _parseConnect(...args) {
|
36 | let closeEventCallback;
|
37 | let connectCallback;
|
38 | let errorCallback;
|
39 | let headers = {};
|
40 | if (args.length < 2) {
|
41 | throw new Error('Connect requires at least 2 arguments');
|
42 | }
|
43 | if (typeof args[1] === 'function') {
|
44 | [headers, connectCallback, errorCallback, closeEventCallback] = args;
|
45 | }
|
46 | else {
|
47 | switch (args.length) {
|
48 | case 6:
|
49 | [
|
50 | headers.login,
|
51 | headers.passcode,
|
52 | connectCallback,
|
53 | errorCallback,
|
54 | closeEventCallback,
|
55 | headers.host,
|
56 | ] = args;
|
57 | break;
|
58 | default:
|
59 | [
|
60 | headers.login,
|
61 | headers.passcode,
|
62 | connectCallback,
|
63 | errorCallback,
|
64 | closeEventCallback,
|
65 | ] = args;
|
66 | }
|
67 | }
|
68 | return [headers, connectCallback, errorCallback, closeEventCallback];
|
69 | }
|
70 | /**
|
71 | * Available for backward compatibility, please shift to using [Client#activate]{@link Client#activate}.
|
72 | *
|
73 | * **Deprecated**
|
74 | *
|
75 | * The `connect` method accepts different number of arguments and types. See the Overloads list. Use the
|
76 | * version with headers to pass your broker specific options.
|
77 | *
|
78 | * overloads:
|
79 | * - connect(headers, connectCallback)
|
80 | * - connect(headers, connectCallback, errorCallback)
|
81 | * - connect(login, passcode, connectCallback)
|
82 | * - connect(login, passcode, connectCallback, errorCallback)
|
83 | * - connect(login, passcode, connectCallback, errorCallback, closeEventCallback)
|
84 | * - connect(login, passcode, connectCallback, errorCallback, closeEventCallback, host)
|
85 | *
|
86 | * params:
|
87 | * - headers, see [Client#connectHeaders]{@link Client#connectHeaders}
|
88 | * - connectCallback, see [Client#onConnect]{@link Client#onConnect}
|
89 | * - errorCallback, see [Client#onStompError]{@link Client#onStompError}
|
90 | * - closeEventCallback, see [Client#onWebSocketClose]{@link Client#onWebSocketClose}
|
91 | * - login [String], see [Client#connectHeaders](../classes/Client.html#connectHeaders)
|
92 | * - passcode [String], [Client#connectHeaders](../classes/Client.html#connectHeaders)
|
93 | * - host [String], see [Client#connectHeaders](../classes/Client.html#connectHeaders)
|
94 | *
|
95 | * To upgrade, please follow the [Upgrade Guide](../additional-documentation/upgrading.html)
|
96 | */
|
97 | connect(...args) {
|
98 | const out = this._parseConnect(...args);
|
99 | if (out[0]) {
|
100 | this.connectHeaders = out[0];
|
101 | }
|
102 | if (out[1]) {
|
103 | this.onConnect = out[1];
|
104 | }
|
105 | if (out[2]) {
|
106 | this.onStompError = out[2];
|
107 | }
|
108 | if (out[3]) {
|
109 | this.onWebSocketClose = out[3];
|
110 | }
|
111 | super.activate();
|
112 | }
|
113 | /**
|
114 | * Available for backward compatibility, please shift to using [Client#deactivate]{@link Client#deactivate}.
|
115 | *
|
116 | * **Deprecated**
|
117 | *
|
118 | * See:
|
119 | * [Client#onDisconnect]{@link Client#onDisconnect}, and
|
120 | * [Client#disconnectHeaders]{@link Client#disconnectHeaders}
|
121 | *
|
122 | * To upgrade, please follow the [Upgrade Guide](../additional-documentation/upgrading.html)
|
123 | */
|
124 | disconnect(disconnectCallback, headers = {}) {
|
125 | if (disconnectCallback) {
|
126 | this.onDisconnect = disconnectCallback;
|
127 | }
|
128 | this.disconnectHeaders = headers;
|
129 | super.deactivate();
|
130 | }
|
131 | /**
|
132 | * Available for backward compatibility, use [Client#publish]{@link Client#publish}.
|
133 | *
|
134 | * Send a message to a named destination. Refer to your STOMP broker documentation for types
|
135 | * and naming of destinations. The headers will, typically, be available to the subscriber.
|
136 | * However, there may be special purpose headers corresponding to your STOMP broker.
|
137 | *
|
138 | * **Deprecated**, use [Client#publish]{@link Client#publish}
|
139 | *
|
140 | * Note: Body must be String. You will need to covert the payload to string in case it is not string (e.g. JSON)
|
141 | *
|
142 | * ```javascript
|
143 | * client.send("/queue/test", {priority: 9}, "Hello, STOMP");
|
144 | *
|
145 | * // If you want to send a message with a body, you must also pass the headers argument.
|
146 | * client.send("/queue/test", {}, "Hello, STOMP");
|
147 | * ```
|
148 | *
|
149 | * To upgrade, please follow the [Upgrade Guide](../additional-documentation/upgrading.html)
|
150 | */
|
151 | send(destination, headers = {}, body = '') {
|
152 | headers = Object.assign({}, headers);
|
153 | const skipContentLengthHeader = headers['content-length'] === false;
|
154 | if (skipContentLengthHeader) {
|
155 | delete headers['content-length'];
|
156 | }
|
157 | this.publish({
|
158 | destination,
|
159 | headers: headers,
|
160 | body,
|
161 | skipContentLengthHeader,
|
162 | });
|
163 | }
|
164 | /**
|
165 | * Available for backward compatibility, renamed to [Client#reconnectDelay]{@link Client#reconnectDelay}.
|
166 | *
|
167 | * **Deprecated**
|
168 | */
|
169 | set reconnect_delay(value) {
|
170 | this.reconnectDelay = value;
|
171 | }
|
172 | /**
|
173 | * Available for backward compatibility, renamed to [Client#webSocket]{@link Client#webSocket}.
|
174 | *
|
175 | * **Deprecated**
|
176 | */
|
177 | get ws() {
|
178 | return this.webSocket;
|
179 | }
|
180 | /**
|
181 | * Available for backward compatibility, renamed to [Client#connectedVersion]{@link Client#connectedVersion}.
|
182 | *
|
183 | * **Deprecated**
|
184 | */
|
185 | get version() {
|
186 | return this.connectedVersion;
|
187 | }
|
188 | /**
|
189 | * Available for backward compatibility, renamed to [Client#onUnhandledMessage]{@link Client#onUnhandledMessage}.
|
190 | *
|
191 | * **Deprecated**
|
192 | */
|
193 | get onreceive() {
|
194 | return this.onUnhandledMessage;
|
195 | }
|
196 | /**
|
197 | * Available for backward compatibility, renamed to [Client#onUnhandledMessage]{@link Client#onUnhandledMessage}.
|
198 | *
|
199 | * **Deprecated**
|
200 | */
|
201 | set onreceive(value) {
|
202 | this.onUnhandledMessage = value;
|
203 | }
|
204 | /**
|
205 | * Available for backward compatibility, renamed to [Client#onUnhandledReceipt]{@link Client#onUnhandledReceipt}.
|
206 | * Prefer using [Client#watchForReceipt]{@link Client#watchForReceipt}.
|
207 | *
|
208 | * **Deprecated**
|
209 | */
|
210 | get onreceipt() {
|
211 | return this.onUnhandledReceipt;
|
212 | }
|
213 | /**
|
214 | * Available for backward compatibility, renamed to [Client#onUnhandledReceipt]{@link Client#onUnhandledReceipt}.
|
215 | *
|
216 | * **Deprecated**
|
217 | */
|
218 | set onreceipt(value) {
|
219 | this.onUnhandledReceipt = value;
|
220 | }
|
221 | /**
|
222 | * Available for backward compatibility, renamed to [Client#heartbeatIncoming]{@link Client#heartbeatIncoming}
|
223 | * [Client#heartbeatOutgoing]{@link Client#heartbeatOutgoing}.
|
224 | *
|
225 | * **Deprecated**
|
226 | */
|
227 | get heartbeat() {
|
228 | return this._heartbeatInfo;
|
229 | }
|
230 | /**
|
231 | * Available for backward compatibility, renamed to [Client#heartbeatIncoming]{@link Client#heartbeatIncoming}
|
232 | * [Client#heartbeatOutgoing]{@link Client#heartbeatOutgoing}.
|
233 | *
|
234 | * **Deprecated**
|
235 | */
|
236 | set heartbeat(value) {
|
237 | this.heartbeatIncoming = value.incoming;
|
238 | this.heartbeatOutgoing = value.outgoing;
|
239 | }
|
240 | }
|
241 | //# sourceMappingURL=compat-client.js.map |
\ | No newline at end of file |