UNPKG

@stomp/stompjs

Version:

STOMP client for Javascript and Typescript

286 lines 11 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var client_1 = require("../client"); var heartbeat_info_1 = require("./heartbeat-info"); /** * Available for backward compatibility, please shift to using {@link Client}. * * **Deprecated** * * Part of `@stomp/stompjs`. * * To upgrade, please follow the [Upgrade Guide](../additional-documentation/upgrading.html) */ var CompatClient = /** @class */ (function (_super) { __extends(CompatClient, _super); /** * Available for backward compatibility, please shift to using {@link Client} * and [Client#webSocketFactory]{@link Client#webSocketFactory}. * * **Deprecated** * * @internal */ function CompatClient(webSocketFactory) { var _this = _super.call(this) || this; /** * It is no op now. No longer needed. Large packets work out of the box. */ _this.maxWebSocketFrameSize = 16 * 1024; _this._heartbeatInfo = new heartbeat_info_1.HeartbeatInfo(_this); _this.reconnect_delay = 0; _this.webSocketFactory = webSocketFactory; // Default from previous version _this.debug = function () { var message = []; for (var _i = 0; _i < arguments.length; _i++) { message[_i] = arguments[_i]; } console.log.apply(console, message); }; return _this; } CompatClient.prototype._parseConnect = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var closeEventCallback; var connectCallback; var errorCallback; var headers = {}; if (args.length < 2) { throw new Error(('Connect requires at least 2 arguments')); } if (typeof (args[1]) === 'function') { headers = args[0], connectCallback = args[1], errorCallback = args[2], closeEventCallback = args[3]; } else { switch (args.length) { case 6: headers.login = args[0], headers.passcode = args[1], connectCallback = args[2], errorCallback = args[3], closeEventCallback = args[4], headers.host = args[5]; break; default: headers.login = args[0], headers.passcode = args[1], connectCallback = args[2], errorCallback = args[3], closeEventCallback = args[4]; } } return [headers, connectCallback, errorCallback, closeEventCallback]; }; /** * Available for backward compatibility, please shift to using [Client#activate]{@link Client#activate}. * * **Deprecated** * * The `connect` method accepts different number of arguments and types. See the Overloads list. Use the * version with headers to pass your broker specific options. * * overloads: * - connect(headers, connectCallback) * - connect(headers, connectCallback, errorCallback) * - connect(login, passcode, connectCallback) * - connect(login, passcode, connectCallback, errorCallback) * - connect(login, passcode, connectCallback, errorCallback, closeEventCallback) * - connect(login, passcode, connectCallback, errorCallback, closeEventCallback, host) * * params: * - headers, see [Client#connectHeaders]{@link Client#connectHeaders} * - connectCallback, see [Client#onConnect]{@link Client#onConnect} * - errorCallback, see [Client#onStompError]{@link Client#onStompError} * - closeEventCallback, see [Client#onWebSocketClose]{@link Client#onWebSocketClose} * - login [String], see [Client#connectHeaders](../classes/Client.html#connectHeaders) * - passcode [String], [Client#connectHeaders](../classes/Client.html#connectHeaders) * - host [String], see [Client#connectHeaders](../classes/Client.html#connectHeaders) * * To upgrade, please follow the [Upgrade Guide](../additional-documentation/upgrading.html) */ CompatClient.prototype.connect = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var out = this._parseConnect.apply(this, args); if (out[0]) { this.connectHeaders = out[0]; } if (out[1]) { this.onConnect = out[1]; } if (out[2]) { this.onStompError = out[2]; } if (out[3]) { this.onWebSocketClose = out[3]; } _super.prototype.activate.call(this); }; /** * Available for backward compatibility, please shift to using [Client#deactivate]{@link Client#deactivate}. * * **Deprecated** * * See: * [Client#onDisconnect]{@link Client#onDisconnect}, and * [Client#disconnectHeaders]{@link Client#disconnectHeaders} * * To upgrade, please follow the [Upgrade Guide](../additional-documentation/upgrading.html) */ CompatClient.prototype.disconnect = function (disconnectCallback, headers) { if (headers === void 0) { headers = {}; } if (disconnectCallback) { this.onDisconnect = disconnectCallback; } this.disconnectHeaders = headers; _super.prototype.deactivate.call(this); }; /** * Available for backward compatibility, use [Client#publish]{@link Client#publish}. * * Send a message to a named destination. Refer to your STOMP broker documentation for types * and naming of destinations. The headers will, typically, be available to the subscriber. * However, there may be special purpose headers corresponding to your STOMP broker. * * **Deprecated**, use [Client#publish]{@link Client#publish} * * Note: Body must be String. You will need to covert the payload to string in case it is not string (e.g. JSON) * * ```javascript * client.send("/queue/test", {priority: 9}, "Hello, STOMP"); * * // If you want to send a message with a body, you must also pass the headers argument. * client.send("/queue/test", {}, "Hello, STOMP"); * ``` * * To upgrade, please follow the [Upgrade Guide](../additional-documentation/upgrading.html) */ CompatClient.prototype.send = function (destination, headers, body) { if (headers === void 0) { headers = {}; } if (body === void 0) { body = ''; } headers = Object.assign({}, headers); var skipContentLengthHeader = (headers['content-length'] === false); if (skipContentLengthHeader) { delete headers['content-length']; } this.publish({ destination: destination, headers: headers, body: body, skipContentLengthHeader: skipContentLengthHeader }); }; Object.defineProperty(CompatClient.prototype, "reconnect_delay", { /** * Available for backward compatibility, renamed to [Client#reconnectDelay]{@link Client#reconnectDelay}. * * **Deprecated** */ set: function (value) { this.reconnectDelay = value; }, enumerable: true, configurable: true }); Object.defineProperty(CompatClient.prototype, "ws", { /** * Available for backward compatibility, renamed to [Client#webSocket]{@link Client#webSocket}. * * **Deprecated** */ get: function () { return this._webSocket; }, enumerable: true, configurable: true }); Object.defineProperty(CompatClient.prototype, "version", { /** * Available for backward compatibility, renamed to [Client#connectedVersion]{@link Client#connectedVersion}. * * **Deprecated** */ get: function () { return this.connectedVersion; }, enumerable: true, configurable: true }); Object.defineProperty(CompatClient.prototype, "onreceive", { /** * Available for backward compatibility, renamed to [Client#onUnhandledMessage]{@link Client#onUnhandledMessage}. * * **Deprecated** */ get: function () { return this.onUnhandledMessage; }, /** * Available for backward compatibility, renamed to [Client#onUnhandledMessage]{@link Client#onUnhandledMessage}. * * **Deprecated** */ set: function (value) { this.onUnhandledMessage = value; }, enumerable: true, configurable: true }); Object.defineProperty(CompatClient.prototype, "onreceipt", { /** * Available for backward compatibility, renamed to [Client#onUnhandledReceipt]{@link Client#onUnhandledReceipt}. * Prefer using [Client#watchForReceipt]{@link Client#watchForReceipt}. * * **Deprecated** */ get: function () { return this.onUnhandledReceipt; }, /** * Available for backward compatibility, renamed to [Client#onUnhandledReceipt]{@link Client#onUnhandledReceipt}. * * **Deprecated** */ set: function (value) { this.onUnhandledReceipt = value; }, enumerable: true, configurable: true }); Object.defineProperty(CompatClient.prototype, "heartbeat", { /** * Available for backward compatibility, renamed to [Client#heartbeatIncoming]{@link Client#heartbeatIncoming} * [Client#heartbeatOutgoing]{@link Client#heartbeatOutgoing}. * * **Deprecated** */ get: function () { return this._heartbeatInfo; }, /** * Available for backward compatibility, renamed to [Client#heartbeatIncoming]{@link Client#heartbeatIncoming} * [Client#heartbeatOutgoing]{@link Client#heartbeatOutgoing}. * * **Deprecated** */ set: function (value) { this.heartbeatIncoming = value.incoming; this.heartbeatOutgoing = value.outgoing; }, enumerable: true, configurable: true }); return CompatClient; }(client_1.Client)); exports.CompatClient = CompatClient; //# sourceMappingURL=compat-client.js.map