@ngxs/websocket-plugin 3.8.1 → 3.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,697 +1,786 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@ngxs/store'), require('rxjs'), require('rxjs/webSocket')) :
3
- typeof define === 'function' && define.amd ? define('@ngxs/websocket-plugin', ['exports', '@angular/core', '@ngxs/store', 'rxjs', 'rxjs/webSocket'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ngxs = global.ngxs || {}, global.ngxs["websocket-plugin"] = {}), global.ng.core, global["ngxs-store"], global.rxjs, global.rxjs.webSocket));
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@ngxs/store'), require('rxjs'), require('rxjs/webSocket')) :
3
+ typeof define === 'function' && define.amd ? define('@ngxs/websocket-plugin', ['exports', '@angular/core', '@ngxs/store', 'rxjs', 'rxjs/webSocket'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ngxs = global.ngxs || {}, global.ngxs["websocket-plugin"] = {}), global.ng.core, global["ngxs-store"], global.rxjs, global.rxjs.webSocket));
5
5
  })(this, (function (exports, i0, i1, rxjs, webSocket) { 'use strict';
6
6
 
7
- function _interopNamespace(e) {
8
- if (e && e.__esModule) return e;
9
- var n = Object.create(null);
10
- if (e) {
11
- Object.keys(e).forEach(function (k) {
12
- if (k !== 'default') {
13
- var d = Object.getOwnPropertyDescriptor(e, k);
14
- Object.defineProperty(n, k, d.get ? d : {
15
- enumerable: true,
16
- get: function () { return e[k]; }
17
- });
18
- }
19
- });
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
20
18
  }
21
- n["default"] = e;
22
- return Object.freeze(n);
19
+ });
23
20
  }
21
+ n["default"] = e;
22
+ return Object.freeze(n);
23
+ }
24
24
 
25
- var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
26
- var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
25
+ var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
26
+ var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
27
27
 
28
- /******************************************************************************
29
- Copyright (c) Microsoft Corporation.
28
+ /******************************************************************************
29
+ Copyright (c) Microsoft Corporation.
30
30
 
31
- Permission to use, copy, modify, and/or distribute this software for any
32
- purpose with or without fee is hereby granted.
31
+ Permission to use, copy, modify, and/or distribute this software for any
32
+ purpose with or without fee is hereby granted.
33
33
 
34
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
35
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
37
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
38
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
39
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
40
- PERFORMANCE OF THIS SOFTWARE.
41
- ***************************************************************************** */
42
- /* global Reflect, Promise */
43
- var extendStatics = function (d, b) {
44
- extendStatics = Object.setPrototypeOf ||
45
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
46
- function (d, b) { for (var p in b)
47
- if (Object.prototype.hasOwnProperty.call(b, p))
48
- d[p] = b[p]; };
49
- return extendStatics(d, b);
50
- };
51
- function __extends(d, b) {
52
- if (typeof b !== "function" && b !== null)
53
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
54
- extendStatics(d, b);
55
- function __() { this.constructor = d; }
56
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
57
- }
58
- var __assign = function () {
59
- __assign = Object.assign || function __assign(t) {
60
- for (var s, i = 1, n = arguments.length; i < n; i++) {
61
- s = arguments[i];
62
- for (var p in s)
63
- if (Object.prototype.hasOwnProperty.call(s, p))
64
- t[p] = s[p];
65
- }
66
- return t;
67
- };
68
- return __assign.apply(this, arguments);
69
- };
70
- function __rest(s, e) {
71
- var t = {};
72
- for (var p in s)
73
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
74
- t[p] = s[p];
75
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
76
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
77
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
78
- t[p[i]] = s[p[i]];
79
- }
80
- return t;
81
- }
82
- function __decorate(decorators, target, key, desc) {
83
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
84
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
85
- r = Reflect.decorate(decorators, target, key, desc);
86
- else
87
- for (var i = decorators.length - 1; i >= 0; i--)
88
- if (d = decorators[i])
89
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
90
- return c > 3 && r && Object.defineProperty(target, key, r), r;
91
- }
92
- function __param(paramIndex, decorator) {
93
- return function (target, key) { decorator(target, key, paramIndex); };
94
- }
95
- function __metadata(metadataKey, metadataValue) {
96
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
97
- return Reflect.metadata(metadataKey, metadataValue);
98
- }
99
- function __awaiter(thisArg, _arguments, P, generator) {
100
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
101
- return new (P || (P = Promise))(function (resolve, reject) {
102
- function fulfilled(value) { try {
103
- step(generator.next(value));
104
- }
105
- catch (e) {
106
- reject(e);
107
- } }
108
- function rejected(value) { try {
109
- step(generator["throw"](value));
110
- }
111
- catch (e) {
112
- reject(e);
113
- } }
114
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
115
- step((generator = generator.apply(thisArg, _arguments || [])).next());
116
- });
117
- }
118
- function __generator(thisArg, body) {
119
- var _ = { label: 0, sent: function () { if (t[0] & 1)
120
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
121
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
122
- function verb(n) { return function (v) { return step([n, v]); }; }
123
- function step(op) {
124
- if (f)
125
- throw new TypeError("Generator is already executing.");
126
- while (g && (g = 0, op[0] && (_ = 0)), _)
127
- try {
128
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
129
- return t;
130
- if (y = 0, t)
131
- op = [op[0] & 2, t.value];
132
- switch (op[0]) {
133
- case 0:
134
- case 1:
135
- t = op;
136
- break;
137
- case 4:
138
- _.label++;
139
- return { value: op[1], done: false };
140
- case 5:
141
- _.label++;
142
- y = op[1];
143
- op = [0];
144
- continue;
145
- case 7:
146
- op = _.ops.pop();
147
- _.trys.pop();
148
- continue;
149
- default:
150
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
151
- _ = 0;
152
- continue;
153
- }
154
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
155
- _.label = op[1];
156
- break;
157
- }
158
- if (op[0] === 6 && _.label < t[1]) {
159
- _.label = t[1];
160
- t = op;
161
- break;
162
- }
163
- if (t && _.label < t[2]) {
164
- _.label = t[2];
165
- _.ops.push(op);
166
- break;
167
- }
168
- if (t[2])
169
- _.ops.pop();
170
- _.trys.pop();
171
- continue;
172
- }
173
- op = body.call(thisArg, _);
174
- }
175
- catch (e) {
176
- op = [6, e];
177
- y = 0;
178
- }
179
- finally {
180
- f = t = 0;
181
- }
182
- if (op[0] & 5)
183
- throw op[1];
184
- return { value: op[0] ? op[1] : void 0, done: true };
185
- }
186
- }
187
- var __createBinding = Object.create ? (function (o, m, k, k2) {
188
- if (k2 === undefined)
189
- k2 = k;
190
- var desc = Object.getOwnPropertyDescriptor(m, k);
191
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
192
- desc = { enumerable: true, get: function () { return m[k]; } };
193
- }
194
- Object.defineProperty(o, k2, desc);
195
- }) : (function (o, m, k, k2) {
196
- if (k2 === undefined)
197
- k2 = k;
198
- o[k2] = m[k];
199
- });
200
- function __exportStar(m, o) {
201
- for (var p in m)
202
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
203
- __createBinding(o, m, p);
204
- }
205
- function __values(o) {
206
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
207
- if (m)
208
- return m.call(o);
209
- if (o && typeof o.length === "number")
210
- return {
211
- next: function () {
212
- if (o && i >= o.length)
213
- o = void 0;
214
- return { value: o && o[i++], done: !o };
215
- }
216
- };
217
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
218
- }
219
- function __read(o, n) {
220
- var m = typeof Symbol === "function" && o[Symbol.iterator];
221
- if (!m)
222
- return o;
223
- var i = m.call(o), r, ar = [], e;
224
- try {
225
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
226
- ar.push(r.value);
227
- }
228
- catch (error) {
229
- e = { error: error };
230
- }
231
- finally {
232
- try {
233
- if (r && !r.done && (m = i["return"]))
234
- m.call(i);
235
- }
236
- finally {
237
- if (e)
238
- throw e.error;
239
- }
240
- }
241
- return ar;
242
- }
243
- /** @deprecated */
244
- function __spread() {
245
- for (var ar = [], i = 0; i < arguments.length; i++)
246
- ar = ar.concat(__read(arguments[i]));
247
- return ar;
248
- }
249
- /** @deprecated */
250
- function __spreadArrays() {
251
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
252
- s += arguments[i].length;
253
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
254
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
255
- r[k] = a[j];
256
- return r;
257
- }
258
- function __spreadArray(to, from, pack) {
259
- if (pack || arguments.length === 2)
260
- for (var i = 0, l = from.length, ar; i < l; i++) {
261
- if (ar || !(i in from)) {
262
- if (!ar)
263
- ar = Array.prototype.slice.call(from, 0, i);
264
- ar[i] = from[i];
265
- }
266
- }
267
- return to.concat(ar || Array.prototype.slice.call(from));
268
- }
269
- function __await(v) {
270
- return this instanceof __await ? (this.v = v, this) : new __await(v);
271
- }
272
- function __asyncGenerator(thisArg, _arguments, generator) {
273
- if (!Symbol.asyncIterator)
274
- throw new TypeError("Symbol.asyncIterator is not defined.");
275
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
276
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
277
- function verb(n) { if (g[n])
278
- i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
279
- function resume(n, v) { try {
280
- step(g[n](v));
281
- }
282
- catch (e) {
283
- settle(q[0][3], e);
284
- } }
285
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
286
- function fulfill(value) { resume("next", value); }
287
- function reject(value) { resume("throw", value); }
288
- function settle(f, v) { if (f(v), q.shift(), q.length)
289
- resume(q[0][0], q[0][1]); }
290
- }
291
- function __asyncDelegator(o) {
292
- var i, p;
293
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
294
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
295
- }
296
- function __asyncValues(o) {
297
- if (!Symbol.asyncIterator)
298
- throw new TypeError("Symbol.asyncIterator is not defined.");
299
- var m = o[Symbol.asyncIterator], i;
300
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
301
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
302
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
303
- }
304
- function __makeTemplateObject(cooked, raw) {
305
- if (Object.defineProperty) {
306
- Object.defineProperty(cooked, "raw", { value: raw });
307
- }
308
- else {
309
- cooked.raw = raw;
310
- }
311
- return cooked;
312
- }
313
- ;
314
- var __setModuleDefault = Object.create ? (function (o, v) {
315
- Object.defineProperty(o, "default", { enumerable: true, value: v });
316
- }) : function (o, v) {
317
- o["default"] = v;
318
- };
319
- function __importStar(mod) {
320
- if (mod && mod.__esModule)
321
- return mod;
322
- var result = {};
323
- if (mod != null)
324
- for (var k in mod)
325
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
326
- __createBinding(result, mod, k);
327
- __setModuleDefault(result, mod);
328
- return result;
329
- }
330
- function __importDefault(mod) {
331
- return (mod && mod.__esModule) ? mod : { default: mod };
332
- }
333
- function __classPrivateFieldGet(receiver, state, kind, f) {
334
- if (kind === "a" && !f)
335
- throw new TypeError("Private accessor was defined without a getter");
336
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
337
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
338
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
339
- }
340
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
341
- if (kind === "m")
342
- throw new TypeError("Private method is not writable");
343
- if (kind === "a" && !f)
344
- throw new TypeError("Private accessor was defined without a setter");
345
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
346
- throw new TypeError("Cannot write private member to an object whose class did not declare it");
347
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
348
- }
349
- function __classPrivateFieldIn(state, receiver) {
350
- if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function"))
351
- throw new TypeError("Cannot use 'in' operator on non-object");
352
- return typeof state === "function" ? receiver === state : state.has(receiver);
353
- }
34
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
35
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
37
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
38
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
39
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
40
+ PERFORMANCE OF THIS SOFTWARE.
41
+ ***************************************************************************** */
42
+ /* global Reflect, Promise, SuppressedError, Symbol */
43
+ var extendStatics = function (d, b) {
44
+ extendStatics = Object.setPrototypeOf ||
45
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
46
+ function (d, b) { for (var p in b)
47
+ if (Object.prototype.hasOwnProperty.call(b, p))
48
+ d[p] = b[p]; };
49
+ return extendStatics(d, b);
50
+ };
51
+ function __extends(d, b) {
52
+ if (typeof b !== "function" && b !== null)
53
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
54
+ extendStatics(d, b);
55
+ function __() { this.constructor = d; }
56
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
57
+ }
58
+ var __assign = function () {
59
+ __assign = Object.assign || function __assign(t) {
60
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
61
+ s = arguments[i];
62
+ for (var p in s)
63
+ if (Object.prototype.hasOwnProperty.call(s, p))
64
+ t[p] = s[p];
65
+ }
66
+ return t;
67
+ };
68
+ return __assign.apply(this, arguments);
69
+ };
70
+ function __rest(s, e) {
71
+ var t = {};
72
+ for (var p in s)
73
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
74
+ t[p] = s[p];
75
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
76
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
77
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
78
+ t[p[i]] = s[p[i]];
79
+ }
80
+ return t;
81
+ }
82
+ function __decorate(decorators, target, key, desc) {
83
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
84
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
85
+ r = Reflect.decorate(decorators, target, key, desc);
86
+ else
87
+ for (var i = decorators.length - 1; i >= 0; i--)
88
+ if (d = decorators[i])
89
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
90
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
91
+ }
92
+ function __param(paramIndex, decorator) {
93
+ return function (target, key) { decorator(target, key, paramIndex); };
94
+ }
95
+ function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
96
+ function accept(f) { if (f !== void 0 && typeof f !== "function")
97
+ throw new TypeError("Function expected"); return f; }
98
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
99
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
100
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
101
+ var _, done = false;
102
+ for (var i = decorators.length - 1; i >= 0; i--) {
103
+ var context = {};
104
+ for (var p in contextIn)
105
+ context[p] = p === "access" ? {} : contextIn[p];
106
+ for (var p in contextIn.access)
107
+ context.access[p] = contextIn.access[p];
108
+ context.addInitializer = function (f) { if (done)
109
+ throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
110
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
111
+ if (kind === "accessor") {
112
+ if (result === void 0)
113
+ continue;
114
+ if (result === null || typeof result !== "object")
115
+ throw new TypeError("Object expected");
116
+ if (_ = accept(result.get))
117
+ descriptor.get = _;
118
+ if (_ = accept(result.set))
119
+ descriptor.set = _;
120
+ if (_ = accept(result.init))
121
+ initializers.unshift(_);
122
+ }
123
+ else if (_ = accept(result)) {
124
+ if (kind === "field")
125
+ initializers.unshift(_);
126
+ else
127
+ descriptor[key] = _;
128
+ }
129
+ }
130
+ if (target)
131
+ Object.defineProperty(target, contextIn.name, descriptor);
132
+ done = true;
133
+ }
134
+ ;
135
+ function __runInitializers(thisArg, initializers, value) {
136
+ var useValue = arguments.length > 2;
137
+ for (var i = 0; i < initializers.length; i++) {
138
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
139
+ }
140
+ return useValue ? value : void 0;
141
+ }
142
+ ;
143
+ function __propKey(x) {
144
+ return typeof x === "symbol" ? x : "".concat(x);
145
+ }
146
+ ;
147
+ function __setFunctionName(f, name, prefix) {
148
+ if (typeof name === "symbol")
149
+ name = name.description ? "[".concat(name.description, "]") : "";
150
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
151
+ }
152
+ ;
153
+ function __metadata(metadataKey, metadataValue) {
154
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
155
+ return Reflect.metadata(metadataKey, metadataValue);
156
+ }
157
+ function __awaiter(thisArg, _arguments, P, generator) {
158
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
159
+ return new (P || (P = Promise))(function (resolve, reject) {
160
+ function fulfilled(value) { try {
161
+ step(generator.next(value));
162
+ }
163
+ catch (e) {
164
+ reject(e);
165
+ } }
166
+ function rejected(value) { try {
167
+ step(generator["throw"](value));
168
+ }
169
+ catch (e) {
170
+ reject(e);
171
+ } }
172
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
173
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
174
+ });
175
+ }
176
+ function __generator(thisArg, body) {
177
+ var _ = { label: 0, sent: function () { if (t[0] & 1)
178
+ throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
179
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
180
+ function verb(n) { return function (v) { return step([n, v]); }; }
181
+ function step(op) {
182
+ if (f)
183
+ throw new TypeError("Generator is already executing.");
184
+ while (g && (g = 0, op[0] && (_ = 0)), _)
185
+ try {
186
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
187
+ return t;
188
+ if (y = 0, t)
189
+ op = [op[0] & 2, t.value];
190
+ switch (op[0]) {
191
+ case 0:
192
+ case 1:
193
+ t = op;
194
+ break;
195
+ case 4:
196
+ _.label++;
197
+ return { value: op[1], done: false };
198
+ case 5:
199
+ _.label++;
200
+ y = op[1];
201
+ op = [0];
202
+ continue;
203
+ case 7:
204
+ op = _.ops.pop();
205
+ _.trys.pop();
206
+ continue;
207
+ default:
208
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
209
+ _ = 0;
210
+ continue;
211
+ }
212
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
213
+ _.label = op[1];
214
+ break;
215
+ }
216
+ if (op[0] === 6 && _.label < t[1]) {
217
+ _.label = t[1];
218
+ t = op;
219
+ break;
220
+ }
221
+ if (t && _.label < t[2]) {
222
+ _.label = t[2];
223
+ _.ops.push(op);
224
+ break;
225
+ }
226
+ if (t[2])
227
+ _.ops.pop();
228
+ _.trys.pop();
229
+ continue;
230
+ }
231
+ op = body.call(thisArg, _);
232
+ }
233
+ catch (e) {
234
+ op = [6, e];
235
+ y = 0;
236
+ }
237
+ finally {
238
+ f = t = 0;
239
+ }
240
+ if (op[0] & 5)
241
+ throw op[1];
242
+ return { value: op[0] ? op[1] : void 0, done: true };
243
+ }
244
+ }
245
+ var __createBinding = Object.create ? (function (o, m, k, k2) {
246
+ if (k2 === undefined)
247
+ k2 = k;
248
+ var desc = Object.getOwnPropertyDescriptor(m, k);
249
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
250
+ desc = { enumerable: true, get: function () { return m[k]; } };
251
+ }
252
+ Object.defineProperty(o, k2, desc);
253
+ }) : (function (o, m, k, k2) {
254
+ if (k2 === undefined)
255
+ k2 = k;
256
+ o[k2] = m[k];
257
+ });
258
+ function __exportStar(m, o) {
259
+ for (var p in m)
260
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
261
+ __createBinding(o, m, p);
262
+ }
263
+ function __values(o) {
264
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
265
+ if (m)
266
+ return m.call(o);
267
+ if (o && typeof o.length === "number")
268
+ return {
269
+ next: function () {
270
+ if (o && i >= o.length)
271
+ o = void 0;
272
+ return { value: o && o[i++], done: !o };
273
+ }
274
+ };
275
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
276
+ }
277
+ function __read(o, n) {
278
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
279
+ if (!m)
280
+ return o;
281
+ var i = m.call(o), r, ar = [], e;
282
+ try {
283
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
284
+ ar.push(r.value);
285
+ }
286
+ catch (error) {
287
+ e = { error: error };
288
+ }
289
+ finally {
290
+ try {
291
+ if (r && !r.done && (m = i["return"]))
292
+ m.call(i);
293
+ }
294
+ finally {
295
+ if (e)
296
+ throw e.error;
297
+ }
298
+ }
299
+ return ar;
300
+ }
301
+ /** @deprecated */
302
+ function __spread() {
303
+ for (var ar = [], i = 0; i < arguments.length; i++)
304
+ ar = ar.concat(__read(arguments[i]));
305
+ return ar;
306
+ }
307
+ /** @deprecated */
308
+ function __spreadArrays() {
309
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++)
310
+ s += arguments[i].length;
311
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
312
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
313
+ r[k] = a[j];
314
+ return r;
315
+ }
316
+ function __spreadArray(to, from, pack) {
317
+ if (pack || arguments.length === 2)
318
+ for (var i = 0, l = from.length, ar; i < l; i++) {
319
+ if (ar || !(i in from)) {
320
+ if (!ar)
321
+ ar = Array.prototype.slice.call(from, 0, i);
322
+ ar[i] = from[i];
323
+ }
324
+ }
325
+ return to.concat(ar || Array.prototype.slice.call(from));
326
+ }
327
+ function __await(v) {
328
+ return this instanceof __await ? (this.v = v, this) : new __await(v);
329
+ }
330
+ function __asyncGenerator(thisArg, _arguments, generator) {
331
+ if (!Symbol.asyncIterator)
332
+ throw new TypeError("Symbol.asyncIterator is not defined.");
333
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
334
+ return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
335
+ function verb(n) { if (g[n])
336
+ i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
337
+ function resume(n, v) { try {
338
+ step(g[n](v));
339
+ }
340
+ catch (e) {
341
+ settle(q[0][3], e);
342
+ } }
343
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
344
+ function fulfill(value) { resume("next", value); }
345
+ function reject(value) { resume("throw", value); }
346
+ function settle(f, v) { if (f(v), q.shift(), q.length)
347
+ resume(q[0][0], q[0][1]); }
348
+ }
349
+ function __asyncDelegator(o) {
350
+ var i, p;
351
+ return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
352
+ function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
353
+ }
354
+ function __asyncValues(o) {
355
+ if (!Symbol.asyncIterator)
356
+ throw new TypeError("Symbol.asyncIterator is not defined.");
357
+ var m = o[Symbol.asyncIterator], i;
358
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
359
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
360
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
361
+ }
362
+ function __makeTemplateObject(cooked, raw) {
363
+ if (Object.defineProperty) {
364
+ Object.defineProperty(cooked, "raw", { value: raw });
365
+ }
366
+ else {
367
+ cooked.raw = raw;
368
+ }
369
+ return cooked;
370
+ }
371
+ ;
372
+ var __setModuleDefault = Object.create ? (function (o, v) {
373
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
374
+ }) : function (o, v) {
375
+ o["default"] = v;
376
+ };
377
+ function __importStar(mod) {
378
+ if (mod && mod.__esModule)
379
+ return mod;
380
+ var result = {};
381
+ if (mod != null)
382
+ for (var k in mod)
383
+ if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
384
+ __createBinding(result, mod, k);
385
+ __setModuleDefault(result, mod);
386
+ return result;
387
+ }
388
+ function __importDefault(mod) {
389
+ return (mod && mod.__esModule) ? mod : { default: mod };
390
+ }
391
+ function __classPrivateFieldGet(receiver, state, kind, f) {
392
+ if (kind === "a" && !f)
393
+ throw new TypeError("Private accessor was defined without a getter");
394
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
395
+ throw new TypeError("Cannot read private member from an object whose class did not declare it");
396
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
397
+ }
398
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
399
+ if (kind === "m")
400
+ throw new TypeError("Private method is not writable");
401
+ if (kind === "a" && !f)
402
+ throw new TypeError("Private accessor was defined without a setter");
403
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
404
+ throw new TypeError("Cannot write private member to an object whose class did not declare it");
405
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
406
+ }
407
+ function __classPrivateFieldIn(state, receiver) {
408
+ if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function"))
409
+ throw new TypeError("Cannot use 'in' operator on non-object");
410
+ return typeof state === "function" ? receiver === state : state.has(receiver);
411
+ }
412
+ function __addDisposableResource(env, value, async) {
413
+ if (value !== null && value !== void 0) {
414
+ if (typeof value !== "object" && typeof value !== "function")
415
+ throw new TypeError("Object expected.");
416
+ var dispose;
417
+ if (async) {
418
+ if (!Symbol.asyncDispose)
419
+ throw new TypeError("Symbol.asyncDispose is not defined.");
420
+ dispose = value[Symbol.asyncDispose];
421
+ }
422
+ if (dispose === void 0) {
423
+ if (!Symbol.dispose)
424
+ throw new TypeError("Symbol.dispose is not defined.");
425
+ dispose = value[Symbol.dispose];
426
+ }
427
+ if (typeof dispose !== "function")
428
+ throw new TypeError("Object not disposable.");
429
+ env.stack.push({ value: value, dispose: dispose, async: async });
430
+ }
431
+ else if (async) {
432
+ env.stack.push({ async: true });
433
+ }
434
+ return value;
435
+ }
436
+ var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
437
+ var e = new Error(message);
438
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
439
+ };
440
+ function __disposeResources(env) {
441
+ function fail(e) {
442
+ env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
443
+ env.hasError = true;
444
+ }
445
+ function next() {
446
+ while (env.stack.length) {
447
+ var rec = env.stack.pop();
448
+ try {
449
+ var result = rec.dispose && rec.dispose.call(rec.value);
450
+ if (rec.async)
451
+ return Promise.resolve(result).then(next, function (e) { fail(e); return next(); });
452
+ }
453
+ catch (e) {
454
+ fail(e);
455
+ }
456
+ }
457
+ if (env.hasError)
458
+ throw env.error;
459
+ }
460
+ return next();
461
+ }
462
+ var tslib_es6 = {
463
+ __extends: __extends,
464
+ __assign: __assign,
465
+ __rest: __rest,
466
+ __decorate: __decorate,
467
+ __param: __param,
468
+ __metadata: __metadata,
469
+ __awaiter: __awaiter,
470
+ __generator: __generator,
471
+ __createBinding: __createBinding,
472
+ __exportStar: __exportStar,
473
+ __values: __values,
474
+ __read: __read,
475
+ __spread: __spread,
476
+ __spreadArrays: __spreadArrays,
477
+ __spreadArray: __spreadArray,
478
+ __await: __await,
479
+ __asyncGenerator: __asyncGenerator,
480
+ __asyncDelegator: __asyncDelegator,
481
+ __asyncValues: __asyncValues,
482
+ __makeTemplateObject: __makeTemplateObject,
483
+ __importStar: __importStar,
484
+ __importDefault: __importDefault,
485
+ __classPrivateFieldGet: __classPrivateFieldGet,
486
+ __classPrivateFieldSet: __classPrivateFieldSet,
487
+ __classPrivateFieldIn: __classPrivateFieldIn,
488
+ __addDisposableResource: __addDisposableResource,
489
+ __disposeResources: __disposeResources,
490
+ };
354
491
 
355
- var NGXS_WEBSOCKET_OPTIONS = new i0.InjectionToken('NGXS_WEBSOCKET_OPTIONS');
356
- function noop() {
357
- var _args = [];
358
- for (var _i = 0; _i < arguments.length; _i++) {
359
- _args[_i] = arguments[_i];
360
- }
361
- return function () { };
362
- }
363
- /**
364
- * Action to connect to the websocket. Optionally pass a URL.
365
- */
366
- var ConnectWebSocket = /** @class */ (function () {
367
- function ConnectWebSocket(payload) {
368
- this.payload = payload;
369
- }
370
- Object.defineProperty(ConnectWebSocket, "type", {
371
- get: function () {
372
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
373
- return '[WebSocket] Connect';
374
- },
375
- enumerable: false,
376
- configurable: true
377
- });
378
- return ConnectWebSocket;
379
- }());
380
- /**
381
- * Action triggered when a error ocurrs
382
- */
383
- var WebsocketMessageError = /** @class */ (function () {
384
- function WebsocketMessageError(payload) {
385
- this.payload = payload;
386
- }
387
- Object.defineProperty(WebsocketMessageError, "type", {
388
- get: function () {
389
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
390
- return '[WebSocket] Message Error';
391
- },
392
- enumerable: false,
393
- configurable: true
394
- });
395
- return WebsocketMessageError;
396
- }());
397
- /**
398
- * Action to disconnect the websocket.
399
- */
400
- var DisconnectWebSocket = /** @class */ (function () {
401
- function DisconnectWebSocket() {
402
- }
403
- Object.defineProperty(DisconnectWebSocket, "type", {
404
- get: function () {
405
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
406
- return '[WebSocket] Disconnect';
407
- },
408
- enumerable: false,
409
- configurable: true
410
- });
411
- return DisconnectWebSocket;
412
- }());
413
- /**
414
- * Action triggered when websocket is connected
415
- */
416
- var WebSocketConnected = /** @class */ (function () {
417
- function WebSocketConnected() {
418
- }
419
- Object.defineProperty(WebSocketConnected, "type", {
420
- get: function () {
421
- return '[WebSocket] Connected';
422
- },
423
- enumerable: false,
424
- configurable: true
425
- });
426
- return WebSocketConnected;
427
- }());
428
- /**
429
- * Action triggered when websocket is disconnected
430
- */
431
- var WebSocketDisconnected = /** @class */ (function () {
432
- function WebSocketDisconnected() {
433
- }
434
- Object.defineProperty(WebSocketDisconnected, "type", {
435
- get: function () {
436
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
437
- return '[WebSocket] Disconnected';
438
- },
439
- enumerable: false,
440
- configurable: true
441
- });
442
- return WebSocketDisconnected;
443
- }());
444
- /**
445
- * Action to send to the server.
446
- */
447
- var SendWebSocketMessage = /** @class */ (function () {
448
- function SendWebSocketMessage(payload) {
449
- this.payload = payload;
450
- }
451
- Object.defineProperty(SendWebSocketMessage, "type", {
452
- get: function () {
453
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
454
- return '[WebSocket] Send Message';
455
- },
456
- enumerable: false,
457
- configurable: true
458
- });
459
- return SendWebSocketMessage;
460
- }());
461
- /**
462
- * Action dispatched when the user tries to connect if the connection already exists.
463
- */
464
- var WebSocketConnectionUpdated = /** @class */ (function () {
465
- function WebSocketConnectionUpdated() {
466
- }
467
- Object.defineProperty(WebSocketConnectionUpdated, "type", {
468
- get: function () {
469
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
470
- return '[WebSocket] Connection Updated';
471
- },
472
- enumerable: false,
473
- configurable: true
474
- });
475
- return WebSocketConnectionUpdated;
476
- }());
477
- /**
478
- * This error is thrown where there is no `type` (or custom `typeKey`) property
479
- * on the message that came from the server side socket
480
- */
481
- var TypeKeyPropertyMissingError = /** @class */ (function (_super) {
482
- __extends(TypeKeyPropertyMissingError, _super);
483
- function TypeKeyPropertyMissingError(typeKey) {
484
- return _super.call(this, "Property " + typeKey + " is missing on the socket message") || this;
485
- }
486
- return TypeKeyPropertyMissingError;
487
- }(Error));
492
+ var NGXS_WEBSOCKET_OPTIONS = new i0.InjectionToken('NGXS_WEBSOCKET_OPTIONS');
493
+ function noop() {
494
+ var _args = [];
495
+ for (var _i = 0; _i < arguments.length; _i++) {
496
+ _args[_i] = arguments[_i];
497
+ }
498
+ return function () { };
499
+ }
500
+ /**
501
+ * Action to connect to the websocket. Optionally pass a URL.
502
+ */
503
+ var ConnectWebSocket = /** @class */ (function () {
504
+ function ConnectWebSocket(payload) {
505
+ this.payload = payload;
506
+ }
507
+ return ConnectWebSocket;
508
+ }());
509
+ ConnectWebSocket.type = '[WebSocket] Connect';
510
+ /**
511
+ * Action triggered when a error ocurrs
512
+ */
513
+ var WebsocketMessageError = /** @class */ (function () {
514
+ function WebsocketMessageError(payload) {
515
+ this.payload = payload;
516
+ }
517
+ return WebsocketMessageError;
518
+ }());
519
+ WebsocketMessageError.type = '[WebSocket] Message Error';
520
+ /**
521
+ * Action to disconnect the websocket.
522
+ */
523
+ var DisconnectWebSocket = /** @class */ (function () {
524
+ function DisconnectWebSocket() {
525
+ }
526
+ return DisconnectWebSocket;
527
+ }());
528
+ DisconnectWebSocket.type = '[WebSocket] Disconnect';
529
+ /**
530
+ * Action triggered when websocket is connected
531
+ */
532
+ var WebSocketConnected = /** @class */ (function () {
533
+ function WebSocketConnected() {
534
+ }
535
+ return WebSocketConnected;
536
+ }());
537
+ WebSocketConnected.type = '[WebSocket] Connected';
538
+ /**
539
+ * Action triggered when websocket is disconnected
540
+ */
541
+ var WebSocketDisconnected = /** @class */ (function () {
542
+ function WebSocketDisconnected() {
543
+ }
544
+ return WebSocketDisconnected;
545
+ }());
546
+ WebSocketDisconnected.type = '[WebSocket] Disconnected';
547
+ /**
548
+ * Action to send to the server.
549
+ */
550
+ var SendWebSocketMessage = /** @class */ (function () {
551
+ function SendWebSocketMessage(payload) {
552
+ this.payload = payload;
553
+ }
554
+ return SendWebSocketMessage;
555
+ }());
556
+ SendWebSocketMessage.type = '[WebSocket] Send Message';
557
+ /**
558
+ * Action dispatched when the user tries to connect if the connection already exists.
559
+ */
560
+ var WebSocketConnectionUpdated = /** @class */ (function () {
561
+ function WebSocketConnectionUpdated() {
562
+ }
563
+ return WebSocketConnectionUpdated;
564
+ }());
565
+ WebSocketConnectionUpdated.type = '[WebSocket] Connection Updated';
566
+ /**
567
+ * This error is thrown where there is no `type` (or custom `typeKey`) property
568
+ * on the message that came from the server side socket
569
+ */
570
+ var TypeKeyPropertyMissingError = /** @class */ (function (_super) {
571
+ __extends(TypeKeyPropertyMissingError, _super);
572
+ function TypeKeyPropertyMissingError(typeKey) {
573
+ return _super.call(this, "Property " + typeKey + " is missing on the socket message") || this;
574
+ }
575
+ return TypeKeyPropertyMissingError;
576
+ }(Error));
488
577
 
489
- var WebSocketHandler = /** @class */ (function () {
490
- function WebSocketHandler(store, actions$, options) {
491
- var _this = this;
492
- this.store = store;
493
- this.actions$ = actions$;
494
- this.options = options;
495
- this.socket = null;
496
- this.config = {
497
- url: this.options.url,
498
- protocol: this.options.protocol,
499
- // Default binary type is `blob` for the global `WebSocket`
500
- binaryType: this.options.binaryType,
501
- serializer: this.options.serializer,
502
- deserializer: this.options.deserializer,
503
- closeObserver: {
504
- next: function () {
505
- // ATTENTION!
506
- // See https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/dom/WebSocketSubject.ts#L340
507
- // RxJS socket emits `onComplete` event only if `event.wasClean` is truthy
508
- // and doesn't complete socket subject if it's falsy
509
- _this.disconnect();
510
- }
511
- },
512
- openObserver: {
513
- next: function () { return _this.store.dispatch(new WebSocketConnected()); }
514
- }
515
- };
516
- this.typeKey = this.options.typeKey;
517
- this.subscription = new rxjs.Subscription();
518
- this.setupActionsListeners();
519
- }
520
- WebSocketHandler.prototype.ngOnDestroy = function () {
521
- this.closeConnection();
522
- this.subscription.unsubscribe();
523
- };
524
- WebSocketHandler.prototype.setupActionsListeners = function () {
525
- var _this = this;
526
- this.subscription.add(this.actions$.pipe(i1.ofActionDispatched(ConnectWebSocket)).subscribe(function (_a) {
527
- var payload = _a.payload;
528
- _this.connect(payload);
529
- }));
530
- this.subscription.add(this.actions$.pipe(i1.ofActionDispatched(DisconnectWebSocket)).subscribe(function () {
531
- _this.disconnect();
532
- }));
533
- this.subscription.add(this.actions$.pipe(i1.ofActionDispatched(SendWebSocketMessage)).subscribe(function (_a) {
534
- var payload = _a.payload;
535
- _this.send(payload);
536
- }));
537
- };
538
- WebSocketHandler.prototype.connect = function (options) {
539
- var _this = this;
540
- this.updateConnection();
541
- // Users can pass the options in the connect method so
542
- // if options aren't available at DI bootstrap they have access
543
- // to pass them here
544
- if (options) {
545
- this.mergeConfigWithOptions(options);
546
- }
547
- this.socket = new webSocket.WebSocketSubject(this.config);
548
- this.socket.subscribe({
549
- next: function (message) {
550
- var type = i1.getValue(message, _this.typeKey);
551
- if (!type) {
552
- throw new TypeKeyPropertyMissingError(_this.typeKey);
553
- }
554
- _this.store.dispatch(Object.assign(Object.assign({}, message), { type: type }));
555
- },
556
- error: function (error) {
557
- if (error instanceof CloseEvent) {
558
- _this.dispatchWebSocketDisconnected();
559
- }
560
- else {
561
- _this.store.dispatch(new WebsocketMessageError(error));
562
- }
563
- }
564
- });
565
- };
566
- WebSocketHandler.prototype.disconnect = function () {
567
- if (this.socket) {
568
- this.closeConnection();
569
- this.dispatchWebSocketDisconnected();
570
- }
571
- };
572
- WebSocketHandler.prototype.send = function (data) {
573
- if (!this.socket) {
574
- throw new Error('You must connect to the socket before sending any data');
575
- }
576
- this.socket.next(data);
577
- };
578
- /**
579
- * Don't enlarge the `connect` method
580
- */
581
- WebSocketHandler.prototype.mergeConfigWithOptions = function (options) {
582
- if (options.url) {
583
- this.config.url = options.url;
584
- }
585
- if (options.serializer) {
586
- this.config.serializer = options.serializer;
587
- }
588
- if (options.deserializer) {
589
- this.config.deserializer = options.deserializer;
590
- }
591
- };
592
- /**
593
- * To ensure we don't have any memory leaks
594
- * e.g. if the user occasionally dispatched `ConnectWebSocket` twice
595
- * then the previous subscription will still live in the memory
596
- * to prevent such behavior - we close the previous connection if it exists
597
- */
598
- WebSocketHandler.prototype.updateConnection = function () {
599
- if (this.socket) {
600
- this.closeConnection();
601
- this.store.dispatch(new WebSocketConnectionUpdated());
602
- }
603
- };
604
- /**
605
- * Used in many places so it's better to move the code into function
606
- */
607
- WebSocketHandler.prototype.dispatchWebSocketDisconnected = function () {
608
- this.store.dispatch(new WebSocketDisconnected());
609
- };
610
- WebSocketHandler.prototype.closeConnection = function () {
611
- // `socket.complete()` closes the connection
612
- // also it doesn't invoke the `onComplete` callback that we passed
613
- // into `socket.subscribe(...)`
614
- if (this.socket !== null) {
615
- this.socket.complete();
616
- this.socket = null;
617
- }
618
- };
619
- return WebSocketHandler;
620
- }());
621
- /** @nocollapse */ WebSocketHandler.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: WebSocketHandler, deps: [{ token: i1__namespace.Store }, { token: i1__namespace.Actions }, { token: NGXS_WEBSOCKET_OPTIONS }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
622
- /** @nocollapse */ WebSocketHandler.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: WebSocketHandler });
623
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: WebSocketHandler, decorators: [{
624
- type: i0.Injectable
625
- }], ctorParameters: function () {
626
- return [{ type: i1__namespace.Store }, { type: i1__namespace.Actions }, { type: undefined, decorators: [{
627
- type: i0.Inject,
628
- args: [NGXS_WEBSOCKET_OPTIONS]
629
- }] }];
630
- } });
578
+ var WebSocketHandler = /** @class */ (function () {
579
+ function WebSocketHandler(store, actions$, options) {
580
+ var _this = this;
581
+ this.store = store;
582
+ this.actions$ = actions$;
583
+ this.options = options;
584
+ this.socket = null;
585
+ this.config = {
586
+ url: this.options.url,
587
+ protocol: this.options.protocol,
588
+ // Default binary type is `blob` for the global `WebSocket`
589
+ binaryType: this.options.binaryType,
590
+ serializer: this.options.serializer,
591
+ deserializer: this.options.deserializer,
592
+ closeObserver: {
593
+ next: function () {
594
+ // ATTENTION!
595
+ // See https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/dom/WebSocketSubject.ts#L340
596
+ // RxJS socket emits `onComplete` event only if `event.wasClean` is truthy
597
+ // and doesn't complete socket subject if it's falsy
598
+ _this.disconnect();
599
+ }
600
+ },
601
+ openObserver: {
602
+ next: function () { return _this.store.dispatch(new WebSocketConnected()); }
603
+ }
604
+ };
605
+ this.typeKey = this.options.typeKey;
606
+ this.subscription = new rxjs.Subscription();
607
+ this.setupActionsListeners();
608
+ }
609
+ WebSocketHandler.prototype.ngOnDestroy = function () {
610
+ this.closeConnection();
611
+ this.subscription.unsubscribe();
612
+ };
613
+ WebSocketHandler.prototype.setupActionsListeners = function () {
614
+ var _this = this;
615
+ this.subscription.add(this.actions$.pipe(i1.ofActionDispatched(ConnectWebSocket)).subscribe(function (_a) {
616
+ var payload = _a.payload;
617
+ _this.connect(payload);
618
+ }));
619
+ this.subscription.add(this.actions$.pipe(i1.ofActionDispatched(DisconnectWebSocket)).subscribe(function () {
620
+ _this.disconnect();
621
+ }));
622
+ this.subscription.add(this.actions$.pipe(i1.ofActionDispatched(SendWebSocketMessage)).subscribe(function (_a) {
623
+ var payload = _a.payload;
624
+ _this.send(payload);
625
+ }));
626
+ };
627
+ WebSocketHandler.prototype.connect = function (options) {
628
+ var _this = this;
629
+ this.updateConnection();
630
+ // Users can pass the options in the connect method so
631
+ // if options aren't available at DI bootstrap they have access
632
+ // to pass them here
633
+ if (options) {
634
+ this.mergeConfigWithOptions(options);
635
+ }
636
+ this.socket = new webSocket.WebSocketSubject(this.config);
637
+ this.socket.subscribe({
638
+ next: function (message) {
639
+ var type = i1.getValue(message, _this.typeKey);
640
+ if (!type) {
641
+ throw new TypeKeyPropertyMissingError(_this.typeKey);
642
+ }
643
+ _this.store.dispatch(Object.assign(Object.assign({}, message), { type: type }));
644
+ },
645
+ error: function (error) {
646
+ if (error instanceof CloseEvent) {
647
+ _this.dispatchWebSocketDisconnected();
648
+ }
649
+ else {
650
+ _this.store.dispatch(new WebsocketMessageError(error));
651
+ }
652
+ }
653
+ });
654
+ };
655
+ WebSocketHandler.prototype.disconnect = function () {
656
+ if (this.socket) {
657
+ this.closeConnection();
658
+ this.dispatchWebSocketDisconnected();
659
+ }
660
+ };
661
+ WebSocketHandler.prototype.send = function (data) {
662
+ if (!this.socket) {
663
+ throw new Error('You must connect to the socket before sending any data');
664
+ }
665
+ this.socket.next(data);
666
+ };
667
+ /**
668
+ * Don't enlarge the `connect` method
669
+ */
670
+ WebSocketHandler.prototype.mergeConfigWithOptions = function (options) {
671
+ if (options.url) {
672
+ this.config.url = options.url;
673
+ }
674
+ if (options.serializer) {
675
+ this.config.serializer = options.serializer;
676
+ }
677
+ if (options.deserializer) {
678
+ this.config.deserializer = options.deserializer;
679
+ }
680
+ };
681
+ /**
682
+ * To ensure we don't have any memory leaks
683
+ * e.g. if the user occasionally dispatched `ConnectWebSocket` twice
684
+ * then the previous subscription will still live in the memory
685
+ * to prevent such behavior - we close the previous connection if it exists
686
+ */
687
+ WebSocketHandler.prototype.updateConnection = function () {
688
+ if (this.socket) {
689
+ this.closeConnection();
690
+ this.store.dispatch(new WebSocketConnectionUpdated());
691
+ }
692
+ };
693
+ /**
694
+ * Used in many places so it's better to move the code into function
695
+ */
696
+ WebSocketHandler.prototype.dispatchWebSocketDisconnected = function () {
697
+ this.store.dispatch(new WebSocketDisconnected());
698
+ };
699
+ WebSocketHandler.prototype.closeConnection = function () {
700
+ // `socket.complete()` closes the connection
701
+ // also it doesn't invoke the `onComplete` callback that we passed
702
+ // into `socket.subscribe(...)`
703
+ if (this.socket !== null) {
704
+ this.socket.complete();
705
+ this.socket = null;
706
+ }
707
+ };
708
+ return WebSocketHandler;
709
+ }());
710
+ /** @nocollapse */ WebSocketHandler.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: WebSocketHandler, deps: [{ token: i1__namespace.Store }, { token: i1__namespace.Actions }, { token: NGXS_WEBSOCKET_OPTIONS }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
711
+ /** @nocollapse */ WebSocketHandler.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: WebSocketHandler });
712
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: WebSocketHandler, decorators: [{
713
+ type: i0.Injectable
714
+ }], ctorParameters: function () {
715
+ return [{ type: i1__namespace.Store }, { type: i1__namespace.Actions }, { type: undefined, decorators: [{
716
+ type: i0.Inject,
717
+ args: [NGXS_WEBSOCKET_OPTIONS]
718
+ }] }];
719
+ } });
631
720
 
632
- function websocketOptionsFactory(options) {
633
- return Object.assign({ reconnectInterval: 5000, reconnectAttempts: 10, typeKey: 'type', deserializer: function (e) {
634
- return JSON.parse(e.data);
635
- },
636
- serializer: function (value) {
637
- return JSON.stringify(value);
638
- } }, options);
639
- }
640
- var USER_OPTIONS = new i0.InjectionToken('USER_OPTIONS');
641
- var NgxsWebsocketPluginModule = /** @class */ (function () {
642
- function NgxsWebsocketPluginModule() {
643
- }
644
- NgxsWebsocketPluginModule.forRoot = function (options) {
645
- return {
646
- ngModule: NgxsWebsocketPluginModule,
647
- providers: [
648
- WebSocketHandler,
649
- {
650
- provide: USER_OPTIONS,
651
- useValue: options
652
- },
653
- {
654
- provide: NGXS_WEBSOCKET_OPTIONS,
655
- useFactory: websocketOptionsFactory,
656
- deps: [USER_OPTIONS]
657
- },
658
- {
659
- provide: i0.APP_INITIALIZER,
660
- useFactory: noop,
661
- deps: [WebSocketHandler],
662
- multi: true
663
- }
664
- ]
665
- };
666
- };
667
- return NgxsWebsocketPluginModule;
668
- }());
669
- /** @nocollapse */ NgxsWebsocketPluginModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NgxsWebsocketPluginModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
670
- /** @nocollapse */ NgxsWebsocketPluginModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NgxsWebsocketPluginModule });
671
- /** @nocollapse */ NgxsWebsocketPluginModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NgxsWebsocketPluginModule });
672
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NgxsWebsocketPluginModule, decorators: [{
673
- type: i0.NgModule
674
- }] });
721
+ function websocketOptionsFactory(options) {
722
+ return Object.assign({ reconnectInterval: 5000, reconnectAttempts: 10, typeKey: 'type', deserializer: function (e) {
723
+ return JSON.parse(e.data);
724
+ },
725
+ serializer: function (value) {
726
+ return JSON.stringify(value);
727
+ } }, options);
728
+ }
729
+ var USER_OPTIONS = new i0.InjectionToken('USER_OPTIONS');
730
+ var NgxsWebsocketPluginModule = /** @class */ (function () {
731
+ function NgxsWebsocketPluginModule() {
732
+ }
733
+ NgxsWebsocketPluginModule.forRoot = function (options) {
734
+ return {
735
+ ngModule: NgxsWebsocketPluginModule,
736
+ providers: [
737
+ WebSocketHandler,
738
+ {
739
+ provide: USER_OPTIONS,
740
+ useValue: options
741
+ },
742
+ {
743
+ provide: NGXS_WEBSOCKET_OPTIONS,
744
+ useFactory: websocketOptionsFactory,
745
+ deps: [USER_OPTIONS]
746
+ },
747
+ {
748
+ provide: i0.APP_INITIALIZER,
749
+ useFactory: noop,
750
+ deps: [WebSocketHandler],
751
+ multi: true
752
+ }
753
+ ]
754
+ };
755
+ };
756
+ return NgxsWebsocketPluginModule;
757
+ }());
758
+ /** @nocollapse */ NgxsWebsocketPluginModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NgxsWebsocketPluginModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
759
+ /** @nocollapse */ NgxsWebsocketPluginModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NgxsWebsocketPluginModule });
760
+ /** @nocollapse */ NgxsWebsocketPluginModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NgxsWebsocketPluginModule });
761
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NgxsWebsocketPluginModule, decorators: [{
762
+ type: i0.NgModule
763
+ }] });
675
764
 
676
- /**
677
- * The public api for consumers of @ngxs/websocket-plugin
678
- */
765
+ /**
766
+ * The public api for consumers of @ngxs/websocket-plugin
767
+ */
679
768
 
680
- /**
681
- * Generated bundle index. Do not edit.
682
- */
769
+ /**
770
+ * Generated bundle index. Do not edit.
771
+ */
683
772
 
684
- exports.ConnectWebSocket = ConnectWebSocket;
685
- exports.DisconnectWebSocket = DisconnectWebSocket;
686
- exports.NGXS_WEBSOCKET_OPTIONS = NGXS_WEBSOCKET_OPTIONS;
687
- exports.NgxsWebsocketPluginModule = NgxsWebsocketPluginModule;
688
- exports.SendWebSocketMessage = SendWebSocketMessage;
689
- exports.WebSocketConnected = WebSocketConnected;
690
- exports.WebSocketConnectionUpdated = WebSocketConnectionUpdated;
691
- exports.WebSocketDisconnected = WebSocketDisconnected;
692
- exports.WebsocketMessageError = WebsocketMessageError;
773
+ exports.ConnectWebSocket = ConnectWebSocket;
774
+ exports.DisconnectWebSocket = DisconnectWebSocket;
775
+ exports.NGXS_WEBSOCKET_OPTIONS = NGXS_WEBSOCKET_OPTIONS;
776
+ exports.NgxsWebsocketPluginModule = NgxsWebsocketPluginModule;
777
+ exports.SendWebSocketMessage = SendWebSocketMessage;
778
+ exports.WebSocketConnected = WebSocketConnected;
779
+ exports.WebSocketConnectionUpdated = WebSocketConnectionUpdated;
780
+ exports.WebSocketDisconnected = WebSocketDisconnected;
781
+ exports.WebsocketMessageError = WebsocketMessageError;
693
782
 
694
- Object.defineProperty(exports, '__esModule', { value: true });
783
+ Object.defineProperty(exports, '__esModule', { value: true });
695
784
 
696
785
  }));
697
786
  //# sourceMappingURL=ngxs-websocket-plugin.umd.js.map