UNPKG

@stomp/stompjs

Version:

STOMP client for Javascript and Typescript

108 lines 3.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var versions_1 = require("../versions"); var compat_client_1 = require("./compat-client"); /** * STOMP Class, acts like a factory to create {@link Client}. * * Part of `@stomp/stompjs`. * * **Deprecated** * * It will be removed in next major version. Please switch to {@link Client}. */ var Stomp = /** @class */ (function () { function Stomp() { } /** * This method creates a WebSocket client that is connected to * the STOMP server located at the url. * * ```javascript * var url = "ws://localhost:61614/stomp"; * var client = Stomp.client(url); * ``` * * **Deprecated** * * It will be removed in next major version. Please switch to {@link Client} * using [Client#brokerURL]{@link Client#brokerURL}. */ Stomp.client = function (url, protocols) { // This is a hack to allow another implementation than the standard // HTML5 WebSocket class. // // It is possible to use another class by calling // // Stomp.WebSocketClass = MozWebSocket // // *prior* to call `Stomp.client()`. // // This hack is deprecated and `Stomp.over()` method should be used // instead. // See remarks on the function Stomp.over if (protocols == null) { protocols = versions_1.Versions.default.protocolVersions(); } var wsFn = function () { var klass = Stomp.WebSocketClass || WebSocket; return new klass(url, protocols); }; return new compat_client_1.CompatClient(wsFn); }; /** * This method is an alternative to [Stomp#client]{@link Stomp#client} to let the user * specify the WebSocket to use (either a standard HTML5 WebSocket or * a similar object). * * In order to support reconnection, the function Client._connect should be callable more than once. * While reconnecting * a new instance of underlying transport (TCP Socket, WebSocket or SockJS) will be needed. So, this function * alternatively allows passing a function that should return a new instance of the underlying socket. * * ```javascript * var client = Stomp.over(function(){ * return new WebSocket('ws://localhost:15674/ws') * }); * ``` * * **Deprecated** * * It will be removed in next major version. Please switch to {@link Client} * using [Client#webSocketFactory]{@link Client#webSocketFactory}. */ Stomp.over = function (ws) { var wsFn; if (typeof (ws) === 'function') { wsFn = ws; } else { console.warn('Stomp.over did not receive a factory, auto reconnect will not work. ' + 'Please see https://stomp-js.github.io/api-docs/latest/classes/Stomp.html#over'); wsFn = function () { return ws; }; } return new compat_client_1.CompatClient(wsFn); }; /** * In case you need to use a non standard class for WebSocket. * * For example when using within NodeJS environment: * * ```javascript * StompJs = require('../../esm5/'); * Stomp = StompJs.Stomp; * Stomp.WebSocketClass = require('websocket').w3cwebsocket; * ``` * * **Deprecated** * * * It will be removed in next major version. Please switch to {@link Client} * using [Client#webSocketFactory]{@link Client#webSocketFactory}. */ // tslint:disable-next-line:variable-name Stomp.WebSocketClass = null; return Stomp; }()); exports.Stomp = Stomp; //# sourceMappingURL=stomp.js.map