@ngxs/websocket-plugin 3.7.4 → 3.7.5-dev.master-17a1bb8
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.
- package/README.md +3 -3
- package/bundles/ngxs-websocket-plugin.umd.js +615 -615
- package/bundles/ngxs-websocket-plugin.umd.js.map +1 -1
- package/bundles/ngxs-websocket-plugin.umd.min.js.map +1 -1
- package/esm2015/index.js +9 -9
- package/esm2015/ngxs-websocket-plugin.js +11 -11
- package/esm2015/src/public_api.js +7 -7
- package/esm2015/src/symbols.js +197 -197
- package/esm2015/src/websocket-handler.js +245 -245
- package/esm2015/src/websocket.module.js +62 -62
- package/esm5/index.js +9 -9
- package/esm5/ngxs-websocket-plugin.js +11 -11
- package/esm5/src/public_api.js +7 -7
- package/esm5/src/symbols.js +293 -293
- package/esm5/src/websocket-handler.js +304 -304
- package/esm5/src/websocket.module.js +71 -71
- package/fesm2015/ngxs-websocket-plugin.js +498 -498
- package/fesm2015/ngxs-websocket-plugin.js.map +1 -1
- package/fesm5/ngxs-websocket-plugin.js +624 -624
- package/fesm5/ngxs-websocket-plugin.js.map +1 -1
- package/index.d.ts +4 -4
- package/ngxs-websocket-plugin.d.ts +7 -7
- package/package.json +2 -2
- package/src/public_api.d.ts +2 -2
- package/src/symbols.d.ts +100 -100
- package/src/websocket-handler.d.ts +34 -34
- package/src/websocket.module.d.ts +16 -16
- package/tests/typings.d.ts +18 -18
|
@@ -223,625 +223,625 @@
|
|
|
223
223
|
return value;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
/**
|
|
227
|
-
* @fileoverview added by tsickle
|
|
228
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
229
|
-
*/
|
|
230
|
-
/** @type {?} */
|
|
231
|
-
var NGXS_WEBSOCKET_OPTIONS = new core.InjectionToken('NGXS_WEBSOCKET_OPTIONS');
|
|
232
|
-
/**
|
|
233
|
-
* @record
|
|
234
|
-
*/
|
|
235
|
-
function NgxsWebsocketPluginOptions() { }
|
|
236
|
-
if (false) {
|
|
237
|
-
/**
|
|
238
|
-
* URL of the websocket.
|
|
239
|
-
* @type {?|undefined}
|
|
240
|
-
*/
|
|
241
|
-
NgxsWebsocketPluginOptions.prototype.url;
|
|
242
|
-
/**
|
|
243
|
-
* Either a single protocol string or an array of protocol strings.
|
|
244
|
-
* These strings are used to indicate sub-protocols, so that a single server
|
|
245
|
-
* can implement multiple WebSocket sub-protocols (for example, you might want one server to be able
|
|
246
|
-
* to handle different types of interactions depending on the specified protocol).
|
|
247
|
-
* If you don't specify a protocol string, an empty string is assumed.
|
|
248
|
-
* @type {?|undefined}
|
|
249
|
-
*/
|
|
250
|
-
NgxsWebsocketPluginOptions.prototype.protocol;
|
|
251
|
-
/**
|
|
252
|
-
* Sets the `binaryType` property of the underlying WebSocket.
|
|
253
|
-
* @type {?|undefined}
|
|
254
|
-
*/
|
|
255
|
-
NgxsWebsocketPluginOptions.prototype.binaryType;
|
|
256
|
-
/**
|
|
257
|
-
* The property name to distigunish this type for the store.
|
|
258
|
-
* Default: 'type'
|
|
259
|
-
* @type {?|undefined}
|
|
260
|
-
*/
|
|
261
|
-
NgxsWebsocketPluginOptions.prototype.typeKey;
|
|
262
|
-
/**
|
|
263
|
-
* Interval to try and reconnect.
|
|
264
|
-
* Default: 5000
|
|
265
|
-
* @type {?|undefined}
|
|
266
|
-
*/
|
|
267
|
-
NgxsWebsocketPluginOptions.prototype.reconnectInterval;
|
|
268
|
-
/**
|
|
269
|
-
* Number of reconnect attemps.
|
|
270
|
-
* Default: 10
|
|
271
|
-
* @type {?|undefined}
|
|
272
|
-
*/
|
|
273
|
-
NgxsWebsocketPluginOptions.prototype.reconnectAttempts;
|
|
274
|
-
/**
|
|
275
|
-
* Serializer to call before sending messages
|
|
276
|
-
* Default: `json.stringify`
|
|
277
|
-
* @type {?|undefined}
|
|
278
|
-
*/
|
|
279
|
-
NgxsWebsocketPluginOptions.prototype.serializer;
|
|
280
|
-
/**
|
|
281
|
-
* Deseralizer before publishing the message.
|
|
282
|
-
* @type {?|undefined}
|
|
283
|
-
*/
|
|
284
|
-
NgxsWebsocketPluginOptions.prototype.deserializer;
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* @param {...?} _args
|
|
288
|
-
* @return {?}
|
|
289
|
-
*/
|
|
290
|
-
function noop() {
|
|
291
|
-
var _args = [];
|
|
292
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
293
|
-
_args[_i] = arguments[_i];
|
|
294
|
-
}
|
|
295
|
-
return (/**
|
|
296
|
-
* @return {?}
|
|
297
|
-
*/
|
|
298
|
-
function () { });
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Action to connect to the websocket. Optionally pass a URL.
|
|
302
|
-
*/
|
|
303
|
-
var /**
|
|
304
|
-
* Action to connect to the websocket. Optionally pass a URL.
|
|
305
|
-
*/
|
|
306
|
-
ConnectWebSocket = /** @class */ (function () {
|
|
307
|
-
function ConnectWebSocket(payload) {
|
|
308
|
-
this.payload = payload;
|
|
309
|
-
}
|
|
310
|
-
Object.defineProperty(ConnectWebSocket, "type", {
|
|
311
|
-
get: /**
|
|
312
|
-
* @return {?}
|
|
313
|
-
*/
|
|
314
|
-
function () {
|
|
315
|
-
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
316
|
-
return '[WebSocket] Connect';
|
|
317
|
-
},
|
|
318
|
-
enumerable: true,
|
|
319
|
-
configurable: true
|
|
320
|
-
});
|
|
321
|
-
return ConnectWebSocket;
|
|
322
|
-
}());
|
|
323
|
-
if (false) {
|
|
324
|
-
/** @type {?} */
|
|
325
|
-
ConnectWebSocket.prototype.payload;
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Action triggered when a error ocurrs
|
|
329
|
-
*/
|
|
330
|
-
var /**
|
|
331
|
-
* Action triggered when a error ocurrs
|
|
332
|
-
*/
|
|
333
|
-
WebsocketMessageError = /** @class */ (function () {
|
|
334
|
-
function WebsocketMessageError(payload) {
|
|
335
|
-
this.payload = payload;
|
|
336
|
-
}
|
|
337
|
-
Object.defineProperty(WebsocketMessageError, "type", {
|
|
338
|
-
get: /**
|
|
339
|
-
* @return {?}
|
|
340
|
-
*/
|
|
341
|
-
function () {
|
|
342
|
-
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
343
|
-
return '[WebSocket] Message Error';
|
|
344
|
-
},
|
|
345
|
-
enumerable: true,
|
|
346
|
-
configurable: true
|
|
347
|
-
});
|
|
348
|
-
return WebsocketMessageError;
|
|
349
|
-
}());
|
|
350
|
-
if (false) {
|
|
351
|
-
/** @type {?} */
|
|
352
|
-
WebsocketMessageError.prototype.payload;
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Action to disconnect the websocket.
|
|
356
|
-
*/
|
|
357
|
-
var /**
|
|
358
|
-
* Action to disconnect the websocket.
|
|
359
|
-
*/
|
|
360
|
-
DisconnectWebSocket = /** @class */ (function () {
|
|
361
|
-
function DisconnectWebSocket() {
|
|
362
|
-
}
|
|
363
|
-
Object.defineProperty(DisconnectWebSocket, "type", {
|
|
364
|
-
get: /**
|
|
365
|
-
* @return {?}
|
|
366
|
-
*/
|
|
367
|
-
function () {
|
|
368
|
-
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
369
|
-
return '[WebSocket] Disconnect';
|
|
370
|
-
},
|
|
371
|
-
enumerable: true,
|
|
372
|
-
configurable: true
|
|
373
|
-
});
|
|
374
|
-
return DisconnectWebSocket;
|
|
375
|
-
}());
|
|
376
|
-
/**
|
|
377
|
-
* Action triggered when websocket is connected
|
|
378
|
-
*/
|
|
379
|
-
var /**
|
|
380
|
-
* Action triggered when websocket is connected
|
|
381
|
-
*/
|
|
382
|
-
WebSocketConnected = /** @class */ (function () {
|
|
383
|
-
function WebSocketConnected() {
|
|
384
|
-
}
|
|
385
|
-
Object.defineProperty(WebSocketConnected, "type", {
|
|
386
|
-
get: /**
|
|
387
|
-
* @return {?}
|
|
388
|
-
*/
|
|
389
|
-
function () {
|
|
390
|
-
return '[WebSocket] Connected';
|
|
391
|
-
},
|
|
392
|
-
enumerable: true,
|
|
393
|
-
configurable: true
|
|
394
|
-
});
|
|
395
|
-
return WebSocketConnected;
|
|
396
|
-
}());
|
|
397
|
-
/**
|
|
398
|
-
* Action triggered when websocket is disconnected
|
|
399
|
-
*/
|
|
400
|
-
var /**
|
|
401
|
-
* Action triggered when websocket is disconnected
|
|
402
|
-
*/
|
|
403
|
-
WebSocketDisconnected = /** @class */ (function () {
|
|
404
|
-
function WebSocketDisconnected() {
|
|
405
|
-
}
|
|
406
|
-
Object.defineProperty(WebSocketDisconnected, "type", {
|
|
407
|
-
get: /**
|
|
408
|
-
* @return {?}
|
|
409
|
-
*/
|
|
410
|
-
function () {
|
|
411
|
-
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
412
|
-
return '[WebSocket] Disconnected';
|
|
413
|
-
},
|
|
414
|
-
enumerable: true,
|
|
415
|
-
configurable: true
|
|
416
|
-
});
|
|
417
|
-
return WebSocketDisconnected;
|
|
418
|
-
}());
|
|
419
|
-
/**
|
|
420
|
-
* Action to send to the server.
|
|
421
|
-
*/
|
|
422
|
-
var /**
|
|
423
|
-
* Action to send to the server.
|
|
424
|
-
*/
|
|
425
|
-
SendWebSocketMessage = /** @class */ (function () {
|
|
426
|
-
function SendWebSocketMessage(payload) {
|
|
427
|
-
this.payload = payload;
|
|
428
|
-
}
|
|
429
|
-
Object.defineProperty(SendWebSocketMessage, "type", {
|
|
430
|
-
get: /**
|
|
431
|
-
* @return {?}
|
|
432
|
-
*/
|
|
433
|
-
function () {
|
|
434
|
-
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
435
|
-
return '[WebSocket] Send Message';
|
|
436
|
-
},
|
|
437
|
-
enumerable: true,
|
|
438
|
-
configurable: true
|
|
439
|
-
});
|
|
440
|
-
return SendWebSocketMessage;
|
|
441
|
-
}());
|
|
442
|
-
if (false) {
|
|
443
|
-
/** @type {?} */
|
|
444
|
-
SendWebSocketMessage.prototype.payload;
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Action dispatched when the user tries to connect if the connection already exists.
|
|
448
|
-
*/
|
|
449
|
-
var /**
|
|
450
|
-
* Action dispatched when the user tries to connect if the connection already exists.
|
|
451
|
-
*/
|
|
452
|
-
WebSocketConnectionUpdated = /** @class */ (function () {
|
|
453
|
-
function WebSocketConnectionUpdated() {
|
|
454
|
-
}
|
|
455
|
-
Object.defineProperty(WebSocketConnectionUpdated, "type", {
|
|
456
|
-
get: /**
|
|
457
|
-
* @return {?}
|
|
458
|
-
*/
|
|
459
|
-
function () {
|
|
460
|
-
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
461
|
-
return '[WebSocket] Connection Updated';
|
|
462
|
-
},
|
|
463
|
-
enumerable: true,
|
|
464
|
-
configurable: true
|
|
465
|
-
});
|
|
466
|
-
return WebSocketConnectionUpdated;
|
|
467
|
-
}());
|
|
468
|
-
/**
|
|
469
|
-
* This error is thrown where there is no `type` (or custom `typeKey`) property
|
|
470
|
-
* on the message that came from the server side socket
|
|
471
|
-
*/
|
|
472
|
-
var /**
|
|
473
|
-
* This error is thrown where there is no `type` (or custom `typeKey`) property
|
|
474
|
-
* on the message that came from the server side socket
|
|
475
|
-
*/
|
|
476
|
-
TypeKeyPropertyMissingError = /** @class */ (function (_super) {
|
|
477
|
-
__extends(TypeKeyPropertyMissingError, _super);
|
|
478
|
-
function TypeKeyPropertyMissingError(typeKey) {
|
|
479
|
-
return _super.call(this, "Property " + typeKey + " is missing on the socket message") || this;
|
|
480
|
-
}
|
|
481
|
-
return TypeKeyPropertyMissingError;
|
|
226
|
+
/**
|
|
227
|
+
* @fileoverview added by tsickle
|
|
228
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
229
|
+
*/
|
|
230
|
+
/** @type {?} */
|
|
231
|
+
var NGXS_WEBSOCKET_OPTIONS = new core.InjectionToken('NGXS_WEBSOCKET_OPTIONS');
|
|
232
|
+
/**
|
|
233
|
+
* @record
|
|
234
|
+
*/
|
|
235
|
+
function NgxsWebsocketPluginOptions() { }
|
|
236
|
+
if (false) {
|
|
237
|
+
/**
|
|
238
|
+
* URL of the websocket.
|
|
239
|
+
* @type {?|undefined}
|
|
240
|
+
*/
|
|
241
|
+
NgxsWebsocketPluginOptions.prototype.url;
|
|
242
|
+
/**
|
|
243
|
+
* Either a single protocol string or an array of protocol strings.
|
|
244
|
+
* These strings are used to indicate sub-protocols, so that a single server
|
|
245
|
+
* can implement multiple WebSocket sub-protocols (for example, you might want one server to be able
|
|
246
|
+
* to handle different types of interactions depending on the specified protocol).
|
|
247
|
+
* If you don't specify a protocol string, an empty string is assumed.
|
|
248
|
+
* @type {?|undefined}
|
|
249
|
+
*/
|
|
250
|
+
NgxsWebsocketPluginOptions.prototype.protocol;
|
|
251
|
+
/**
|
|
252
|
+
* Sets the `binaryType` property of the underlying WebSocket.
|
|
253
|
+
* @type {?|undefined}
|
|
254
|
+
*/
|
|
255
|
+
NgxsWebsocketPluginOptions.prototype.binaryType;
|
|
256
|
+
/**
|
|
257
|
+
* The property name to distigunish this type for the store.
|
|
258
|
+
* Default: 'type'
|
|
259
|
+
* @type {?|undefined}
|
|
260
|
+
*/
|
|
261
|
+
NgxsWebsocketPluginOptions.prototype.typeKey;
|
|
262
|
+
/**
|
|
263
|
+
* Interval to try and reconnect.
|
|
264
|
+
* Default: 5000
|
|
265
|
+
* @type {?|undefined}
|
|
266
|
+
*/
|
|
267
|
+
NgxsWebsocketPluginOptions.prototype.reconnectInterval;
|
|
268
|
+
/**
|
|
269
|
+
* Number of reconnect attemps.
|
|
270
|
+
* Default: 10
|
|
271
|
+
* @type {?|undefined}
|
|
272
|
+
*/
|
|
273
|
+
NgxsWebsocketPluginOptions.prototype.reconnectAttempts;
|
|
274
|
+
/**
|
|
275
|
+
* Serializer to call before sending messages
|
|
276
|
+
* Default: `json.stringify`
|
|
277
|
+
* @type {?|undefined}
|
|
278
|
+
*/
|
|
279
|
+
NgxsWebsocketPluginOptions.prototype.serializer;
|
|
280
|
+
/**
|
|
281
|
+
* Deseralizer before publishing the message.
|
|
282
|
+
* @type {?|undefined}
|
|
283
|
+
*/
|
|
284
|
+
NgxsWebsocketPluginOptions.prototype.deserializer;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* @param {...?} _args
|
|
288
|
+
* @return {?}
|
|
289
|
+
*/
|
|
290
|
+
function noop() {
|
|
291
|
+
var _args = [];
|
|
292
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
293
|
+
_args[_i] = arguments[_i];
|
|
294
|
+
}
|
|
295
|
+
return (/**
|
|
296
|
+
* @return {?}
|
|
297
|
+
*/
|
|
298
|
+
function () { });
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Action to connect to the websocket. Optionally pass a URL.
|
|
302
|
+
*/
|
|
303
|
+
var /**
|
|
304
|
+
* Action to connect to the websocket. Optionally pass a URL.
|
|
305
|
+
*/
|
|
306
|
+
ConnectWebSocket = /** @class */ (function () {
|
|
307
|
+
function ConnectWebSocket(payload) {
|
|
308
|
+
this.payload = payload;
|
|
309
|
+
}
|
|
310
|
+
Object.defineProperty(ConnectWebSocket, "type", {
|
|
311
|
+
get: /**
|
|
312
|
+
* @return {?}
|
|
313
|
+
*/
|
|
314
|
+
function () {
|
|
315
|
+
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
316
|
+
return '[WebSocket] Connect';
|
|
317
|
+
},
|
|
318
|
+
enumerable: true,
|
|
319
|
+
configurable: true
|
|
320
|
+
});
|
|
321
|
+
return ConnectWebSocket;
|
|
322
|
+
}());
|
|
323
|
+
if (false) {
|
|
324
|
+
/** @type {?} */
|
|
325
|
+
ConnectWebSocket.prototype.payload;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Action triggered when a error ocurrs
|
|
329
|
+
*/
|
|
330
|
+
var /**
|
|
331
|
+
* Action triggered when a error ocurrs
|
|
332
|
+
*/
|
|
333
|
+
WebsocketMessageError = /** @class */ (function () {
|
|
334
|
+
function WebsocketMessageError(payload) {
|
|
335
|
+
this.payload = payload;
|
|
336
|
+
}
|
|
337
|
+
Object.defineProperty(WebsocketMessageError, "type", {
|
|
338
|
+
get: /**
|
|
339
|
+
* @return {?}
|
|
340
|
+
*/
|
|
341
|
+
function () {
|
|
342
|
+
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
343
|
+
return '[WebSocket] Message Error';
|
|
344
|
+
},
|
|
345
|
+
enumerable: true,
|
|
346
|
+
configurable: true
|
|
347
|
+
});
|
|
348
|
+
return WebsocketMessageError;
|
|
349
|
+
}());
|
|
350
|
+
if (false) {
|
|
351
|
+
/** @type {?} */
|
|
352
|
+
WebsocketMessageError.prototype.payload;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Action to disconnect the websocket.
|
|
356
|
+
*/
|
|
357
|
+
var /**
|
|
358
|
+
* Action to disconnect the websocket.
|
|
359
|
+
*/
|
|
360
|
+
DisconnectWebSocket = /** @class */ (function () {
|
|
361
|
+
function DisconnectWebSocket() {
|
|
362
|
+
}
|
|
363
|
+
Object.defineProperty(DisconnectWebSocket, "type", {
|
|
364
|
+
get: /**
|
|
365
|
+
* @return {?}
|
|
366
|
+
*/
|
|
367
|
+
function () {
|
|
368
|
+
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
369
|
+
return '[WebSocket] Disconnect';
|
|
370
|
+
},
|
|
371
|
+
enumerable: true,
|
|
372
|
+
configurable: true
|
|
373
|
+
});
|
|
374
|
+
return DisconnectWebSocket;
|
|
375
|
+
}());
|
|
376
|
+
/**
|
|
377
|
+
* Action triggered when websocket is connected
|
|
378
|
+
*/
|
|
379
|
+
var /**
|
|
380
|
+
* Action triggered when websocket is connected
|
|
381
|
+
*/
|
|
382
|
+
WebSocketConnected = /** @class */ (function () {
|
|
383
|
+
function WebSocketConnected() {
|
|
384
|
+
}
|
|
385
|
+
Object.defineProperty(WebSocketConnected, "type", {
|
|
386
|
+
get: /**
|
|
387
|
+
* @return {?}
|
|
388
|
+
*/
|
|
389
|
+
function () {
|
|
390
|
+
return '[WebSocket] Connected';
|
|
391
|
+
},
|
|
392
|
+
enumerable: true,
|
|
393
|
+
configurable: true
|
|
394
|
+
});
|
|
395
|
+
return WebSocketConnected;
|
|
396
|
+
}());
|
|
397
|
+
/**
|
|
398
|
+
* Action triggered when websocket is disconnected
|
|
399
|
+
*/
|
|
400
|
+
var /**
|
|
401
|
+
* Action triggered when websocket is disconnected
|
|
402
|
+
*/
|
|
403
|
+
WebSocketDisconnected = /** @class */ (function () {
|
|
404
|
+
function WebSocketDisconnected() {
|
|
405
|
+
}
|
|
406
|
+
Object.defineProperty(WebSocketDisconnected, "type", {
|
|
407
|
+
get: /**
|
|
408
|
+
* @return {?}
|
|
409
|
+
*/
|
|
410
|
+
function () {
|
|
411
|
+
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
412
|
+
return '[WebSocket] Disconnected';
|
|
413
|
+
},
|
|
414
|
+
enumerable: true,
|
|
415
|
+
configurable: true
|
|
416
|
+
});
|
|
417
|
+
return WebSocketDisconnected;
|
|
418
|
+
}());
|
|
419
|
+
/**
|
|
420
|
+
* Action to send to the server.
|
|
421
|
+
*/
|
|
422
|
+
var /**
|
|
423
|
+
* Action to send to the server.
|
|
424
|
+
*/
|
|
425
|
+
SendWebSocketMessage = /** @class */ (function () {
|
|
426
|
+
function SendWebSocketMessage(payload) {
|
|
427
|
+
this.payload = payload;
|
|
428
|
+
}
|
|
429
|
+
Object.defineProperty(SendWebSocketMessage, "type", {
|
|
430
|
+
get: /**
|
|
431
|
+
* @return {?}
|
|
432
|
+
*/
|
|
433
|
+
function () {
|
|
434
|
+
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
435
|
+
return '[WebSocket] Send Message';
|
|
436
|
+
},
|
|
437
|
+
enumerable: true,
|
|
438
|
+
configurable: true
|
|
439
|
+
});
|
|
440
|
+
return SendWebSocketMessage;
|
|
441
|
+
}());
|
|
442
|
+
if (false) {
|
|
443
|
+
/** @type {?} */
|
|
444
|
+
SendWebSocketMessage.prototype.payload;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Action dispatched when the user tries to connect if the connection already exists.
|
|
448
|
+
*/
|
|
449
|
+
var /**
|
|
450
|
+
* Action dispatched when the user tries to connect if the connection already exists.
|
|
451
|
+
*/
|
|
452
|
+
WebSocketConnectionUpdated = /** @class */ (function () {
|
|
453
|
+
function WebSocketConnectionUpdated() {
|
|
454
|
+
}
|
|
455
|
+
Object.defineProperty(WebSocketConnectionUpdated, "type", {
|
|
456
|
+
get: /**
|
|
457
|
+
* @return {?}
|
|
458
|
+
*/
|
|
459
|
+
function () {
|
|
460
|
+
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
461
|
+
return '[WebSocket] Connection Updated';
|
|
462
|
+
},
|
|
463
|
+
enumerable: true,
|
|
464
|
+
configurable: true
|
|
465
|
+
});
|
|
466
|
+
return WebSocketConnectionUpdated;
|
|
467
|
+
}());
|
|
468
|
+
/**
|
|
469
|
+
* This error is thrown where there is no `type` (or custom `typeKey`) property
|
|
470
|
+
* on the message that came from the server side socket
|
|
471
|
+
*/
|
|
472
|
+
var /**
|
|
473
|
+
* This error is thrown where there is no `type` (or custom `typeKey`) property
|
|
474
|
+
* on the message that came from the server side socket
|
|
475
|
+
*/
|
|
476
|
+
TypeKeyPropertyMissingError = /** @class */ (function (_super) {
|
|
477
|
+
__extends(TypeKeyPropertyMissingError, _super);
|
|
478
|
+
function TypeKeyPropertyMissingError(typeKey) {
|
|
479
|
+
return _super.call(this, "Property " + typeKey + " is missing on the socket message") || this;
|
|
480
|
+
}
|
|
481
|
+
return TypeKeyPropertyMissingError;
|
|
482
482
|
}(Error));
|
|
483
483
|
|
|
484
|
-
/**
|
|
485
|
-
* @fileoverview added by tsickle
|
|
486
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
487
|
-
*/
|
|
488
|
-
var WebSocketHandler = /** @class */ (function () {
|
|
489
|
-
function WebSocketHandler(store, actions$, options) {
|
|
490
|
-
var _this = this;
|
|
491
|
-
this.store = store;
|
|
492
|
-
this.actions$ = actions$;
|
|
493
|
-
this.options = options;
|
|
494
|
-
this.socket = null;
|
|
495
|
-
this.config = {
|
|
496
|
-
url: (/** @type {?} */ (this.options.url)),
|
|
497
|
-
protocol: this.options.protocol,
|
|
498
|
-
// Default binary type is `blob` for the global `WebSocket`
|
|
499
|
-
binaryType: this.options.binaryType,
|
|
500
|
-
serializer: this.options.serializer,
|
|
501
|
-
deserializer: this.options.deserializer,
|
|
502
|
-
closeObserver: {
|
|
503
|
-
next: (/**
|
|
504
|
-
* @return {?}
|
|
505
|
-
*/
|
|
506
|
-
function () {
|
|
507
|
-
// ATTENTION!
|
|
508
|
-
// See https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/dom/WebSocketSubject.ts#L340
|
|
509
|
-
// RxJS socket emits `onComplete` event only if `event.wasClean` is truthy
|
|
510
|
-
// and doesn't complete socket subject if it's falsy
|
|
511
|
-
_this.disconnect();
|
|
512
|
-
})
|
|
513
|
-
},
|
|
514
|
-
openObserver: {
|
|
515
|
-
next: (/**
|
|
516
|
-
* @return {?}
|
|
517
|
-
*/
|
|
518
|
-
function () { return _this.store.dispatch(new WebSocketConnected()); })
|
|
519
|
-
}
|
|
520
|
-
};
|
|
521
|
-
this.typeKey = (/** @type {?} */ (this.options.typeKey));
|
|
522
|
-
this.subscription = new rxjs.Subscription();
|
|
523
|
-
this.setupActionsListeners();
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* @return {?}
|
|
527
|
-
*/
|
|
528
|
-
WebSocketHandler.prototype.ngOnDestroy = /**
|
|
529
|
-
* @return {?}
|
|
530
|
-
*/
|
|
531
|
-
function () {
|
|
532
|
-
this.closeConnection();
|
|
533
|
-
this.subscription.unsubscribe();
|
|
534
|
-
};
|
|
535
|
-
/**
|
|
536
|
-
* @private
|
|
537
|
-
* @return {?}
|
|
538
|
-
*/
|
|
539
|
-
WebSocketHandler.prototype.setupActionsListeners = /**
|
|
540
|
-
* @private
|
|
541
|
-
* @return {?}
|
|
542
|
-
*/
|
|
543
|
-
function () {
|
|
544
|
-
var _this = this;
|
|
545
|
-
this.subscription.add(this.actions$.pipe(store.ofActionDispatched(ConnectWebSocket)).subscribe((/**
|
|
546
|
-
* @param {?} __0
|
|
547
|
-
* @return {?}
|
|
548
|
-
*/
|
|
549
|
-
function (_a) {
|
|
550
|
-
var payload = _a.payload;
|
|
551
|
-
_this.connect(payload);
|
|
552
|
-
})));
|
|
553
|
-
this.subscription.add(this.actions$.pipe(store.ofActionDispatched(DisconnectWebSocket)).subscribe((/**
|
|
554
|
-
* @return {?}
|
|
555
|
-
*/
|
|
556
|
-
function () {
|
|
557
|
-
_this.disconnect();
|
|
558
|
-
})));
|
|
559
|
-
this.subscription.add(this.actions$.pipe(store.ofActionDispatched(SendWebSocketMessage)).subscribe((/**
|
|
560
|
-
* @param {?} __0
|
|
561
|
-
* @return {?}
|
|
562
|
-
*/
|
|
563
|
-
function (_a) {
|
|
564
|
-
var payload = _a.payload;
|
|
565
|
-
_this.send(payload);
|
|
566
|
-
})));
|
|
567
|
-
};
|
|
568
|
-
/**
|
|
569
|
-
* @private
|
|
570
|
-
* @param {?=} options
|
|
571
|
-
* @return {?}
|
|
572
|
-
*/
|
|
573
|
-
WebSocketHandler.prototype.connect = /**
|
|
574
|
-
* @private
|
|
575
|
-
* @param {?=} options
|
|
576
|
-
* @return {?}
|
|
577
|
-
*/
|
|
578
|
-
function (options) {
|
|
579
|
-
var _this = this;
|
|
580
|
-
this.updateConnection();
|
|
581
|
-
// Users can pass the options in the connect method so
|
|
582
|
-
// if options aren't available at DI bootstrap they have access
|
|
583
|
-
// to pass them here
|
|
584
|
-
if (options) {
|
|
585
|
-
this.mergeConfigWithOptions(options);
|
|
586
|
-
}
|
|
587
|
-
this.socket = new webSocket.WebSocketSubject(this.config);
|
|
588
|
-
this.socket.subscribe({
|
|
589
|
-
next: (/**
|
|
590
|
-
* @param {?} message
|
|
591
|
-
* @return {?}
|
|
592
|
-
*/
|
|
593
|
-
function (message) {
|
|
594
|
-
/** @type {?} */
|
|
595
|
-
var type = store.getValue(message, _this.typeKey);
|
|
596
|
-
if (!type) {
|
|
597
|
-
throw new TypeKeyPropertyMissingError(_this.typeKey);
|
|
598
|
-
}
|
|
599
|
-
_this.store.dispatch(__assign({}, message, { type: type }));
|
|
600
|
-
}),
|
|
601
|
-
error: (/**
|
|
602
|
-
* @param {?} error
|
|
603
|
-
* @return {?}
|
|
604
|
-
*/
|
|
605
|
-
function (error) {
|
|
606
|
-
if (error instanceof CloseEvent) {
|
|
607
|
-
_this.dispatchWebSocketDisconnected();
|
|
608
|
-
}
|
|
609
|
-
else {
|
|
610
|
-
_this.store.dispatch(new WebsocketMessageError(error));
|
|
611
|
-
}
|
|
612
|
-
})
|
|
613
|
-
});
|
|
614
|
-
};
|
|
615
|
-
/**
|
|
616
|
-
* @private
|
|
617
|
-
* @return {?}
|
|
618
|
-
*/
|
|
619
|
-
WebSocketHandler.prototype.disconnect = /**
|
|
620
|
-
* @private
|
|
621
|
-
* @return {?}
|
|
622
|
-
*/
|
|
623
|
-
function () {
|
|
624
|
-
if (this.socket) {
|
|
625
|
-
this.closeConnection();
|
|
626
|
-
this.dispatchWebSocketDisconnected();
|
|
627
|
-
}
|
|
628
|
-
};
|
|
629
|
-
/**
|
|
630
|
-
* @private
|
|
631
|
-
* @param {?} data
|
|
632
|
-
* @return {?}
|
|
633
|
-
*/
|
|
634
|
-
WebSocketHandler.prototype.send = /**
|
|
635
|
-
* @private
|
|
636
|
-
* @param {?} data
|
|
637
|
-
* @return {?}
|
|
638
|
-
*/
|
|
639
|
-
function (data) {
|
|
640
|
-
if (!this.socket) {
|
|
641
|
-
throw new Error('You must connect to the socket before sending any data');
|
|
642
|
-
}
|
|
643
|
-
this.socket.next(data);
|
|
644
|
-
};
|
|
645
|
-
/**
|
|
646
|
-
* Don't enlarge the `connect` method
|
|
647
|
-
*/
|
|
648
|
-
/**
|
|
649
|
-
* Don't enlarge the `connect` method
|
|
650
|
-
* @private
|
|
651
|
-
* @param {?} options
|
|
652
|
-
* @return {?}
|
|
653
|
-
*/
|
|
654
|
-
WebSocketHandler.prototype.mergeConfigWithOptions = /**
|
|
655
|
-
* Don't enlarge the `connect` method
|
|
656
|
-
* @private
|
|
657
|
-
* @param {?} options
|
|
658
|
-
* @return {?}
|
|
659
|
-
*/
|
|
660
|
-
function (options) {
|
|
661
|
-
if (options.url) {
|
|
662
|
-
this.config.url = options.url;
|
|
663
|
-
}
|
|
664
|
-
if (options.serializer) {
|
|
665
|
-
this.config.serializer = options.serializer;
|
|
666
|
-
}
|
|
667
|
-
if (options.deserializer) {
|
|
668
|
-
this.config.deserializer = options.deserializer;
|
|
669
|
-
}
|
|
670
|
-
};
|
|
671
|
-
/**
|
|
672
|
-
* To ensure we don't have any memory leaks
|
|
673
|
-
* e.g. if the user occasionally dispatched `ConnectWebSocket` twice
|
|
674
|
-
* then the previous subscription will still live in the memory
|
|
675
|
-
* to prevent such behavior - we close the previous connection if it exists
|
|
676
|
-
*/
|
|
677
|
-
/**
|
|
678
|
-
* To ensure we don't have any memory leaks
|
|
679
|
-
* e.g. if the user occasionally dispatched `ConnectWebSocket` twice
|
|
680
|
-
* then the previous subscription will still live in the memory
|
|
681
|
-
* to prevent such behavior - we close the previous connection if it exists
|
|
682
|
-
* @private
|
|
683
|
-
* @return {?}
|
|
684
|
-
*/
|
|
685
|
-
WebSocketHandler.prototype.updateConnection = /**
|
|
686
|
-
* To ensure we don't have any memory leaks
|
|
687
|
-
* e.g. if the user occasionally dispatched `ConnectWebSocket` twice
|
|
688
|
-
* then the previous subscription will still live in the memory
|
|
689
|
-
* to prevent such behavior - we close the previous connection if it exists
|
|
690
|
-
* @private
|
|
691
|
-
* @return {?}
|
|
692
|
-
*/
|
|
693
|
-
function () {
|
|
694
|
-
if (this.socket) {
|
|
695
|
-
this.closeConnection();
|
|
696
|
-
this.store.dispatch(new WebSocketConnectionUpdated());
|
|
697
|
-
}
|
|
698
|
-
};
|
|
699
|
-
/**
|
|
700
|
-
* Used in many places so it's better to move the code into function
|
|
701
|
-
*/
|
|
702
|
-
/**
|
|
703
|
-
* Used in many places so it's better to move the code into function
|
|
704
|
-
* @private
|
|
705
|
-
* @return {?}
|
|
706
|
-
*/
|
|
707
|
-
WebSocketHandler.prototype.dispatchWebSocketDisconnected = /**
|
|
708
|
-
* Used in many places so it's better to move the code into function
|
|
709
|
-
* @private
|
|
710
|
-
* @return {?}
|
|
711
|
-
*/
|
|
712
|
-
function () {
|
|
713
|
-
this.store.dispatch(new WebSocketDisconnected());
|
|
714
|
-
};
|
|
715
|
-
/**
|
|
716
|
-
* @private
|
|
717
|
-
* @return {?}
|
|
718
|
-
*/
|
|
719
|
-
WebSocketHandler.prototype.closeConnection = /**
|
|
720
|
-
* @private
|
|
721
|
-
* @return {?}
|
|
722
|
-
*/
|
|
723
|
-
function () {
|
|
724
|
-
// `socket.complete()` closes the connection
|
|
725
|
-
// also it doesn't invoke the `onComplete` callback that we passed
|
|
726
|
-
// into `socket.subscribe(...)`
|
|
727
|
-
if (this.socket !== null) {
|
|
728
|
-
this.socket.complete();
|
|
729
|
-
this.socket = null;
|
|
730
|
-
}
|
|
731
|
-
};
|
|
732
|
-
WebSocketHandler.decorators = [
|
|
733
|
-
{ type: core.Injectable }
|
|
734
|
-
];
|
|
735
|
-
/** @nocollapse */
|
|
736
|
-
WebSocketHandler.ctorParameters = function () { return [
|
|
737
|
-
{ type: store.Store },
|
|
738
|
-
{ type: store.Actions },
|
|
739
|
-
{ type: undefined, decorators: [{ type: core.Inject, args: [NGXS_WEBSOCKET_OPTIONS,] }] }
|
|
740
|
-
]; };
|
|
741
|
-
return WebSocketHandler;
|
|
742
|
-
}());
|
|
743
|
-
if (false) {
|
|
744
|
-
/**
|
|
745
|
-
* @type {?}
|
|
746
|
-
* @private
|
|
747
|
-
*/
|
|
748
|
-
WebSocketHandler.prototype.socket;
|
|
749
|
-
/**
|
|
750
|
-
* @type {?}
|
|
751
|
-
* @private
|
|
752
|
-
*/
|
|
753
|
-
WebSocketHandler.prototype.config;
|
|
754
|
-
/**
|
|
755
|
-
* @type {?}
|
|
756
|
-
* @private
|
|
757
|
-
*/
|
|
758
|
-
WebSocketHandler.prototype.typeKey;
|
|
759
|
-
/**
|
|
760
|
-
* @type {?}
|
|
761
|
-
* @private
|
|
762
|
-
*/
|
|
763
|
-
WebSocketHandler.prototype.subscription;
|
|
764
|
-
/**
|
|
765
|
-
* @type {?}
|
|
766
|
-
* @private
|
|
767
|
-
*/
|
|
768
|
-
WebSocketHandler.prototype.store;
|
|
769
|
-
/**
|
|
770
|
-
* @type {?}
|
|
771
|
-
* @private
|
|
772
|
-
*/
|
|
773
|
-
WebSocketHandler.prototype.actions$;
|
|
774
|
-
/**
|
|
775
|
-
* @type {?}
|
|
776
|
-
* @private
|
|
777
|
-
*/
|
|
778
|
-
WebSocketHandler.prototype.options;
|
|
484
|
+
/**
|
|
485
|
+
* @fileoverview added by tsickle
|
|
486
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
487
|
+
*/
|
|
488
|
+
var WebSocketHandler = /** @class */ (function () {
|
|
489
|
+
function WebSocketHandler(store, actions$, options) {
|
|
490
|
+
var _this = this;
|
|
491
|
+
this.store = store;
|
|
492
|
+
this.actions$ = actions$;
|
|
493
|
+
this.options = options;
|
|
494
|
+
this.socket = null;
|
|
495
|
+
this.config = {
|
|
496
|
+
url: (/** @type {?} */ (this.options.url)),
|
|
497
|
+
protocol: this.options.protocol,
|
|
498
|
+
// Default binary type is `blob` for the global `WebSocket`
|
|
499
|
+
binaryType: this.options.binaryType,
|
|
500
|
+
serializer: this.options.serializer,
|
|
501
|
+
deserializer: this.options.deserializer,
|
|
502
|
+
closeObserver: {
|
|
503
|
+
next: (/**
|
|
504
|
+
* @return {?}
|
|
505
|
+
*/
|
|
506
|
+
function () {
|
|
507
|
+
// ATTENTION!
|
|
508
|
+
// See https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/dom/WebSocketSubject.ts#L340
|
|
509
|
+
// RxJS socket emits `onComplete` event only if `event.wasClean` is truthy
|
|
510
|
+
// and doesn't complete socket subject if it's falsy
|
|
511
|
+
_this.disconnect();
|
|
512
|
+
})
|
|
513
|
+
},
|
|
514
|
+
openObserver: {
|
|
515
|
+
next: (/**
|
|
516
|
+
* @return {?}
|
|
517
|
+
*/
|
|
518
|
+
function () { return _this.store.dispatch(new WebSocketConnected()); })
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
this.typeKey = (/** @type {?} */ (this.options.typeKey));
|
|
522
|
+
this.subscription = new rxjs.Subscription();
|
|
523
|
+
this.setupActionsListeners();
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* @return {?}
|
|
527
|
+
*/
|
|
528
|
+
WebSocketHandler.prototype.ngOnDestroy = /**
|
|
529
|
+
* @return {?}
|
|
530
|
+
*/
|
|
531
|
+
function () {
|
|
532
|
+
this.closeConnection();
|
|
533
|
+
this.subscription.unsubscribe();
|
|
534
|
+
};
|
|
535
|
+
/**
|
|
536
|
+
* @private
|
|
537
|
+
* @return {?}
|
|
538
|
+
*/
|
|
539
|
+
WebSocketHandler.prototype.setupActionsListeners = /**
|
|
540
|
+
* @private
|
|
541
|
+
* @return {?}
|
|
542
|
+
*/
|
|
543
|
+
function () {
|
|
544
|
+
var _this = this;
|
|
545
|
+
this.subscription.add(this.actions$.pipe(store.ofActionDispatched(ConnectWebSocket)).subscribe((/**
|
|
546
|
+
* @param {?} __0
|
|
547
|
+
* @return {?}
|
|
548
|
+
*/
|
|
549
|
+
function (_a) {
|
|
550
|
+
var payload = _a.payload;
|
|
551
|
+
_this.connect(payload);
|
|
552
|
+
})));
|
|
553
|
+
this.subscription.add(this.actions$.pipe(store.ofActionDispatched(DisconnectWebSocket)).subscribe((/**
|
|
554
|
+
* @return {?}
|
|
555
|
+
*/
|
|
556
|
+
function () {
|
|
557
|
+
_this.disconnect();
|
|
558
|
+
})));
|
|
559
|
+
this.subscription.add(this.actions$.pipe(store.ofActionDispatched(SendWebSocketMessage)).subscribe((/**
|
|
560
|
+
* @param {?} __0
|
|
561
|
+
* @return {?}
|
|
562
|
+
*/
|
|
563
|
+
function (_a) {
|
|
564
|
+
var payload = _a.payload;
|
|
565
|
+
_this.send(payload);
|
|
566
|
+
})));
|
|
567
|
+
};
|
|
568
|
+
/**
|
|
569
|
+
* @private
|
|
570
|
+
* @param {?=} options
|
|
571
|
+
* @return {?}
|
|
572
|
+
*/
|
|
573
|
+
WebSocketHandler.prototype.connect = /**
|
|
574
|
+
* @private
|
|
575
|
+
* @param {?=} options
|
|
576
|
+
* @return {?}
|
|
577
|
+
*/
|
|
578
|
+
function (options) {
|
|
579
|
+
var _this = this;
|
|
580
|
+
this.updateConnection();
|
|
581
|
+
// Users can pass the options in the connect method so
|
|
582
|
+
// if options aren't available at DI bootstrap they have access
|
|
583
|
+
// to pass them here
|
|
584
|
+
if (options) {
|
|
585
|
+
this.mergeConfigWithOptions(options);
|
|
586
|
+
}
|
|
587
|
+
this.socket = new webSocket.WebSocketSubject(this.config);
|
|
588
|
+
this.socket.subscribe({
|
|
589
|
+
next: (/**
|
|
590
|
+
* @param {?} message
|
|
591
|
+
* @return {?}
|
|
592
|
+
*/
|
|
593
|
+
function (message) {
|
|
594
|
+
/** @type {?} */
|
|
595
|
+
var type = store.getValue(message, _this.typeKey);
|
|
596
|
+
if (!type) {
|
|
597
|
+
throw new TypeKeyPropertyMissingError(_this.typeKey);
|
|
598
|
+
}
|
|
599
|
+
_this.store.dispatch(__assign({}, message, { type: type }));
|
|
600
|
+
}),
|
|
601
|
+
error: (/**
|
|
602
|
+
* @param {?} error
|
|
603
|
+
* @return {?}
|
|
604
|
+
*/
|
|
605
|
+
function (error) {
|
|
606
|
+
if (error instanceof CloseEvent) {
|
|
607
|
+
_this.dispatchWebSocketDisconnected();
|
|
608
|
+
}
|
|
609
|
+
else {
|
|
610
|
+
_this.store.dispatch(new WebsocketMessageError(error));
|
|
611
|
+
}
|
|
612
|
+
})
|
|
613
|
+
});
|
|
614
|
+
};
|
|
615
|
+
/**
|
|
616
|
+
* @private
|
|
617
|
+
* @return {?}
|
|
618
|
+
*/
|
|
619
|
+
WebSocketHandler.prototype.disconnect = /**
|
|
620
|
+
* @private
|
|
621
|
+
* @return {?}
|
|
622
|
+
*/
|
|
623
|
+
function () {
|
|
624
|
+
if (this.socket) {
|
|
625
|
+
this.closeConnection();
|
|
626
|
+
this.dispatchWebSocketDisconnected();
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
/**
|
|
630
|
+
* @private
|
|
631
|
+
* @param {?} data
|
|
632
|
+
* @return {?}
|
|
633
|
+
*/
|
|
634
|
+
WebSocketHandler.prototype.send = /**
|
|
635
|
+
* @private
|
|
636
|
+
* @param {?} data
|
|
637
|
+
* @return {?}
|
|
638
|
+
*/
|
|
639
|
+
function (data) {
|
|
640
|
+
if (!this.socket) {
|
|
641
|
+
throw new Error('You must connect to the socket before sending any data');
|
|
642
|
+
}
|
|
643
|
+
this.socket.next(data);
|
|
644
|
+
};
|
|
645
|
+
/**
|
|
646
|
+
* Don't enlarge the `connect` method
|
|
647
|
+
*/
|
|
648
|
+
/**
|
|
649
|
+
* Don't enlarge the `connect` method
|
|
650
|
+
* @private
|
|
651
|
+
* @param {?} options
|
|
652
|
+
* @return {?}
|
|
653
|
+
*/
|
|
654
|
+
WebSocketHandler.prototype.mergeConfigWithOptions = /**
|
|
655
|
+
* Don't enlarge the `connect` method
|
|
656
|
+
* @private
|
|
657
|
+
* @param {?} options
|
|
658
|
+
* @return {?}
|
|
659
|
+
*/
|
|
660
|
+
function (options) {
|
|
661
|
+
if (options.url) {
|
|
662
|
+
this.config.url = options.url;
|
|
663
|
+
}
|
|
664
|
+
if (options.serializer) {
|
|
665
|
+
this.config.serializer = options.serializer;
|
|
666
|
+
}
|
|
667
|
+
if (options.deserializer) {
|
|
668
|
+
this.config.deserializer = options.deserializer;
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
/**
|
|
672
|
+
* To ensure we don't have any memory leaks
|
|
673
|
+
* e.g. if the user occasionally dispatched `ConnectWebSocket` twice
|
|
674
|
+
* then the previous subscription will still live in the memory
|
|
675
|
+
* to prevent such behavior - we close the previous connection if it exists
|
|
676
|
+
*/
|
|
677
|
+
/**
|
|
678
|
+
* To ensure we don't have any memory leaks
|
|
679
|
+
* e.g. if the user occasionally dispatched `ConnectWebSocket` twice
|
|
680
|
+
* then the previous subscription will still live in the memory
|
|
681
|
+
* to prevent such behavior - we close the previous connection if it exists
|
|
682
|
+
* @private
|
|
683
|
+
* @return {?}
|
|
684
|
+
*/
|
|
685
|
+
WebSocketHandler.prototype.updateConnection = /**
|
|
686
|
+
* To ensure we don't have any memory leaks
|
|
687
|
+
* e.g. if the user occasionally dispatched `ConnectWebSocket` twice
|
|
688
|
+
* then the previous subscription will still live in the memory
|
|
689
|
+
* to prevent such behavior - we close the previous connection if it exists
|
|
690
|
+
* @private
|
|
691
|
+
* @return {?}
|
|
692
|
+
*/
|
|
693
|
+
function () {
|
|
694
|
+
if (this.socket) {
|
|
695
|
+
this.closeConnection();
|
|
696
|
+
this.store.dispatch(new WebSocketConnectionUpdated());
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
/**
|
|
700
|
+
* Used in many places so it's better to move the code into function
|
|
701
|
+
*/
|
|
702
|
+
/**
|
|
703
|
+
* Used in many places so it's better to move the code into function
|
|
704
|
+
* @private
|
|
705
|
+
* @return {?}
|
|
706
|
+
*/
|
|
707
|
+
WebSocketHandler.prototype.dispatchWebSocketDisconnected = /**
|
|
708
|
+
* Used in many places so it's better to move the code into function
|
|
709
|
+
* @private
|
|
710
|
+
* @return {?}
|
|
711
|
+
*/
|
|
712
|
+
function () {
|
|
713
|
+
this.store.dispatch(new WebSocketDisconnected());
|
|
714
|
+
};
|
|
715
|
+
/**
|
|
716
|
+
* @private
|
|
717
|
+
* @return {?}
|
|
718
|
+
*/
|
|
719
|
+
WebSocketHandler.prototype.closeConnection = /**
|
|
720
|
+
* @private
|
|
721
|
+
* @return {?}
|
|
722
|
+
*/
|
|
723
|
+
function () {
|
|
724
|
+
// `socket.complete()` closes the connection
|
|
725
|
+
// also it doesn't invoke the `onComplete` callback that we passed
|
|
726
|
+
// into `socket.subscribe(...)`
|
|
727
|
+
if (this.socket !== null) {
|
|
728
|
+
this.socket.complete();
|
|
729
|
+
this.socket = null;
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
WebSocketHandler.decorators = [
|
|
733
|
+
{ type: core.Injectable }
|
|
734
|
+
];
|
|
735
|
+
/** @nocollapse */
|
|
736
|
+
WebSocketHandler.ctorParameters = function () { return [
|
|
737
|
+
{ type: store.Store },
|
|
738
|
+
{ type: store.Actions },
|
|
739
|
+
{ type: undefined, decorators: [{ type: core.Inject, args: [NGXS_WEBSOCKET_OPTIONS,] }] }
|
|
740
|
+
]; };
|
|
741
|
+
return WebSocketHandler;
|
|
742
|
+
}());
|
|
743
|
+
if (false) {
|
|
744
|
+
/**
|
|
745
|
+
* @type {?}
|
|
746
|
+
* @private
|
|
747
|
+
*/
|
|
748
|
+
WebSocketHandler.prototype.socket;
|
|
749
|
+
/**
|
|
750
|
+
* @type {?}
|
|
751
|
+
* @private
|
|
752
|
+
*/
|
|
753
|
+
WebSocketHandler.prototype.config;
|
|
754
|
+
/**
|
|
755
|
+
* @type {?}
|
|
756
|
+
* @private
|
|
757
|
+
*/
|
|
758
|
+
WebSocketHandler.prototype.typeKey;
|
|
759
|
+
/**
|
|
760
|
+
* @type {?}
|
|
761
|
+
* @private
|
|
762
|
+
*/
|
|
763
|
+
WebSocketHandler.prototype.subscription;
|
|
764
|
+
/**
|
|
765
|
+
* @type {?}
|
|
766
|
+
* @private
|
|
767
|
+
*/
|
|
768
|
+
WebSocketHandler.prototype.store;
|
|
769
|
+
/**
|
|
770
|
+
* @type {?}
|
|
771
|
+
* @private
|
|
772
|
+
*/
|
|
773
|
+
WebSocketHandler.prototype.actions$;
|
|
774
|
+
/**
|
|
775
|
+
* @type {?}
|
|
776
|
+
* @private
|
|
777
|
+
*/
|
|
778
|
+
WebSocketHandler.prototype.options;
|
|
779
779
|
}
|
|
780
780
|
|
|
781
|
-
/**
|
|
782
|
-
* @fileoverview added by tsickle
|
|
783
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
784
|
-
*/
|
|
785
|
-
/**
|
|
786
|
-
* @param {?} options
|
|
787
|
-
* @return {?}
|
|
788
|
-
*/
|
|
789
|
-
function websocketOptionsFactory(options) {
|
|
790
|
-
return __assign({ reconnectInterval: 5000, reconnectAttempts: 10, typeKey: 'type', deserializer: /**
|
|
791
|
-
* @param {?} e
|
|
792
|
-
* @return {?}
|
|
793
|
-
*/
|
|
794
|
-
function (e) {
|
|
795
|
-
return JSON.parse(e.data);
|
|
796
|
-
},
|
|
797
|
-
serializer: /**
|
|
798
|
-
* @param {?} value
|
|
799
|
-
* @return {?}
|
|
800
|
-
*/
|
|
801
|
-
function (value) {
|
|
802
|
-
return JSON.stringify(value);
|
|
803
|
-
} }, options);
|
|
804
|
-
}
|
|
805
|
-
/** @type {?} */
|
|
806
|
-
var USER_OPTIONS = new core.InjectionToken('USER_OPTIONS');
|
|
807
|
-
var NgxsWebsocketPluginModule = /** @class */ (function () {
|
|
808
|
-
function NgxsWebsocketPluginModule() {
|
|
809
|
-
}
|
|
810
|
-
/**
|
|
811
|
-
* @param {?=} options
|
|
812
|
-
* @return {?}
|
|
813
|
-
*/
|
|
814
|
-
NgxsWebsocketPluginModule.forRoot = /**
|
|
815
|
-
* @param {?=} options
|
|
816
|
-
* @return {?}
|
|
817
|
-
*/
|
|
818
|
-
function (options) {
|
|
819
|
-
return {
|
|
820
|
-
ngModule: NgxsWebsocketPluginModule,
|
|
821
|
-
providers: [
|
|
822
|
-
WebSocketHandler,
|
|
823
|
-
{
|
|
824
|
-
provide: USER_OPTIONS,
|
|
825
|
-
useValue: options
|
|
826
|
-
},
|
|
827
|
-
{
|
|
828
|
-
provide: NGXS_WEBSOCKET_OPTIONS,
|
|
829
|
-
useFactory: websocketOptionsFactory,
|
|
830
|
-
deps: [USER_OPTIONS]
|
|
831
|
-
},
|
|
832
|
-
{
|
|
833
|
-
provide: core.APP_INITIALIZER,
|
|
834
|
-
useFactory: noop,
|
|
835
|
-
deps: [WebSocketHandler],
|
|
836
|
-
multi: true
|
|
837
|
-
}
|
|
838
|
-
]
|
|
839
|
-
};
|
|
840
|
-
};
|
|
841
|
-
NgxsWebsocketPluginModule.decorators = [
|
|
842
|
-
{ type: core.NgModule }
|
|
843
|
-
];
|
|
844
|
-
return NgxsWebsocketPluginModule;
|
|
781
|
+
/**
|
|
782
|
+
* @fileoverview added by tsickle
|
|
783
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
784
|
+
*/
|
|
785
|
+
/**
|
|
786
|
+
* @param {?} options
|
|
787
|
+
* @return {?}
|
|
788
|
+
*/
|
|
789
|
+
function websocketOptionsFactory(options) {
|
|
790
|
+
return __assign({ reconnectInterval: 5000, reconnectAttempts: 10, typeKey: 'type', deserializer: /**
|
|
791
|
+
* @param {?} e
|
|
792
|
+
* @return {?}
|
|
793
|
+
*/
|
|
794
|
+
function (e) {
|
|
795
|
+
return JSON.parse(e.data);
|
|
796
|
+
},
|
|
797
|
+
serializer: /**
|
|
798
|
+
* @param {?} value
|
|
799
|
+
* @return {?}
|
|
800
|
+
*/
|
|
801
|
+
function (value) {
|
|
802
|
+
return JSON.stringify(value);
|
|
803
|
+
} }, options);
|
|
804
|
+
}
|
|
805
|
+
/** @type {?} */
|
|
806
|
+
var USER_OPTIONS = new core.InjectionToken('USER_OPTIONS');
|
|
807
|
+
var NgxsWebsocketPluginModule = /** @class */ (function () {
|
|
808
|
+
function NgxsWebsocketPluginModule() {
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* @param {?=} options
|
|
812
|
+
* @return {?}
|
|
813
|
+
*/
|
|
814
|
+
NgxsWebsocketPluginModule.forRoot = /**
|
|
815
|
+
* @param {?=} options
|
|
816
|
+
* @return {?}
|
|
817
|
+
*/
|
|
818
|
+
function (options) {
|
|
819
|
+
return {
|
|
820
|
+
ngModule: NgxsWebsocketPluginModule,
|
|
821
|
+
providers: [
|
|
822
|
+
WebSocketHandler,
|
|
823
|
+
{
|
|
824
|
+
provide: USER_OPTIONS,
|
|
825
|
+
useValue: options
|
|
826
|
+
},
|
|
827
|
+
{
|
|
828
|
+
provide: NGXS_WEBSOCKET_OPTIONS,
|
|
829
|
+
useFactory: websocketOptionsFactory,
|
|
830
|
+
deps: [USER_OPTIONS]
|
|
831
|
+
},
|
|
832
|
+
{
|
|
833
|
+
provide: core.APP_INITIALIZER,
|
|
834
|
+
useFactory: noop,
|
|
835
|
+
deps: [WebSocketHandler],
|
|
836
|
+
multi: true
|
|
837
|
+
}
|
|
838
|
+
]
|
|
839
|
+
};
|
|
840
|
+
};
|
|
841
|
+
NgxsWebsocketPluginModule.decorators = [
|
|
842
|
+
{ type: core.NgModule }
|
|
843
|
+
];
|
|
844
|
+
return NgxsWebsocketPluginModule;
|
|
845
845
|
}());
|
|
846
846
|
|
|
847
847
|
exports.ConnectWebSocket = ConnectWebSocket;
|