| 1 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|---|
| 2 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|---|
| 3 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|---|
| 4 | function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|---|
| 5 | function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|---|
| 6 | import SockJS from "../modules/sockjs-client/index.js";
|
|---|
| 7 | import { log } from "../utils/log.js";
|
|---|
| 8 | var SockJSClient = /*#__PURE__*/function () {
|
|---|
| 9 | /**
|
|---|
| 10 | * @param {string} url
|
|---|
| 11 | */
|
|---|
| 12 | function SockJSClient(url) {
|
|---|
| 13 | _classCallCheck(this, SockJSClient);
|
|---|
| 14 | // SockJS requires `http` and `https` protocols
|
|---|
| 15 | this.sock = new SockJS(url.replace(/^ws:/i, "http:").replace(/^wss:/i, "https:"));
|
|---|
| 16 | this.sock.onerror =
|
|---|
| 17 | /**
|
|---|
| 18 | * @param {Error} error
|
|---|
| 19 | */
|
|---|
| 20 | function (error) {
|
|---|
| 21 | log.error(error);
|
|---|
| 22 | };
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | /**
|
|---|
| 26 | * @param {(...args: any[]) => void} f
|
|---|
| 27 | */
|
|---|
| 28 | _createClass(SockJSClient, [{
|
|---|
| 29 | key: "onOpen",
|
|---|
| 30 | value: function onOpen(f) {
|
|---|
| 31 | this.sock.onopen = f;
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | /**
|
|---|
| 35 | * @param {(...args: any[]) => void} f
|
|---|
| 36 | */
|
|---|
| 37 | }, {
|
|---|
| 38 | key: "onClose",
|
|---|
| 39 | value: function onClose(f) {
|
|---|
| 40 | this.sock.onclose = f;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | // call f with the message string as the first argument
|
|---|
| 44 | /**
|
|---|
| 45 | * @param {(...args: any[]) => void} f
|
|---|
| 46 | */
|
|---|
| 47 | }, {
|
|---|
| 48 | key: "onMessage",
|
|---|
| 49 | value: function onMessage(f) {
|
|---|
| 50 | this.sock.onmessage =
|
|---|
| 51 | /**
|
|---|
| 52 | * @param {Error & { data: string }} e
|
|---|
| 53 | */
|
|---|
| 54 | function (e) {
|
|---|
| 55 | f(e.data);
|
|---|
| 56 | };
|
|---|
| 57 | }
|
|---|
| 58 | }]);
|
|---|
| 59 | return SockJSClient;
|
|---|
| 60 | }();
|
|---|
| 61 | export { SockJSClient as default }; |
|---|