@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
|
@@ -4,640 +4,640 @@ import { ofActionDispatched, getValue, Store, Actions } from '@ngxs/store';
|
|
|
4
4
|
import { Subscription } from 'rxjs';
|
|
5
5
|
import { WebSocketSubject } from 'rxjs/webSocket';
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* @fileoverview added by tsickle
|
|
9
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
10
|
-
*/
|
|
11
|
-
/** @type {?} */
|
|
12
|
-
var NGXS_WEBSOCKET_OPTIONS = new InjectionToken('NGXS_WEBSOCKET_OPTIONS');
|
|
13
|
-
/**
|
|
14
|
-
* @record
|
|
15
|
-
*/
|
|
16
|
-
function NgxsWebsocketPluginOptions() { }
|
|
17
|
-
if (false) {
|
|
18
|
-
/**
|
|
19
|
-
* URL of the websocket.
|
|
20
|
-
* @type {?|undefined}
|
|
21
|
-
*/
|
|
22
|
-
NgxsWebsocketPluginOptions.prototype.url;
|
|
23
|
-
/**
|
|
24
|
-
* Either a single protocol string or an array of protocol strings.
|
|
25
|
-
* These strings are used to indicate sub-protocols, so that a single server
|
|
26
|
-
* can implement multiple WebSocket sub-protocols (for example, you might want one server to be able
|
|
27
|
-
* to handle different types of interactions depending on the specified protocol).
|
|
28
|
-
* If you don't specify a protocol string, an empty string is assumed.
|
|
29
|
-
* @type {?|undefined}
|
|
30
|
-
*/
|
|
31
|
-
NgxsWebsocketPluginOptions.prototype.protocol;
|
|
32
|
-
/**
|
|
33
|
-
* Sets the `binaryType` property of the underlying WebSocket.
|
|
34
|
-
* @type {?|undefined}
|
|
35
|
-
*/
|
|
36
|
-
NgxsWebsocketPluginOptions.prototype.binaryType;
|
|
37
|
-
/**
|
|
38
|
-
* The property name to distigunish this type for the store.
|
|
39
|
-
* Default: 'type'
|
|
40
|
-
* @type {?|undefined}
|
|
41
|
-
*/
|
|
42
|
-
NgxsWebsocketPluginOptions.prototype.typeKey;
|
|
43
|
-
/**
|
|
44
|
-
* Interval to try and reconnect.
|
|
45
|
-
* Default: 5000
|
|
46
|
-
* @type {?|undefined}
|
|
47
|
-
*/
|
|
48
|
-
NgxsWebsocketPluginOptions.prototype.reconnectInterval;
|
|
49
|
-
/**
|
|
50
|
-
* Number of reconnect attemps.
|
|
51
|
-
* Default: 10
|
|
52
|
-
* @type {?|undefined}
|
|
53
|
-
*/
|
|
54
|
-
NgxsWebsocketPluginOptions.prototype.reconnectAttempts;
|
|
55
|
-
/**
|
|
56
|
-
* Serializer to call before sending messages
|
|
57
|
-
* Default: `json.stringify`
|
|
58
|
-
* @type {?|undefined}
|
|
59
|
-
*/
|
|
60
|
-
NgxsWebsocketPluginOptions.prototype.serializer;
|
|
61
|
-
/**
|
|
62
|
-
* Deseralizer before publishing the message.
|
|
63
|
-
* @type {?|undefined}
|
|
64
|
-
*/
|
|
65
|
-
NgxsWebsocketPluginOptions.prototype.deserializer;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* @param {...?} _args
|
|
69
|
-
* @return {?}
|
|
70
|
-
*/
|
|
71
|
-
function noop() {
|
|
72
|
-
var _args = [];
|
|
73
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
74
|
-
_args[_i] = arguments[_i];
|
|
75
|
-
}
|
|
76
|
-
return (/**
|
|
77
|
-
* @return {?}
|
|
78
|
-
*/
|
|
79
|
-
function () { });
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Action to connect to the websocket. Optionally pass a URL.
|
|
83
|
-
*/
|
|
84
|
-
var /**
|
|
85
|
-
* Action to connect to the websocket. Optionally pass a URL.
|
|
86
|
-
*/
|
|
87
|
-
ConnectWebSocket = /** @class */ (function () {
|
|
88
|
-
function ConnectWebSocket(payload) {
|
|
89
|
-
this.payload = payload;
|
|
90
|
-
}
|
|
91
|
-
Object.defineProperty(ConnectWebSocket, "type", {
|
|
92
|
-
get: /**
|
|
93
|
-
* @return {?}
|
|
94
|
-
*/
|
|
95
|
-
function () {
|
|
96
|
-
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
97
|
-
return '[WebSocket] Connect';
|
|
98
|
-
},
|
|
99
|
-
enumerable: true,
|
|
100
|
-
configurable: true
|
|
101
|
-
});
|
|
102
|
-
return ConnectWebSocket;
|
|
103
|
-
}());
|
|
104
|
-
if (false) {
|
|
105
|
-
/** @type {?} */
|
|
106
|
-
ConnectWebSocket.prototype.payload;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Action triggered when a error ocurrs
|
|
110
|
-
*/
|
|
111
|
-
var /**
|
|
112
|
-
* Action triggered when a error ocurrs
|
|
113
|
-
*/
|
|
114
|
-
WebsocketMessageError = /** @class */ (function () {
|
|
115
|
-
function WebsocketMessageError(payload) {
|
|
116
|
-
this.payload = payload;
|
|
117
|
-
}
|
|
118
|
-
Object.defineProperty(WebsocketMessageError, "type", {
|
|
119
|
-
get: /**
|
|
120
|
-
* @return {?}
|
|
121
|
-
*/
|
|
122
|
-
function () {
|
|
123
|
-
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
124
|
-
return '[WebSocket] Message Error';
|
|
125
|
-
},
|
|
126
|
-
enumerable: true,
|
|
127
|
-
configurable: true
|
|
128
|
-
});
|
|
129
|
-
return WebsocketMessageError;
|
|
130
|
-
}());
|
|
131
|
-
if (false) {
|
|
132
|
-
/** @type {?} */
|
|
133
|
-
WebsocketMessageError.prototype.payload;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Action to disconnect the websocket.
|
|
137
|
-
*/
|
|
138
|
-
var /**
|
|
139
|
-
* Action to disconnect the websocket.
|
|
140
|
-
*/
|
|
141
|
-
DisconnectWebSocket = /** @class */ (function () {
|
|
142
|
-
function DisconnectWebSocket() {
|
|
143
|
-
}
|
|
144
|
-
Object.defineProperty(DisconnectWebSocket, "type", {
|
|
145
|
-
get: /**
|
|
146
|
-
* @return {?}
|
|
147
|
-
*/
|
|
148
|
-
function () {
|
|
149
|
-
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
150
|
-
return '[WebSocket] Disconnect';
|
|
151
|
-
},
|
|
152
|
-
enumerable: true,
|
|
153
|
-
configurable: true
|
|
154
|
-
});
|
|
155
|
-
return DisconnectWebSocket;
|
|
156
|
-
}());
|
|
157
|
-
/**
|
|
158
|
-
* Action triggered when websocket is connected
|
|
159
|
-
*/
|
|
160
|
-
var /**
|
|
161
|
-
* Action triggered when websocket is connected
|
|
162
|
-
*/
|
|
163
|
-
WebSocketConnected = /** @class */ (function () {
|
|
164
|
-
function WebSocketConnected() {
|
|
165
|
-
}
|
|
166
|
-
Object.defineProperty(WebSocketConnected, "type", {
|
|
167
|
-
get: /**
|
|
168
|
-
* @return {?}
|
|
169
|
-
*/
|
|
170
|
-
function () {
|
|
171
|
-
return '[WebSocket] Connected';
|
|
172
|
-
},
|
|
173
|
-
enumerable: true,
|
|
174
|
-
configurable: true
|
|
175
|
-
});
|
|
176
|
-
return WebSocketConnected;
|
|
177
|
-
}());
|
|
178
|
-
/**
|
|
179
|
-
* Action triggered when websocket is disconnected
|
|
180
|
-
*/
|
|
181
|
-
var /**
|
|
182
|
-
* Action triggered when websocket is disconnected
|
|
183
|
-
*/
|
|
184
|
-
WebSocketDisconnected = /** @class */ (function () {
|
|
185
|
-
function WebSocketDisconnected() {
|
|
186
|
-
}
|
|
187
|
-
Object.defineProperty(WebSocketDisconnected, "type", {
|
|
188
|
-
get: /**
|
|
189
|
-
* @return {?}
|
|
190
|
-
*/
|
|
191
|
-
function () {
|
|
192
|
-
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
193
|
-
return '[WebSocket] Disconnected';
|
|
194
|
-
},
|
|
195
|
-
enumerable: true,
|
|
196
|
-
configurable: true
|
|
197
|
-
});
|
|
198
|
-
return WebSocketDisconnected;
|
|
199
|
-
}());
|
|
200
|
-
/**
|
|
201
|
-
* Action to send to the server.
|
|
202
|
-
*/
|
|
203
|
-
var /**
|
|
204
|
-
* Action to send to the server.
|
|
205
|
-
*/
|
|
206
|
-
SendWebSocketMessage = /** @class */ (function () {
|
|
207
|
-
function SendWebSocketMessage(payload) {
|
|
208
|
-
this.payload = payload;
|
|
209
|
-
}
|
|
210
|
-
Object.defineProperty(SendWebSocketMessage, "type", {
|
|
211
|
-
get: /**
|
|
212
|
-
* @return {?}
|
|
213
|
-
*/
|
|
214
|
-
function () {
|
|
215
|
-
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
216
|
-
return '[WebSocket] Send Message';
|
|
217
|
-
},
|
|
218
|
-
enumerable: true,
|
|
219
|
-
configurable: true
|
|
220
|
-
});
|
|
221
|
-
return SendWebSocketMessage;
|
|
222
|
-
}());
|
|
223
|
-
if (false) {
|
|
224
|
-
/** @type {?} */
|
|
225
|
-
SendWebSocketMessage.prototype.payload;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Action dispatched when the user tries to connect if the connection already exists.
|
|
229
|
-
*/
|
|
230
|
-
var /**
|
|
231
|
-
* Action dispatched when the user tries to connect if the connection already exists.
|
|
232
|
-
*/
|
|
233
|
-
WebSocketConnectionUpdated = /** @class */ (function () {
|
|
234
|
-
function WebSocketConnectionUpdated() {
|
|
235
|
-
}
|
|
236
|
-
Object.defineProperty(WebSocketConnectionUpdated, "type", {
|
|
237
|
-
get: /**
|
|
238
|
-
* @return {?}
|
|
239
|
-
*/
|
|
240
|
-
function () {
|
|
241
|
-
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
242
|
-
return '[WebSocket] Connection Updated';
|
|
243
|
-
},
|
|
244
|
-
enumerable: true,
|
|
245
|
-
configurable: true
|
|
246
|
-
});
|
|
247
|
-
return WebSocketConnectionUpdated;
|
|
248
|
-
}());
|
|
249
|
-
/**
|
|
250
|
-
* This error is thrown where there is no `type` (or custom `typeKey`) property
|
|
251
|
-
* on the message that came from the server side socket
|
|
252
|
-
*/
|
|
253
|
-
var /**
|
|
254
|
-
* This error is thrown where there is no `type` (or custom `typeKey`) property
|
|
255
|
-
* on the message that came from the server side socket
|
|
256
|
-
*/
|
|
257
|
-
TypeKeyPropertyMissingError = /** @class */ (function (_super) {
|
|
258
|
-
__extends(TypeKeyPropertyMissingError, _super);
|
|
259
|
-
function TypeKeyPropertyMissingError(typeKey) {
|
|
260
|
-
return _super.call(this, "Property " + typeKey + " is missing on the socket message") || this;
|
|
261
|
-
}
|
|
262
|
-
return TypeKeyPropertyMissingError;
|
|
7
|
+
/**
|
|
8
|
+
* @fileoverview added by tsickle
|
|
9
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
10
|
+
*/
|
|
11
|
+
/** @type {?} */
|
|
12
|
+
var NGXS_WEBSOCKET_OPTIONS = new InjectionToken('NGXS_WEBSOCKET_OPTIONS');
|
|
13
|
+
/**
|
|
14
|
+
* @record
|
|
15
|
+
*/
|
|
16
|
+
function NgxsWebsocketPluginOptions() { }
|
|
17
|
+
if (false) {
|
|
18
|
+
/**
|
|
19
|
+
* URL of the websocket.
|
|
20
|
+
* @type {?|undefined}
|
|
21
|
+
*/
|
|
22
|
+
NgxsWebsocketPluginOptions.prototype.url;
|
|
23
|
+
/**
|
|
24
|
+
* Either a single protocol string or an array of protocol strings.
|
|
25
|
+
* These strings are used to indicate sub-protocols, so that a single server
|
|
26
|
+
* can implement multiple WebSocket sub-protocols (for example, you might want one server to be able
|
|
27
|
+
* to handle different types of interactions depending on the specified protocol).
|
|
28
|
+
* If you don't specify a protocol string, an empty string is assumed.
|
|
29
|
+
* @type {?|undefined}
|
|
30
|
+
*/
|
|
31
|
+
NgxsWebsocketPluginOptions.prototype.protocol;
|
|
32
|
+
/**
|
|
33
|
+
* Sets the `binaryType` property of the underlying WebSocket.
|
|
34
|
+
* @type {?|undefined}
|
|
35
|
+
*/
|
|
36
|
+
NgxsWebsocketPluginOptions.prototype.binaryType;
|
|
37
|
+
/**
|
|
38
|
+
* The property name to distigunish this type for the store.
|
|
39
|
+
* Default: 'type'
|
|
40
|
+
* @type {?|undefined}
|
|
41
|
+
*/
|
|
42
|
+
NgxsWebsocketPluginOptions.prototype.typeKey;
|
|
43
|
+
/**
|
|
44
|
+
* Interval to try and reconnect.
|
|
45
|
+
* Default: 5000
|
|
46
|
+
* @type {?|undefined}
|
|
47
|
+
*/
|
|
48
|
+
NgxsWebsocketPluginOptions.prototype.reconnectInterval;
|
|
49
|
+
/**
|
|
50
|
+
* Number of reconnect attemps.
|
|
51
|
+
* Default: 10
|
|
52
|
+
* @type {?|undefined}
|
|
53
|
+
*/
|
|
54
|
+
NgxsWebsocketPluginOptions.prototype.reconnectAttempts;
|
|
55
|
+
/**
|
|
56
|
+
* Serializer to call before sending messages
|
|
57
|
+
* Default: `json.stringify`
|
|
58
|
+
* @type {?|undefined}
|
|
59
|
+
*/
|
|
60
|
+
NgxsWebsocketPluginOptions.prototype.serializer;
|
|
61
|
+
/**
|
|
62
|
+
* Deseralizer before publishing the message.
|
|
63
|
+
* @type {?|undefined}
|
|
64
|
+
*/
|
|
65
|
+
NgxsWebsocketPluginOptions.prototype.deserializer;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* @param {...?} _args
|
|
69
|
+
* @return {?}
|
|
70
|
+
*/
|
|
71
|
+
function noop() {
|
|
72
|
+
var _args = [];
|
|
73
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
74
|
+
_args[_i] = arguments[_i];
|
|
75
|
+
}
|
|
76
|
+
return (/**
|
|
77
|
+
* @return {?}
|
|
78
|
+
*/
|
|
79
|
+
function () { });
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Action to connect to the websocket. Optionally pass a URL.
|
|
83
|
+
*/
|
|
84
|
+
var /**
|
|
85
|
+
* Action to connect to the websocket. Optionally pass a URL.
|
|
86
|
+
*/
|
|
87
|
+
ConnectWebSocket = /** @class */ (function () {
|
|
88
|
+
function ConnectWebSocket(payload) {
|
|
89
|
+
this.payload = payload;
|
|
90
|
+
}
|
|
91
|
+
Object.defineProperty(ConnectWebSocket, "type", {
|
|
92
|
+
get: /**
|
|
93
|
+
* @return {?}
|
|
94
|
+
*/
|
|
95
|
+
function () {
|
|
96
|
+
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
97
|
+
return '[WebSocket] Connect';
|
|
98
|
+
},
|
|
99
|
+
enumerable: true,
|
|
100
|
+
configurable: true
|
|
101
|
+
});
|
|
102
|
+
return ConnectWebSocket;
|
|
103
|
+
}());
|
|
104
|
+
if (false) {
|
|
105
|
+
/** @type {?} */
|
|
106
|
+
ConnectWebSocket.prototype.payload;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Action triggered when a error ocurrs
|
|
110
|
+
*/
|
|
111
|
+
var /**
|
|
112
|
+
* Action triggered when a error ocurrs
|
|
113
|
+
*/
|
|
114
|
+
WebsocketMessageError = /** @class */ (function () {
|
|
115
|
+
function WebsocketMessageError(payload) {
|
|
116
|
+
this.payload = payload;
|
|
117
|
+
}
|
|
118
|
+
Object.defineProperty(WebsocketMessageError, "type", {
|
|
119
|
+
get: /**
|
|
120
|
+
* @return {?}
|
|
121
|
+
*/
|
|
122
|
+
function () {
|
|
123
|
+
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
124
|
+
return '[WebSocket] Message Error';
|
|
125
|
+
},
|
|
126
|
+
enumerable: true,
|
|
127
|
+
configurable: true
|
|
128
|
+
});
|
|
129
|
+
return WebsocketMessageError;
|
|
130
|
+
}());
|
|
131
|
+
if (false) {
|
|
132
|
+
/** @type {?} */
|
|
133
|
+
WebsocketMessageError.prototype.payload;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Action to disconnect the websocket.
|
|
137
|
+
*/
|
|
138
|
+
var /**
|
|
139
|
+
* Action to disconnect the websocket.
|
|
140
|
+
*/
|
|
141
|
+
DisconnectWebSocket = /** @class */ (function () {
|
|
142
|
+
function DisconnectWebSocket() {
|
|
143
|
+
}
|
|
144
|
+
Object.defineProperty(DisconnectWebSocket, "type", {
|
|
145
|
+
get: /**
|
|
146
|
+
* @return {?}
|
|
147
|
+
*/
|
|
148
|
+
function () {
|
|
149
|
+
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
150
|
+
return '[WebSocket] Disconnect';
|
|
151
|
+
},
|
|
152
|
+
enumerable: true,
|
|
153
|
+
configurable: true
|
|
154
|
+
});
|
|
155
|
+
return DisconnectWebSocket;
|
|
156
|
+
}());
|
|
157
|
+
/**
|
|
158
|
+
* Action triggered when websocket is connected
|
|
159
|
+
*/
|
|
160
|
+
var /**
|
|
161
|
+
* Action triggered when websocket is connected
|
|
162
|
+
*/
|
|
163
|
+
WebSocketConnected = /** @class */ (function () {
|
|
164
|
+
function WebSocketConnected() {
|
|
165
|
+
}
|
|
166
|
+
Object.defineProperty(WebSocketConnected, "type", {
|
|
167
|
+
get: /**
|
|
168
|
+
* @return {?}
|
|
169
|
+
*/
|
|
170
|
+
function () {
|
|
171
|
+
return '[WebSocket] Connected';
|
|
172
|
+
},
|
|
173
|
+
enumerable: true,
|
|
174
|
+
configurable: true
|
|
175
|
+
});
|
|
176
|
+
return WebSocketConnected;
|
|
177
|
+
}());
|
|
178
|
+
/**
|
|
179
|
+
* Action triggered when websocket is disconnected
|
|
180
|
+
*/
|
|
181
|
+
var /**
|
|
182
|
+
* Action triggered when websocket is disconnected
|
|
183
|
+
*/
|
|
184
|
+
WebSocketDisconnected = /** @class */ (function () {
|
|
185
|
+
function WebSocketDisconnected() {
|
|
186
|
+
}
|
|
187
|
+
Object.defineProperty(WebSocketDisconnected, "type", {
|
|
188
|
+
get: /**
|
|
189
|
+
* @return {?}
|
|
190
|
+
*/
|
|
191
|
+
function () {
|
|
192
|
+
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
193
|
+
return '[WebSocket] Disconnected';
|
|
194
|
+
},
|
|
195
|
+
enumerable: true,
|
|
196
|
+
configurable: true
|
|
197
|
+
});
|
|
198
|
+
return WebSocketDisconnected;
|
|
199
|
+
}());
|
|
200
|
+
/**
|
|
201
|
+
* Action to send to the server.
|
|
202
|
+
*/
|
|
203
|
+
var /**
|
|
204
|
+
* Action to send to the server.
|
|
205
|
+
*/
|
|
206
|
+
SendWebSocketMessage = /** @class */ (function () {
|
|
207
|
+
function SendWebSocketMessage(payload) {
|
|
208
|
+
this.payload = payload;
|
|
209
|
+
}
|
|
210
|
+
Object.defineProperty(SendWebSocketMessage, "type", {
|
|
211
|
+
get: /**
|
|
212
|
+
* @return {?}
|
|
213
|
+
*/
|
|
214
|
+
function () {
|
|
215
|
+
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
216
|
+
return '[WebSocket] Send Message';
|
|
217
|
+
},
|
|
218
|
+
enumerable: true,
|
|
219
|
+
configurable: true
|
|
220
|
+
});
|
|
221
|
+
return SendWebSocketMessage;
|
|
222
|
+
}());
|
|
223
|
+
if (false) {
|
|
224
|
+
/** @type {?} */
|
|
225
|
+
SendWebSocketMessage.prototype.payload;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Action dispatched when the user tries to connect if the connection already exists.
|
|
229
|
+
*/
|
|
230
|
+
var /**
|
|
231
|
+
* Action dispatched when the user tries to connect if the connection already exists.
|
|
232
|
+
*/
|
|
233
|
+
WebSocketConnectionUpdated = /** @class */ (function () {
|
|
234
|
+
function WebSocketConnectionUpdated() {
|
|
235
|
+
}
|
|
236
|
+
Object.defineProperty(WebSocketConnectionUpdated, "type", {
|
|
237
|
+
get: /**
|
|
238
|
+
* @return {?}
|
|
239
|
+
*/
|
|
240
|
+
function () {
|
|
241
|
+
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
242
|
+
return '[WebSocket] Connection Updated';
|
|
243
|
+
},
|
|
244
|
+
enumerable: true,
|
|
245
|
+
configurable: true
|
|
246
|
+
});
|
|
247
|
+
return WebSocketConnectionUpdated;
|
|
248
|
+
}());
|
|
249
|
+
/**
|
|
250
|
+
* This error is thrown where there is no `type` (or custom `typeKey`) property
|
|
251
|
+
* on the message that came from the server side socket
|
|
252
|
+
*/
|
|
253
|
+
var /**
|
|
254
|
+
* This error is thrown where there is no `type` (or custom `typeKey`) property
|
|
255
|
+
* on the message that came from the server side socket
|
|
256
|
+
*/
|
|
257
|
+
TypeKeyPropertyMissingError = /** @class */ (function (_super) {
|
|
258
|
+
__extends(TypeKeyPropertyMissingError, _super);
|
|
259
|
+
function TypeKeyPropertyMissingError(typeKey) {
|
|
260
|
+
return _super.call(this, "Property " + typeKey + " is missing on the socket message") || this;
|
|
261
|
+
}
|
|
262
|
+
return TypeKeyPropertyMissingError;
|
|
263
263
|
}(Error));
|
|
264
264
|
|
|
265
|
-
/**
|
|
266
|
-
* @fileoverview added by tsickle
|
|
267
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
268
|
-
*/
|
|
269
|
-
var WebSocketHandler = /** @class */ (function () {
|
|
270
|
-
function WebSocketHandler(store, actions$, options) {
|
|
271
|
-
var _this = this;
|
|
272
|
-
this.store = store;
|
|
273
|
-
this.actions$ = actions$;
|
|
274
|
-
this.options = options;
|
|
275
|
-
this.socket = null;
|
|
276
|
-
this.config = {
|
|
277
|
-
url: (/** @type {?} */ (this.options.url)),
|
|
278
|
-
protocol: this.options.protocol,
|
|
279
|
-
// Default binary type is `blob` for the global `WebSocket`
|
|
280
|
-
binaryType: this.options.binaryType,
|
|
281
|
-
serializer: this.options.serializer,
|
|
282
|
-
deserializer: this.options.deserializer,
|
|
283
|
-
closeObserver: {
|
|
284
|
-
next: (/**
|
|
285
|
-
* @return {?}
|
|
286
|
-
*/
|
|
287
|
-
function () {
|
|
288
|
-
// ATTENTION!
|
|
289
|
-
// See https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/dom/WebSocketSubject.ts#L340
|
|
290
|
-
// RxJS socket emits `onComplete` event only if `event.wasClean` is truthy
|
|
291
|
-
// and doesn't complete socket subject if it's falsy
|
|
292
|
-
_this.disconnect();
|
|
293
|
-
})
|
|
294
|
-
},
|
|
295
|
-
openObserver: {
|
|
296
|
-
next: (/**
|
|
297
|
-
* @return {?}
|
|
298
|
-
*/
|
|
299
|
-
function () { return _this.store.dispatch(new WebSocketConnected()); })
|
|
300
|
-
}
|
|
301
|
-
};
|
|
302
|
-
this.typeKey = (/** @type {?} */ (this.options.typeKey));
|
|
303
|
-
this.subscription = new Subscription();
|
|
304
|
-
this.setupActionsListeners();
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* @return {?}
|
|
308
|
-
*/
|
|
309
|
-
WebSocketHandler.prototype.ngOnDestroy = /**
|
|
310
|
-
* @return {?}
|
|
311
|
-
*/
|
|
312
|
-
function () {
|
|
313
|
-
this.closeConnection();
|
|
314
|
-
this.subscription.unsubscribe();
|
|
315
|
-
};
|
|
316
|
-
/**
|
|
317
|
-
* @private
|
|
318
|
-
* @return {?}
|
|
319
|
-
*/
|
|
320
|
-
WebSocketHandler.prototype.setupActionsListeners = /**
|
|
321
|
-
* @private
|
|
322
|
-
* @return {?}
|
|
323
|
-
*/
|
|
324
|
-
function () {
|
|
325
|
-
var _this = this;
|
|
326
|
-
this.subscription.add(this.actions$.pipe(ofActionDispatched(ConnectWebSocket)).subscribe((/**
|
|
327
|
-
* @param {?} __0
|
|
328
|
-
* @return {?}
|
|
329
|
-
*/
|
|
330
|
-
function (_a) {
|
|
331
|
-
var payload = _a.payload;
|
|
332
|
-
_this.connect(payload);
|
|
333
|
-
})));
|
|
334
|
-
this.subscription.add(this.actions$.pipe(ofActionDispatched(DisconnectWebSocket)).subscribe((/**
|
|
335
|
-
* @return {?}
|
|
336
|
-
*/
|
|
337
|
-
function () {
|
|
338
|
-
_this.disconnect();
|
|
339
|
-
})));
|
|
340
|
-
this.subscription.add(this.actions$.pipe(ofActionDispatched(SendWebSocketMessage)).subscribe((/**
|
|
341
|
-
* @param {?} __0
|
|
342
|
-
* @return {?}
|
|
343
|
-
*/
|
|
344
|
-
function (_a) {
|
|
345
|
-
var payload = _a.payload;
|
|
346
|
-
_this.send(payload);
|
|
347
|
-
})));
|
|
348
|
-
};
|
|
349
|
-
/**
|
|
350
|
-
* @private
|
|
351
|
-
* @param {?=} options
|
|
352
|
-
* @return {?}
|
|
353
|
-
*/
|
|
354
|
-
WebSocketHandler.prototype.connect = /**
|
|
355
|
-
* @private
|
|
356
|
-
* @param {?=} options
|
|
357
|
-
* @return {?}
|
|
358
|
-
*/
|
|
359
|
-
function (options) {
|
|
360
|
-
var _this = this;
|
|
361
|
-
this.updateConnection();
|
|
362
|
-
// Users can pass the options in the connect method so
|
|
363
|
-
// if options aren't available at DI bootstrap they have access
|
|
364
|
-
// to pass them here
|
|
365
|
-
if (options) {
|
|
366
|
-
this.mergeConfigWithOptions(options);
|
|
367
|
-
}
|
|
368
|
-
this.socket = new WebSocketSubject(this.config);
|
|
369
|
-
this.socket.subscribe({
|
|
370
|
-
next: (/**
|
|
371
|
-
* @param {?} message
|
|
372
|
-
* @return {?}
|
|
373
|
-
*/
|
|
374
|
-
function (message) {
|
|
375
|
-
/** @type {?} */
|
|
376
|
-
var type = getValue(message, _this.typeKey);
|
|
377
|
-
if (!type) {
|
|
378
|
-
throw new TypeKeyPropertyMissingError(_this.typeKey);
|
|
379
|
-
}
|
|
380
|
-
_this.store.dispatch(__assign({}, message, { type: type }));
|
|
381
|
-
}),
|
|
382
|
-
error: (/**
|
|
383
|
-
* @param {?} error
|
|
384
|
-
* @return {?}
|
|
385
|
-
*/
|
|
386
|
-
function (error) {
|
|
387
|
-
if (error instanceof CloseEvent) {
|
|
388
|
-
_this.dispatchWebSocketDisconnected();
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
_this.store.dispatch(new WebsocketMessageError(error));
|
|
392
|
-
}
|
|
393
|
-
})
|
|
394
|
-
});
|
|
395
|
-
};
|
|
396
|
-
/**
|
|
397
|
-
* @private
|
|
398
|
-
* @return {?}
|
|
399
|
-
*/
|
|
400
|
-
WebSocketHandler.prototype.disconnect = /**
|
|
401
|
-
* @private
|
|
402
|
-
* @return {?}
|
|
403
|
-
*/
|
|
404
|
-
function () {
|
|
405
|
-
if (this.socket) {
|
|
406
|
-
this.closeConnection();
|
|
407
|
-
this.dispatchWebSocketDisconnected();
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
/**
|
|
411
|
-
* @private
|
|
412
|
-
* @param {?} data
|
|
413
|
-
* @return {?}
|
|
414
|
-
*/
|
|
415
|
-
WebSocketHandler.prototype.send = /**
|
|
416
|
-
* @private
|
|
417
|
-
* @param {?} data
|
|
418
|
-
* @return {?}
|
|
419
|
-
*/
|
|
420
|
-
function (data) {
|
|
421
|
-
if (!this.socket) {
|
|
422
|
-
throw new Error('You must connect to the socket before sending any data');
|
|
423
|
-
}
|
|
424
|
-
this.socket.next(data);
|
|
425
|
-
};
|
|
426
|
-
/**
|
|
427
|
-
* Don't enlarge the `connect` method
|
|
428
|
-
*/
|
|
429
|
-
/**
|
|
430
|
-
* Don't enlarge the `connect` method
|
|
431
|
-
* @private
|
|
432
|
-
* @param {?} options
|
|
433
|
-
* @return {?}
|
|
434
|
-
*/
|
|
435
|
-
WebSocketHandler.prototype.mergeConfigWithOptions = /**
|
|
436
|
-
* Don't enlarge the `connect` method
|
|
437
|
-
* @private
|
|
438
|
-
* @param {?} options
|
|
439
|
-
* @return {?}
|
|
440
|
-
*/
|
|
441
|
-
function (options) {
|
|
442
|
-
if (options.url) {
|
|
443
|
-
this.config.url = options.url;
|
|
444
|
-
}
|
|
445
|
-
if (options.serializer) {
|
|
446
|
-
this.config.serializer = options.serializer;
|
|
447
|
-
}
|
|
448
|
-
if (options.deserializer) {
|
|
449
|
-
this.config.deserializer = options.deserializer;
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
/**
|
|
453
|
-
* To ensure we don't have any memory leaks
|
|
454
|
-
* e.g. if the user occasionally dispatched `ConnectWebSocket` twice
|
|
455
|
-
* then the previous subscription will still live in the memory
|
|
456
|
-
* to prevent such behavior - we close the previous connection if it exists
|
|
457
|
-
*/
|
|
458
|
-
/**
|
|
459
|
-
* To ensure we don't have any memory leaks
|
|
460
|
-
* e.g. if the user occasionally dispatched `ConnectWebSocket` twice
|
|
461
|
-
* then the previous subscription will still live in the memory
|
|
462
|
-
* to prevent such behavior - we close the previous connection if it exists
|
|
463
|
-
* @private
|
|
464
|
-
* @return {?}
|
|
465
|
-
*/
|
|
466
|
-
WebSocketHandler.prototype.updateConnection = /**
|
|
467
|
-
* To ensure we don't have any memory leaks
|
|
468
|
-
* e.g. if the user occasionally dispatched `ConnectWebSocket` twice
|
|
469
|
-
* then the previous subscription will still live in the memory
|
|
470
|
-
* to prevent such behavior - we close the previous connection if it exists
|
|
471
|
-
* @private
|
|
472
|
-
* @return {?}
|
|
473
|
-
*/
|
|
474
|
-
function () {
|
|
475
|
-
if (this.socket) {
|
|
476
|
-
this.closeConnection();
|
|
477
|
-
this.store.dispatch(new WebSocketConnectionUpdated());
|
|
478
|
-
}
|
|
479
|
-
};
|
|
480
|
-
/**
|
|
481
|
-
* Used in many places so it's better to move the code into function
|
|
482
|
-
*/
|
|
483
|
-
/**
|
|
484
|
-
* Used in many places so it's better to move the code into function
|
|
485
|
-
* @private
|
|
486
|
-
* @return {?}
|
|
487
|
-
*/
|
|
488
|
-
WebSocketHandler.prototype.dispatchWebSocketDisconnected = /**
|
|
489
|
-
* Used in many places so it's better to move the code into function
|
|
490
|
-
* @private
|
|
491
|
-
* @return {?}
|
|
492
|
-
*/
|
|
493
|
-
function () {
|
|
494
|
-
this.store.dispatch(new WebSocketDisconnected());
|
|
495
|
-
};
|
|
496
|
-
/**
|
|
497
|
-
* @private
|
|
498
|
-
* @return {?}
|
|
499
|
-
*/
|
|
500
|
-
WebSocketHandler.prototype.closeConnection = /**
|
|
501
|
-
* @private
|
|
502
|
-
* @return {?}
|
|
503
|
-
*/
|
|
504
|
-
function () {
|
|
505
|
-
// `socket.complete()` closes the connection
|
|
506
|
-
// also it doesn't invoke the `onComplete` callback that we passed
|
|
507
|
-
// into `socket.subscribe(...)`
|
|
508
|
-
if (this.socket !== null) {
|
|
509
|
-
this.socket.complete();
|
|
510
|
-
this.socket = null;
|
|
511
|
-
}
|
|
512
|
-
};
|
|
513
|
-
WebSocketHandler.decorators = [
|
|
514
|
-
{ type: Injectable }
|
|
515
|
-
];
|
|
516
|
-
/** @nocollapse */
|
|
517
|
-
WebSocketHandler.ctorParameters = function () { return [
|
|
518
|
-
{ type: Store },
|
|
519
|
-
{ type: Actions },
|
|
520
|
-
{ type: undefined, decorators: [{ type: Inject, args: [NGXS_WEBSOCKET_OPTIONS,] }] }
|
|
521
|
-
]; };
|
|
522
|
-
return WebSocketHandler;
|
|
523
|
-
}());
|
|
524
|
-
if (false) {
|
|
525
|
-
/**
|
|
526
|
-
* @type {?}
|
|
527
|
-
* @private
|
|
528
|
-
*/
|
|
529
|
-
WebSocketHandler.prototype.socket;
|
|
530
|
-
/**
|
|
531
|
-
* @type {?}
|
|
532
|
-
* @private
|
|
533
|
-
*/
|
|
534
|
-
WebSocketHandler.prototype.config;
|
|
535
|
-
/**
|
|
536
|
-
* @type {?}
|
|
537
|
-
* @private
|
|
538
|
-
*/
|
|
539
|
-
WebSocketHandler.prototype.typeKey;
|
|
540
|
-
/**
|
|
541
|
-
* @type {?}
|
|
542
|
-
* @private
|
|
543
|
-
*/
|
|
544
|
-
WebSocketHandler.prototype.subscription;
|
|
545
|
-
/**
|
|
546
|
-
* @type {?}
|
|
547
|
-
* @private
|
|
548
|
-
*/
|
|
549
|
-
WebSocketHandler.prototype.store;
|
|
550
|
-
/**
|
|
551
|
-
* @type {?}
|
|
552
|
-
* @private
|
|
553
|
-
*/
|
|
554
|
-
WebSocketHandler.prototype.actions$;
|
|
555
|
-
/**
|
|
556
|
-
* @type {?}
|
|
557
|
-
* @private
|
|
558
|
-
*/
|
|
559
|
-
WebSocketHandler.prototype.options;
|
|
265
|
+
/**
|
|
266
|
+
* @fileoverview added by tsickle
|
|
267
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
268
|
+
*/
|
|
269
|
+
var WebSocketHandler = /** @class */ (function () {
|
|
270
|
+
function WebSocketHandler(store, actions$, options) {
|
|
271
|
+
var _this = this;
|
|
272
|
+
this.store = store;
|
|
273
|
+
this.actions$ = actions$;
|
|
274
|
+
this.options = options;
|
|
275
|
+
this.socket = null;
|
|
276
|
+
this.config = {
|
|
277
|
+
url: (/** @type {?} */ (this.options.url)),
|
|
278
|
+
protocol: this.options.protocol,
|
|
279
|
+
// Default binary type is `blob` for the global `WebSocket`
|
|
280
|
+
binaryType: this.options.binaryType,
|
|
281
|
+
serializer: this.options.serializer,
|
|
282
|
+
deserializer: this.options.deserializer,
|
|
283
|
+
closeObserver: {
|
|
284
|
+
next: (/**
|
|
285
|
+
* @return {?}
|
|
286
|
+
*/
|
|
287
|
+
function () {
|
|
288
|
+
// ATTENTION!
|
|
289
|
+
// See https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/dom/WebSocketSubject.ts#L340
|
|
290
|
+
// RxJS socket emits `onComplete` event only if `event.wasClean` is truthy
|
|
291
|
+
// and doesn't complete socket subject if it's falsy
|
|
292
|
+
_this.disconnect();
|
|
293
|
+
})
|
|
294
|
+
},
|
|
295
|
+
openObserver: {
|
|
296
|
+
next: (/**
|
|
297
|
+
* @return {?}
|
|
298
|
+
*/
|
|
299
|
+
function () { return _this.store.dispatch(new WebSocketConnected()); })
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
this.typeKey = (/** @type {?} */ (this.options.typeKey));
|
|
303
|
+
this.subscription = new Subscription();
|
|
304
|
+
this.setupActionsListeners();
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* @return {?}
|
|
308
|
+
*/
|
|
309
|
+
WebSocketHandler.prototype.ngOnDestroy = /**
|
|
310
|
+
* @return {?}
|
|
311
|
+
*/
|
|
312
|
+
function () {
|
|
313
|
+
this.closeConnection();
|
|
314
|
+
this.subscription.unsubscribe();
|
|
315
|
+
};
|
|
316
|
+
/**
|
|
317
|
+
* @private
|
|
318
|
+
* @return {?}
|
|
319
|
+
*/
|
|
320
|
+
WebSocketHandler.prototype.setupActionsListeners = /**
|
|
321
|
+
* @private
|
|
322
|
+
* @return {?}
|
|
323
|
+
*/
|
|
324
|
+
function () {
|
|
325
|
+
var _this = this;
|
|
326
|
+
this.subscription.add(this.actions$.pipe(ofActionDispatched(ConnectWebSocket)).subscribe((/**
|
|
327
|
+
* @param {?} __0
|
|
328
|
+
* @return {?}
|
|
329
|
+
*/
|
|
330
|
+
function (_a) {
|
|
331
|
+
var payload = _a.payload;
|
|
332
|
+
_this.connect(payload);
|
|
333
|
+
})));
|
|
334
|
+
this.subscription.add(this.actions$.pipe(ofActionDispatched(DisconnectWebSocket)).subscribe((/**
|
|
335
|
+
* @return {?}
|
|
336
|
+
*/
|
|
337
|
+
function () {
|
|
338
|
+
_this.disconnect();
|
|
339
|
+
})));
|
|
340
|
+
this.subscription.add(this.actions$.pipe(ofActionDispatched(SendWebSocketMessage)).subscribe((/**
|
|
341
|
+
* @param {?} __0
|
|
342
|
+
* @return {?}
|
|
343
|
+
*/
|
|
344
|
+
function (_a) {
|
|
345
|
+
var payload = _a.payload;
|
|
346
|
+
_this.send(payload);
|
|
347
|
+
})));
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* @private
|
|
351
|
+
* @param {?=} options
|
|
352
|
+
* @return {?}
|
|
353
|
+
*/
|
|
354
|
+
WebSocketHandler.prototype.connect = /**
|
|
355
|
+
* @private
|
|
356
|
+
* @param {?=} options
|
|
357
|
+
* @return {?}
|
|
358
|
+
*/
|
|
359
|
+
function (options) {
|
|
360
|
+
var _this = this;
|
|
361
|
+
this.updateConnection();
|
|
362
|
+
// Users can pass the options in the connect method so
|
|
363
|
+
// if options aren't available at DI bootstrap they have access
|
|
364
|
+
// to pass them here
|
|
365
|
+
if (options) {
|
|
366
|
+
this.mergeConfigWithOptions(options);
|
|
367
|
+
}
|
|
368
|
+
this.socket = new WebSocketSubject(this.config);
|
|
369
|
+
this.socket.subscribe({
|
|
370
|
+
next: (/**
|
|
371
|
+
* @param {?} message
|
|
372
|
+
* @return {?}
|
|
373
|
+
*/
|
|
374
|
+
function (message) {
|
|
375
|
+
/** @type {?} */
|
|
376
|
+
var type = getValue(message, _this.typeKey);
|
|
377
|
+
if (!type) {
|
|
378
|
+
throw new TypeKeyPropertyMissingError(_this.typeKey);
|
|
379
|
+
}
|
|
380
|
+
_this.store.dispatch(__assign({}, message, { type: type }));
|
|
381
|
+
}),
|
|
382
|
+
error: (/**
|
|
383
|
+
* @param {?} error
|
|
384
|
+
* @return {?}
|
|
385
|
+
*/
|
|
386
|
+
function (error) {
|
|
387
|
+
if (error instanceof CloseEvent) {
|
|
388
|
+
_this.dispatchWebSocketDisconnected();
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
_this.store.dispatch(new WebsocketMessageError(error));
|
|
392
|
+
}
|
|
393
|
+
})
|
|
394
|
+
});
|
|
395
|
+
};
|
|
396
|
+
/**
|
|
397
|
+
* @private
|
|
398
|
+
* @return {?}
|
|
399
|
+
*/
|
|
400
|
+
WebSocketHandler.prototype.disconnect = /**
|
|
401
|
+
* @private
|
|
402
|
+
* @return {?}
|
|
403
|
+
*/
|
|
404
|
+
function () {
|
|
405
|
+
if (this.socket) {
|
|
406
|
+
this.closeConnection();
|
|
407
|
+
this.dispatchWebSocketDisconnected();
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
/**
|
|
411
|
+
* @private
|
|
412
|
+
* @param {?} data
|
|
413
|
+
* @return {?}
|
|
414
|
+
*/
|
|
415
|
+
WebSocketHandler.prototype.send = /**
|
|
416
|
+
* @private
|
|
417
|
+
* @param {?} data
|
|
418
|
+
* @return {?}
|
|
419
|
+
*/
|
|
420
|
+
function (data) {
|
|
421
|
+
if (!this.socket) {
|
|
422
|
+
throw new Error('You must connect to the socket before sending any data');
|
|
423
|
+
}
|
|
424
|
+
this.socket.next(data);
|
|
425
|
+
};
|
|
426
|
+
/**
|
|
427
|
+
* Don't enlarge the `connect` method
|
|
428
|
+
*/
|
|
429
|
+
/**
|
|
430
|
+
* Don't enlarge the `connect` method
|
|
431
|
+
* @private
|
|
432
|
+
* @param {?} options
|
|
433
|
+
* @return {?}
|
|
434
|
+
*/
|
|
435
|
+
WebSocketHandler.prototype.mergeConfigWithOptions = /**
|
|
436
|
+
* Don't enlarge the `connect` method
|
|
437
|
+
* @private
|
|
438
|
+
* @param {?} options
|
|
439
|
+
* @return {?}
|
|
440
|
+
*/
|
|
441
|
+
function (options) {
|
|
442
|
+
if (options.url) {
|
|
443
|
+
this.config.url = options.url;
|
|
444
|
+
}
|
|
445
|
+
if (options.serializer) {
|
|
446
|
+
this.config.serializer = options.serializer;
|
|
447
|
+
}
|
|
448
|
+
if (options.deserializer) {
|
|
449
|
+
this.config.deserializer = options.deserializer;
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
/**
|
|
453
|
+
* To ensure we don't have any memory leaks
|
|
454
|
+
* e.g. if the user occasionally dispatched `ConnectWebSocket` twice
|
|
455
|
+
* then the previous subscription will still live in the memory
|
|
456
|
+
* to prevent such behavior - we close the previous connection if it exists
|
|
457
|
+
*/
|
|
458
|
+
/**
|
|
459
|
+
* To ensure we don't have any memory leaks
|
|
460
|
+
* e.g. if the user occasionally dispatched `ConnectWebSocket` twice
|
|
461
|
+
* then the previous subscription will still live in the memory
|
|
462
|
+
* to prevent such behavior - we close the previous connection if it exists
|
|
463
|
+
* @private
|
|
464
|
+
* @return {?}
|
|
465
|
+
*/
|
|
466
|
+
WebSocketHandler.prototype.updateConnection = /**
|
|
467
|
+
* To ensure we don't have any memory leaks
|
|
468
|
+
* e.g. if the user occasionally dispatched `ConnectWebSocket` twice
|
|
469
|
+
* then the previous subscription will still live in the memory
|
|
470
|
+
* to prevent such behavior - we close the previous connection if it exists
|
|
471
|
+
* @private
|
|
472
|
+
* @return {?}
|
|
473
|
+
*/
|
|
474
|
+
function () {
|
|
475
|
+
if (this.socket) {
|
|
476
|
+
this.closeConnection();
|
|
477
|
+
this.store.dispatch(new WebSocketConnectionUpdated());
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
/**
|
|
481
|
+
* Used in many places so it's better to move the code into function
|
|
482
|
+
*/
|
|
483
|
+
/**
|
|
484
|
+
* Used in many places so it's better to move the code into function
|
|
485
|
+
* @private
|
|
486
|
+
* @return {?}
|
|
487
|
+
*/
|
|
488
|
+
WebSocketHandler.prototype.dispatchWebSocketDisconnected = /**
|
|
489
|
+
* Used in many places so it's better to move the code into function
|
|
490
|
+
* @private
|
|
491
|
+
* @return {?}
|
|
492
|
+
*/
|
|
493
|
+
function () {
|
|
494
|
+
this.store.dispatch(new WebSocketDisconnected());
|
|
495
|
+
};
|
|
496
|
+
/**
|
|
497
|
+
* @private
|
|
498
|
+
* @return {?}
|
|
499
|
+
*/
|
|
500
|
+
WebSocketHandler.prototype.closeConnection = /**
|
|
501
|
+
* @private
|
|
502
|
+
* @return {?}
|
|
503
|
+
*/
|
|
504
|
+
function () {
|
|
505
|
+
// `socket.complete()` closes the connection
|
|
506
|
+
// also it doesn't invoke the `onComplete` callback that we passed
|
|
507
|
+
// into `socket.subscribe(...)`
|
|
508
|
+
if (this.socket !== null) {
|
|
509
|
+
this.socket.complete();
|
|
510
|
+
this.socket = null;
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
WebSocketHandler.decorators = [
|
|
514
|
+
{ type: Injectable }
|
|
515
|
+
];
|
|
516
|
+
/** @nocollapse */
|
|
517
|
+
WebSocketHandler.ctorParameters = function () { return [
|
|
518
|
+
{ type: Store },
|
|
519
|
+
{ type: Actions },
|
|
520
|
+
{ type: undefined, decorators: [{ type: Inject, args: [NGXS_WEBSOCKET_OPTIONS,] }] }
|
|
521
|
+
]; };
|
|
522
|
+
return WebSocketHandler;
|
|
523
|
+
}());
|
|
524
|
+
if (false) {
|
|
525
|
+
/**
|
|
526
|
+
* @type {?}
|
|
527
|
+
* @private
|
|
528
|
+
*/
|
|
529
|
+
WebSocketHandler.prototype.socket;
|
|
530
|
+
/**
|
|
531
|
+
* @type {?}
|
|
532
|
+
* @private
|
|
533
|
+
*/
|
|
534
|
+
WebSocketHandler.prototype.config;
|
|
535
|
+
/**
|
|
536
|
+
* @type {?}
|
|
537
|
+
* @private
|
|
538
|
+
*/
|
|
539
|
+
WebSocketHandler.prototype.typeKey;
|
|
540
|
+
/**
|
|
541
|
+
* @type {?}
|
|
542
|
+
* @private
|
|
543
|
+
*/
|
|
544
|
+
WebSocketHandler.prototype.subscription;
|
|
545
|
+
/**
|
|
546
|
+
* @type {?}
|
|
547
|
+
* @private
|
|
548
|
+
*/
|
|
549
|
+
WebSocketHandler.prototype.store;
|
|
550
|
+
/**
|
|
551
|
+
* @type {?}
|
|
552
|
+
* @private
|
|
553
|
+
*/
|
|
554
|
+
WebSocketHandler.prototype.actions$;
|
|
555
|
+
/**
|
|
556
|
+
* @type {?}
|
|
557
|
+
* @private
|
|
558
|
+
*/
|
|
559
|
+
WebSocketHandler.prototype.options;
|
|
560
560
|
}
|
|
561
561
|
|
|
562
|
-
/**
|
|
563
|
-
* @fileoverview added by tsickle
|
|
564
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
565
|
-
*/
|
|
566
|
-
/**
|
|
567
|
-
* @param {?} options
|
|
568
|
-
* @return {?}
|
|
569
|
-
*/
|
|
570
|
-
function websocketOptionsFactory(options) {
|
|
571
|
-
return __assign({ reconnectInterval: 5000, reconnectAttempts: 10, typeKey: 'type', deserializer: /**
|
|
572
|
-
* @param {?} e
|
|
573
|
-
* @return {?}
|
|
574
|
-
*/
|
|
575
|
-
function (e) {
|
|
576
|
-
return JSON.parse(e.data);
|
|
577
|
-
},
|
|
578
|
-
serializer: /**
|
|
579
|
-
* @param {?} value
|
|
580
|
-
* @return {?}
|
|
581
|
-
*/
|
|
582
|
-
function (value) {
|
|
583
|
-
return JSON.stringify(value);
|
|
584
|
-
} }, options);
|
|
585
|
-
}
|
|
586
|
-
/** @type {?} */
|
|
587
|
-
var USER_OPTIONS = new InjectionToken('USER_OPTIONS');
|
|
588
|
-
var NgxsWebsocketPluginModule = /** @class */ (function () {
|
|
589
|
-
function NgxsWebsocketPluginModule() {
|
|
590
|
-
}
|
|
591
|
-
/**
|
|
592
|
-
* @param {?=} options
|
|
593
|
-
* @return {?}
|
|
594
|
-
*/
|
|
595
|
-
NgxsWebsocketPluginModule.forRoot = /**
|
|
596
|
-
* @param {?=} options
|
|
597
|
-
* @return {?}
|
|
598
|
-
*/
|
|
599
|
-
function (options) {
|
|
600
|
-
return {
|
|
601
|
-
ngModule: NgxsWebsocketPluginModule,
|
|
602
|
-
providers: [
|
|
603
|
-
WebSocketHandler,
|
|
604
|
-
{
|
|
605
|
-
provide: USER_OPTIONS,
|
|
606
|
-
useValue: options
|
|
607
|
-
},
|
|
608
|
-
{
|
|
609
|
-
provide: NGXS_WEBSOCKET_OPTIONS,
|
|
610
|
-
useFactory: websocketOptionsFactory,
|
|
611
|
-
deps: [USER_OPTIONS]
|
|
612
|
-
},
|
|
613
|
-
{
|
|
614
|
-
provide: APP_INITIALIZER,
|
|
615
|
-
useFactory: noop,
|
|
616
|
-
deps: [WebSocketHandler],
|
|
617
|
-
multi: true
|
|
618
|
-
}
|
|
619
|
-
]
|
|
620
|
-
};
|
|
621
|
-
};
|
|
622
|
-
NgxsWebsocketPluginModule.decorators = [
|
|
623
|
-
{ type: NgModule }
|
|
624
|
-
];
|
|
625
|
-
return NgxsWebsocketPluginModule;
|
|
562
|
+
/**
|
|
563
|
+
* @fileoverview added by tsickle
|
|
564
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
565
|
+
*/
|
|
566
|
+
/**
|
|
567
|
+
* @param {?} options
|
|
568
|
+
* @return {?}
|
|
569
|
+
*/
|
|
570
|
+
function websocketOptionsFactory(options) {
|
|
571
|
+
return __assign({ reconnectInterval: 5000, reconnectAttempts: 10, typeKey: 'type', deserializer: /**
|
|
572
|
+
* @param {?} e
|
|
573
|
+
* @return {?}
|
|
574
|
+
*/
|
|
575
|
+
function (e) {
|
|
576
|
+
return JSON.parse(e.data);
|
|
577
|
+
},
|
|
578
|
+
serializer: /**
|
|
579
|
+
* @param {?} value
|
|
580
|
+
* @return {?}
|
|
581
|
+
*/
|
|
582
|
+
function (value) {
|
|
583
|
+
return JSON.stringify(value);
|
|
584
|
+
} }, options);
|
|
585
|
+
}
|
|
586
|
+
/** @type {?} */
|
|
587
|
+
var USER_OPTIONS = new InjectionToken('USER_OPTIONS');
|
|
588
|
+
var NgxsWebsocketPluginModule = /** @class */ (function () {
|
|
589
|
+
function NgxsWebsocketPluginModule() {
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* @param {?=} options
|
|
593
|
+
* @return {?}
|
|
594
|
+
*/
|
|
595
|
+
NgxsWebsocketPluginModule.forRoot = /**
|
|
596
|
+
* @param {?=} options
|
|
597
|
+
* @return {?}
|
|
598
|
+
*/
|
|
599
|
+
function (options) {
|
|
600
|
+
return {
|
|
601
|
+
ngModule: NgxsWebsocketPluginModule,
|
|
602
|
+
providers: [
|
|
603
|
+
WebSocketHandler,
|
|
604
|
+
{
|
|
605
|
+
provide: USER_OPTIONS,
|
|
606
|
+
useValue: options
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
provide: NGXS_WEBSOCKET_OPTIONS,
|
|
610
|
+
useFactory: websocketOptionsFactory,
|
|
611
|
+
deps: [USER_OPTIONS]
|
|
612
|
+
},
|
|
613
|
+
{
|
|
614
|
+
provide: APP_INITIALIZER,
|
|
615
|
+
useFactory: noop,
|
|
616
|
+
deps: [WebSocketHandler],
|
|
617
|
+
multi: true
|
|
618
|
+
}
|
|
619
|
+
]
|
|
620
|
+
};
|
|
621
|
+
};
|
|
622
|
+
NgxsWebsocketPluginModule.decorators = [
|
|
623
|
+
{ type: NgModule }
|
|
624
|
+
];
|
|
625
|
+
return NgxsWebsocketPluginModule;
|
|
626
626
|
}());
|
|
627
627
|
|
|
628
|
-
/**
|
|
629
|
-
* @fileoverview added by tsickle
|
|
630
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
628
|
+
/**
|
|
629
|
+
* @fileoverview added by tsickle
|
|
630
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
631
631
|
*/
|
|
632
632
|
|
|
633
|
-
/**
|
|
634
|
-
* @fileoverview added by tsickle
|
|
635
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
633
|
+
/**
|
|
634
|
+
* @fileoverview added by tsickle
|
|
635
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
636
636
|
*/
|
|
637
637
|
|
|
638
|
-
/**
|
|
639
|
-
* @fileoverview added by tsickle
|
|
640
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
638
|
+
/**
|
|
639
|
+
* @fileoverview added by tsickle
|
|
640
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
641
641
|
*/
|
|
642
642
|
|
|
643
643
|
export { ConnectWebSocket, DisconnectWebSocket, NGXS_WEBSOCKET_OPTIONS, NgxsWebsocketPluginModule, SendWebSocketMessage, WebSocketConnected, WebSocketConnectionUpdated, WebSocketDisconnected, WebsocketMessageError, websocketOptionsFactory as ɵa, USER_OPTIONS as ɵb, noop as ɵc, WebSocketHandler as ɵd };
|