@ngxs/websocket-plugin 3.8.1-dev.master-07536db → 3.8.1-dev.master-db96f65

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.
@@ -2,13 +2,12 @@ import * as i0 from '@angular/core';
2
2
  import { InjectionToken, Injectable, Inject, APP_INITIALIZER, NgModule, makeEnvironmentProviders } from '@angular/core';
3
3
  import * as i1 from '@ngxs/store';
4
4
  import { ofActionDispatched, getValue } from '@ngxs/store';
5
- import { Subscription } from 'rxjs';
6
- import { WebSocketSubject } from 'rxjs/webSocket';
5
+ import { Subject, ReplaySubject, fromEvent } from 'rxjs';
6
+ import { takeUntil } from 'rxjs/operators';
7
7
 
8
- const NGXS_WEBSOCKET_OPTIONS = new InjectionToken('NGXS_WEBSOCKET_OPTIONS');
9
- function noop(..._args) {
10
- return function () { };
11
- }
8
+ const NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;
9
+ const NGXS_WEBSOCKET_OPTIONS = new InjectionToken(NG_DEV_MODE ? 'NGXS_WEBSOCKET_OPTIONS' : '');
10
+ const USER_OPTIONS = new InjectionToken(NG_DEV_MODE ? 'USER_OPTIONS' : '');
12
11
  /**
13
12
  * Action to connect to the websocket. Optionally pass a URL.
14
13
  */
@@ -71,141 +70,147 @@ class TypeKeyPropertyMissingError extends Error {
71
70
  }
72
71
 
73
72
  class WebSocketHandler {
74
- constructor(store, actions$, options) {
75
- this.store = store;
76
- this.actions$ = actions$;
77
- this.options = options;
78
- this.socket = null;
79
- this.config = {
80
- url: this.options.url,
81
- protocol: this.options.protocol,
82
- // Default binary type is `blob` for the global `WebSocket`
83
- binaryType: this.options.binaryType,
84
- serializer: this.options.serializer,
85
- deserializer: this.options.deserializer,
86
- closeObserver: {
87
- next: () => {
88
- // ATTENTION!
89
- // See https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/dom/WebSocketSubject.ts#L340
90
- // RxJS socket emits `onComplete` event only if `event.wasClean` is truthy
91
- // and doesn't complete socket subject if it's falsy
92
- this.disconnect();
93
- }
94
- },
95
- openObserver: {
96
- next: () => this.store.dispatch(new WebSocketConnected())
97
- }
98
- };
99
- this.typeKey = this.options.typeKey;
100
- this.subscription = new Subscription();
101
- this.setupActionsListeners();
73
+ constructor(_store, _ngZone, _actions$, _options) {
74
+ this._store = _store;
75
+ this._ngZone = _ngZone;
76
+ this._actions$ = _actions$;
77
+ this._options = _options;
78
+ this._socket = null;
79
+ this._socketClosed$ = new Subject();
80
+ this._typeKey = this._options.typeKey;
81
+ this._destroy$ = new ReplaySubject(1);
82
+ this._setupActionsListeners();
102
83
  }
103
84
  ngOnDestroy() {
104
- this.closeConnection();
105
- this.subscription.unsubscribe();
85
+ this._disconnect(/* forcelyCloseSocket */ true);
86
+ this._destroy$.next();
106
87
  }
107
- setupActionsListeners() {
108
- this.subscription.add(this.actions$.pipe(ofActionDispatched(ConnectWebSocket)).subscribe(({ payload }) => {
88
+ _setupActionsListeners() {
89
+ this._actions$
90
+ .pipe(ofActionDispatched(ConnectWebSocket), takeUntil(this._destroy$))
91
+ .subscribe(({ payload }) => {
109
92
  this.connect(payload);
110
- }));
111
- this.subscription.add(this.actions$.pipe(ofActionDispatched(DisconnectWebSocket)).subscribe(() => {
112
- this.disconnect();
113
- }));
114
- this.subscription.add(this.actions$.pipe(ofActionDispatched(SendWebSocketMessage)).subscribe(({ payload }) => {
93
+ });
94
+ this._actions$
95
+ .pipe(ofActionDispatched(DisconnectWebSocket), takeUntil(this._destroy$))
96
+ .subscribe(() => {
97
+ this._disconnect(/* forcelyCloseSocket */ true);
98
+ });
99
+ this._actions$
100
+ .pipe(ofActionDispatched(SendWebSocketMessage), takeUntil(this._destroy$))
101
+ .subscribe(({ payload }) => {
115
102
  this.send(payload);
116
- }));
103
+ });
117
104
  }
118
105
  connect(options) {
119
- this.updateConnection();
120
- // Users can pass the options in the connect method so
121
- // if options aren't available at DI bootstrap they have access
122
- // to pass them here
106
+ if (this._socket) {
107
+ this._closeConnection(/* forcelyCloseSocket */ true);
108
+ this._store.dispatch(new WebSocketConnectionUpdated());
109
+ }
110
+ // TODO(arturovt): we should not override default config values because this breaks support for having multiple socket connections.
123
111
  if (options) {
124
- this.mergeConfigWithOptions(options);
112
+ if (options.serializer) {
113
+ this._options.serializer = options.serializer;
114
+ }
115
+ if (options.deserializer) {
116
+ this._options.deserializer = options.deserializer;
117
+ }
125
118
  }
126
- this.socket = new WebSocketSubject(this.config);
127
- this.socket.subscribe({
128
- next: (message) => {
129
- const type = getValue(message, this.typeKey);
119
+ this._ngZone.runOutsideAngular(() => {
120
+ // We either use options provided in the `ConnectWebSocket` action
121
+ // or fallback to default config values.
122
+ const url = options?.url || this._options.url;
123
+ const protocol = options?.protocol || this._options.protocol;
124
+ const binaryType = options?.binaryType || this._options.binaryType;
125
+ const socket = (this._socket = protocol
126
+ ? new WebSocket(url, protocol)
127
+ : new WebSocket(url));
128
+ if (binaryType) {
129
+ socket.binaryType = binaryType;
130
+ }
131
+ fromEvent(socket, 'open')
132
+ .pipe(takeUntil(this._socketClosed$))
133
+ .subscribe(() => this._store.dispatch(new WebSocketConnected()));
134
+ fromEvent(socket, 'message')
135
+ .pipe(takeUntil(this._socketClosed$))
136
+ .subscribe(event => {
137
+ const message = this._options.deserializer(event);
138
+ const type = getValue(message, this._typeKey);
130
139
  if (!type) {
131
- throw new TypeKeyPropertyMissingError(this.typeKey);
140
+ throw new TypeKeyPropertyMissingError(this._typeKey);
132
141
  }
133
- this.store.dispatch({ ...message, type });
134
- },
135
- error: (error) => {
136
- if (error instanceof CloseEvent) {
137
- this.dispatchWebSocketDisconnected();
142
+ this._store.dispatch({ ...message, type });
143
+ });
144
+ fromEvent(socket, 'error')
145
+ .pipe(takeUntil(this._socketClosed$))
146
+ .subscribe(error => {
147
+ // The error event indicates that an error has occurred during the
148
+ // WebSocket communication, and it is often appropriate to close the
149
+ // WebSocket connection when such an error occurs.
150
+ // We need to call `_disconnect()` after the error event has been fired.
151
+ // This ensures that the WebSocket connection is properly closed to prevent
152
+ // potential resource leaks.
153
+ this._disconnect(/* forcelyCloseSocket */ true);
154
+ this._store.dispatch(new WebsocketMessageError(error));
155
+ });
156
+ fromEvent(socket, 'close')
157
+ .pipe(takeUntil(this._socketClosed$))
158
+ .subscribe(event => {
159
+ if (event.wasClean) {
160
+ // It is not necessary to call `socket.close()` after the `close` event
161
+ // has been fired. In fact, calling `socket.close()` within the `close`
162
+ // event handler or immediately after the event has been fired can lead
163
+ // to unexpected behavior.
164
+ this._disconnect(/* forcelyCloseSocket */ false);
138
165
  }
139
166
  else {
140
- this.store.dispatch(new WebsocketMessageError(error));
167
+ // If the WebSocket `close` event has been fired and its `wasClean`
168
+ // property is falsy, it indicates that the WebSocket connection was
169
+ // closed in an unexpected or abnormal manner.
170
+ // We should call `socket.close()` in this scenario, we can ensure that
171
+ // the WebSocket connection is properly closed.
172
+ this._disconnect(/* forcelyCloseSocket */ true);
173
+ this._store.dispatch(new WebsocketMessageError(event));
141
174
  }
142
- }
175
+ });
143
176
  });
144
177
  }
145
- disconnect() {
146
- if (this.socket) {
147
- this.closeConnection();
148
- this.dispatchWebSocketDisconnected();
178
+ _disconnect(forcelyCloseSocket) {
179
+ if (this._socket) {
180
+ this._closeConnection(forcelyCloseSocket);
181
+ this._store.dispatch(new WebSocketDisconnected());
149
182
  }
150
183
  }
151
184
  send(data) {
152
- if (!this.socket) {
185
+ if (!this._socket) {
153
186
  throw new Error('You must connect to the socket before sending any data');
154
187
  }
155
- this.socket.next(data);
156
- }
157
- /**
158
- * Don't enlarge the `connect` method
159
- */
160
- mergeConfigWithOptions(options) {
161
- if (options.url) {
162
- this.config.url = options.url;
163
- }
164
- if (options.serializer) {
165
- this.config.serializer = options.serializer;
166
- }
167
- if (options.deserializer) {
168
- this.config.deserializer = options.deserializer;
188
+ try {
189
+ this._socket.send(this._options.serializer(data));
169
190
  }
170
- }
171
- /**
172
- * To ensure we don't have any memory leaks
173
- * e.g. if the user occasionally dispatched `ConnectWebSocket` twice
174
- * then the previous subscription will still live in the memory
175
- * to prevent such behavior - we close the previous connection if it exists
176
- */
177
- updateConnection() {
178
- if (this.socket) {
179
- this.closeConnection();
180
- this.store.dispatch(new WebSocketConnectionUpdated());
191
+ catch (error) {
192
+ this._store.dispatch(new WebsocketMessageError(error));
181
193
  }
182
194
  }
183
- /**
184
- * Used in many places so it's better to move the code into function
185
- */
186
- dispatchWebSocketDisconnected() {
187
- this.store.dispatch(new WebSocketDisconnected());
188
- }
189
- closeConnection() {
190
- // `socket.complete()` closes the connection
191
- // also it doesn't invoke the `onComplete` callback that we passed
192
- // into `socket.subscribe(...)`
193
- if (this.socket !== null) {
194
- this.socket.complete();
195
- this.socket = null;
195
+ _closeConnection(forcelyCloseSocket) {
196
+ if (forcelyCloseSocket) {
197
+ this._socket?.close();
196
198
  }
199
+ this._socket = null;
200
+ this._socketClosed$.next();
197
201
  }
198
202
  }
199
- /** @nocollapse */ WebSocketHandler.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: WebSocketHandler, deps: [{ token: i1.Store }, { token: i1.Actions }, { token: NGXS_WEBSOCKET_OPTIONS }], target: i0.ɵɵFactoryTarget.Injectable });
200
- /** @nocollapse */ WebSocketHandler.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: WebSocketHandler });
203
+ /** @nocollapse */ WebSocketHandler.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: WebSocketHandler, deps: [{ token: i1.Store }, { token: i0.NgZone }, { token: i1.Actions }, { token: NGXS_WEBSOCKET_OPTIONS }], target: i0.ɵɵFactoryTarget.Injectable });
204
+ /** @nocollapse */ WebSocketHandler.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: WebSocketHandler, providedIn: 'root' });
201
205
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: WebSocketHandler, decorators: [{
202
- type: Injectable
203
- }], ctorParameters: function () { return [{ type: i1.Store }, { type: i1.Actions }, { type: undefined, decorators: [{
206
+ type: Injectable,
207
+ args: [{ providedIn: 'root' }]
208
+ }], ctorParameters: function () { return [{ type: i1.Store }, { type: i0.NgZone }, { type: i1.Actions }, { type: undefined, decorators: [{
204
209
  type: Inject,
205
210
  args: [NGXS_WEBSOCKET_OPTIONS]
206
211
  }] }]; } });
207
212
 
208
- function websocketOptionsFactory(options) {
213
+ function ɵwebsocketOptionsFactory(options) {
209
214
  return {
210
215
  reconnectInterval: 5000,
211
216
  reconnectAttempts: 10,
@@ -219,29 +224,28 @@ function websocketOptionsFactory(options) {
219
224
  ...options
220
225
  };
221
226
  }
222
- const USER_OPTIONS = new InjectionToken('USER_OPTIONS');
227
+ function ɵgetProviders(options) {
228
+ return [
229
+ { provide: USER_OPTIONS, useValue: options },
230
+ {
231
+ provide: NGXS_WEBSOCKET_OPTIONS,
232
+ useFactory: ɵwebsocketOptionsFactory,
233
+ deps: [USER_OPTIONS]
234
+ },
235
+ {
236
+ provide: APP_INITIALIZER,
237
+ useFactory: () => () => { },
238
+ deps: [WebSocketHandler],
239
+ multi: true
240
+ }
241
+ ];
242
+ }
243
+
223
244
  class NgxsWebsocketPluginModule {
224
245
  static forRoot(options) {
225
246
  return {
226
247
  ngModule: NgxsWebsocketPluginModule,
227
- providers: [
228
- WebSocketHandler,
229
- {
230
- provide: USER_OPTIONS,
231
- useValue: options
232
- },
233
- {
234
- provide: NGXS_WEBSOCKET_OPTIONS,
235
- useFactory: websocketOptionsFactory,
236
- deps: [USER_OPTIONS]
237
- },
238
- {
239
- provide: APP_INITIALIZER,
240
- useFactory: noop,
241
- deps: [WebSocketHandler],
242
- multi: true
243
- }
244
- ]
248
+ providers: ɵgetProviders(options)
245
249
  };
246
250
  }
247
251
  }
@@ -252,20 +256,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImpor
252
256
  type: NgModule
253
257
  }] });
254
258
  function withNgxsWebSocketPlugin(options) {
255
- return makeEnvironmentProviders([
256
- { provide: USER_OPTIONS, useValue: options },
257
- {
258
- provide: NGXS_WEBSOCKET_OPTIONS,
259
- useFactory: websocketOptionsFactory,
260
- deps: [USER_OPTIONS]
261
- },
262
- {
263
- provide: APP_INITIALIZER,
264
- useFactory: noop,
265
- deps: [WebSocketHandler],
266
- multi: true
267
- }
268
- ]);
259
+ return makeEnvironmentProviders(ɵgetProviders(options));
269
260
  }
270
261
 
271
262
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ngxs-websocket-plugin.mjs","sources":["../../../packages/websocket-plugin/src/symbols.ts","../../../packages/websocket-plugin/src/websocket-handler.ts","../../../packages/websocket-plugin/src/websocket.module.ts","../../../packages/websocket-plugin/index.ts","../../../packages/websocket-plugin/ngxs-websocket-plugin.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\nexport const NGXS_WEBSOCKET_OPTIONS = new InjectionToken('NGXS_WEBSOCKET_OPTIONS');\n\nexport interface NgxsWebsocketPluginOptions {\n /**\n * URL of the websocket.\n */\n url?: string;\n\n /**\n * Either a single protocol string or an array of protocol strings.\n * These strings are used to indicate sub-protocols, so that a single server\n * can implement multiple WebSocket sub-protocols (for example, you might want one server to be able\n * to handle different types of interactions depending on the specified protocol).\n * If you don't specify a protocol string, an empty string is assumed.\n */\n protocol?: string | string[];\n\n /**\n * Sets the `binaryType` property of the underlying WebSocket.\n */\n binaryType?: 'blob' | 'arraybuffer';\n\n /**\n * The property name to distigunish this type for the store.\n * Default: 'type'\n */\n typeKey?: string;\n\n /**\n * Interval to try and reconnect.\n * Default: 5000\n */\n reconnectInterval?: number;\n\n /**\n * Number of reconnect attemps.\n * Default: 10\n */\n reconnectAttempts?: number;\n\n /**\n * Serializer to call before sending messages\n * Default: `json.stringify`\n */\n serializer?: (data: any) => string;\n\n /**\n * Deseralizer before publishing the message.\n */\n deserializer?: (e: MessageEvent) => any;\n}\n\nexport function noop(..._args: any[]) {\n return function () {};\n}\n\n/**\n * Action to connect to the websocket. Optionally pass a URL.\n */\nexport class ConnectWebSocket {\n static readonly type = '[WebSocket] Connect';\n\n constructor(public payload?: NgxsWebsocketPluginOptions) {}\n}\n\n/**\n * Action triggered when a error ocurrs\n */\nexport class WebsocketMessageError {\n static readonly type = '[WebSocket] Message Error';\n\n constructor(public payload: any) {}\n}\n\n/**\n * Action to disconnect the websocket.\n */\nexport class DisconnectWebSocket {\n static readonly type = '[WebSocket] Disconnect';\n}\n\n/**\n * Action triggered when websocket is connected\n */\nexport class WebSocketConnected {\n static readonly type = '[WebSocket] Connected';\n}\n\n/**\n * Action triggered when websocket is disconnected\n */\nexport class WebSocketDisconnected {\n static readonly type = '[WebSocket] Disconnected';\n}\n\n/**\n * Action to send to the server.\n */\nexport class SendWebSocketMessage {\n static readonly type = '[WebSocket] Send Message';\n\n constructor(public payload: any) {}\n}\n\n/**\n * Action dispatched when the user tries to connect if the connection already exists.\n */\nexport class WebSocketConnectionUpdated {\n static readonly type = '[WebSocket] Connection Updated';\n}\n\n/**\n * This error is thrown where there is no `type` (or custom `typeKey`) property\n * on the message that came from the server side socket\n */\nexport class TypeKeyPropertyMissingError extends Error {\n constructor(typeKey: string) {\n super(`Property ${typeKey} is missing on the socket message`);\n }\n}\n","import { Injectable, Inject, OnDestroy } from '@angular/core';\nimport { Actions, Store, getValue, ofActionDispatched } from '@ngxs/store';\nimport { Subscription } from 'rxjs';\n\nimport { WebSocketSubject, WebSocketSubjectConfig } from 'rxjs/webSocket';\n\nimport {\n ConnectWebSocket,\n DisconnectWebSocket,\n SendWebSocketMessage,\n NGXS_WEBSOCKET_OPTIONS,\n NgxsWebsocketPluginOptions,\n WebsocketMessageError,\n WebSocketDisconnected,\n TypeKeyPropertyMissingError,\n WebSocketConnectionUpdated,\n WebSocketConnected\n} from './symbols';\n\n@Injectable()\nexport class WebSocketHandler implements OnDestroy {\n private socket: WebSocketSubject<any> | null = null;\n\n private config: WebSocketSubjectConfig<any> = {\n url: this.options.url!,\n protocol: this.options.protocol,\n // Default binary type is `blob` for the global `WebSocket`\n binaryType: this.options.binaryType,\n serializer: this.options.serializer,\n deserializer: this.options.deserializer,\n closeObserver: {\n next: () => {\n // ATTENTION!\n // See https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/dom/WebSocketSubject.ts#L340\n // RxJS socket emits `onComplete` event only if `event.wasClean` is truthy\n // and doesn't complete socket subject if it's falsy\n this.disconnect();\n }\n },\n openObserver: {\n next: () => this.store.dispatch(new WebSocketConnected())\n }\n };\n\n private typeKey = this.options.typeKey!;\n\n private subscription = new Subscription();\n\n constructor(\n private store: Store,\n private actions$: Actions,\n @Inject(NGXS_WEBSOCKET_OPTIONS) private options: NgxsWebsocketPluginOptions\n ) {\n this.setupActionsListeners();\n }\n\n ngOnDestroy(): void {\n this.closeConnection();\n this.subscription.unsubscribe();\n }\n\n private setupActionsListeners(): void {\n this.subscription.add(\n this.actions$.pipe(ofActionDispatched(ConnectWebSocket)).subscribe(({ payload }) => {\n this.connect(payload);\n })\n );\n\n this.subscription.add(\n this.actions$.pipe(ofActionDispatched(DisconnectWebSocket)).subscribe(() => {\n this.disconnect();\n })\n );\n\n this.subscription.add(\n this.actions$.pipe(ofActionDispatched(SendWebSocketMessage)).subscribe(({ payload }) => {\n this.send(payload);\n })\n );\n }\n\n private connect(options?: NgxsWebsocketPluginOptions): void {\n this.updateConnection();\n\n // Users can pass the options in the connect method so\n // if options aren't available at DI bootstrap they have access\n // to pass them here\n if (options) {\n this.mergeConfigWithOptions(options);\n }\n\n this.socket = new WebSocketSubject(this.config);\n\n this.socket.subscribe({\n next: (message: any) => {\n const type = getValue(message, this.typeKey);\n if (!type) {\n throw new TypeKeyPropertyMissingError(this.typeKey);\n }\n this.store.dispatch({ ...message, type });\n },\n error: (error: any) => {\n if (error instanceof CloseEvent) {\n this.dispatchWebSocketDisconnected();\n } else {\n this.store.dispatch(new WebsocketMessageError(error));\n }\n }\n });\n }\n\n private disconnect(): void {\n if (this.socket) {\n this.closeConnection();\n this.dispatchWebSocketDisconnected();\n }\n }\n\n private send(data: any): void {\n if (!this.socket) {\n throw new Error('You must connect to the socket before sending any data');\n }\n\n this.socket.next(data);\n }\n\n /**\n * Don't enlarge the `connect` method\n */\n private mergeConfigWithOptions(options: NgxsWebsocketPluginOptions): void {\n if (options.url) {\n this.config.url = options.url;\n }\n\n if (options.serializer) {\n this.config.serializer = options.serializer;\n }\n\n if (options.deserializer) {\n this.config.deserializer = options.deserializer;\n }\n }\n\n /**\n * To ensure we don't have any memory leaks\n * e.g. if the user occasionally dispatched `ConnectWebSocket` twice\n * then the previous subscription will still live in the memory\n * to prevent such behavior - we close the previous connection if it exists\n */\n private updateConnection(): void {\n if (this.socket) {\n this.closeConnection();\n this.store.dispatch(new WebSocketConnectionUpdated());\n }\n }\n\n /**\n * Used in many places so it's better to move the code into function\n */\n private dispatchWebSocketDisconnected(): void {\n this.store.dispatch(new WebSocketDisconnected());\n }\n\n private closeConnection(): void {\n // `socket.complete()` closes the connection\n // also it doesn't invoke the `onComplete` callback that we passed\n // into `socket.subscribe(...)`\n if (this.socket !== null) {\n this.socket.complete();\n this.socket = null;\n }\n }\n}\n","import {\n NgModule,\n ModuleWithProviders,\n APP_INITIALIZER,\n InjectionToken,\n EnvironmentProviders,\n makeEnvironmentProviders\n} from '@angular/core';\n\nimport { WebSocketHandler } from './websocket-handler';\nimport { NgxsWebsocketPluginOptions, NGXS_WEBSOCKET_OPTIONS, noop } from './symbols';\n\nexport function websocketOptionsFactory(options: NgxsWebsocketPluginOptions) {\n return {\n reconnectInterval: 5000,\n reconnectAttempts: 10,\n typeKey: 'type',\n deserializer(e: MessageEvent) {\n return JSON.parse(e.data);\n },\n serializer(value: any) {\n return JSON.stringify(value);\n },\n ...options\n };\n}\n\nexport const USER_OPTIONS = new InjectionToken('USER_OPTIONS');\n\n@NgModule()\nexport class NgxsWebsocketPluginModule {\n static forRoot(\n options?: NgxsWebsocketPluginOptions\n ): ModuleWithProviders<NgxsWebsocketPluginModule> {\n return {\n ngModule: NgxsWebsocketPluginModule,\n providers: [\n WebSocketHandler,\n {\n provide: USER_OPTIONS,\n useValue: options\n },\n {\n provide: NGXS_WEBSOCKET_OPTIONS,\n useFactory: websocketOptionsFactory,\n deps: [USER_OPTIONS]\n },\n {\n provide: APP_INITIALIZER,\n useFactory: noop,\n deps: [WebSocketHandler],\n multi: true\n }\n ]\n };\n }\n}\n\nexport function withNgxsWebSocketPlugin(\n options?: NgxsWebsocketPluginOptions\n): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: USER_OPTIONS, useValue: options },\n {\n provide: NGXS_WEBSOCKET_OPTIONS,\n useFactory: websocketOptionsFactory,\n deps: [USER_OPTIONS]\n },\n {\n provide: APP_INITIALIZER,\n useFactory: noop,\n deps: [WebSocketHandler],\n multi: true\n }\n ]);\n}\n","/**\n * The public api for consumers of @ngxs/websocket-plugin\n */\nexport * from './src/public_api';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;MAEa,sBAAsB,GAAG,IAAI,cAAc,CAAC,wBAAwB,EAAE;AAoDnE,SAAA,IAAI,CAAC,GAAG,KAAY,EAAA;IAClC,OAAO,YAAA,GAAc,CAAC;AACxB,CAAC;AAED;;AAEG;MACU,gBAAgB,CAAA;AAG3B,IAAA,WAAA,CAAmB,OAAoC,EAAA;QAApC,IAAO,CAAA,OAAA,GAAP,OAAO,CAA6B;KAAI;;AAF3C,gBAAI,CAAA,IAAA,GAAG,qBAAqB,CAAC;AAK/C;;AAEG;MACU,qBAAqB,CAAA;AAGhC,IAAA,WAAA,CAAmB,OAAY,EAAA;QAAZ,IAAO,CAAA,OAAA,GAAP,OAAO,CAAK;KAAI;;AAFnB,qBAAI,CAAA,IAAA,GAAG,2BAA2B,CAAC;AAKrD;;AAEG;MACU,mBAAmB,CAAA;;AACd,mBAAI,CAAA,I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AAzB,yBAAyB,EAAA,CAAA,CAAA;0IAAzB,yBAAyB,EAAA,CAAA,CAAA;2FAAzB,yBAAyB,EAAA,UAAA,EAAA,CAAA;kBADrC,QAAQ;;AA6BH,SAAU,uBAAuB,CACrC,OAAoC,EAAA;AAEpC,IAAA,OAAO,wBAAwB,CAAC;AAC9B,QAAA,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE;AAC5C,QAAA;AACE,YAAA,OAAO,EAAE,sBAAsB;AAC/B,YAAA,UAAU,EAAE,uBAAuB;YACnC,IAAI,EAAE,CAAC,YAAY,CAAC;AACrB,SAAA;AACD,QAAA;AACE,YAAA,OAAO,EAAE,eAAe;AACxB,YAAA,UAAU,EAAE,IAAI;YAChB,IAAI,EAAE,CAAC,gBAAgB,CAAC;AACxB,YAAA,KAAK,EAAE,IAAI;AACZ,SAAA;AACF,KAAA,CAAC,CAAC;AACL;;AC3EA;;AAEG;;ACFH;;AAEG;;;;"}
1
+ {"version":3,"file":"ngxs-websocket-plugin.mjs","sources":["../../../packages/websocket-plugin/src/symbols.ts","../../../packages/websocket-plugin/src/websocket-handler.ts","../../../packages/websocket-plugin/src/providers.ts","../../../packages/websocket-plugin/src/websocket.module.ts","../../../packages/websocket-plugin/index.ts","../../../packages/websocket-plugin/ngxs-websocket-plugin.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\ndeclare const ngDevMode: boolean;\n\nconst NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;\n\nexport const NGXS_WEBSOCKET_OPTIONS = new InjectionToken<NgxsWebsocketPluginOptions>(\n NG_DEV_MODE ? 'NGXS_WEBSOCKET_OPTIONS' : ''\n);\n\nexport const USER_OPTIONS = new InjectionToken(NG_DEV_MODE ? 'USER_OPTIONS' : '');\n\nexport interface NgxsWebsocketPluginOptions {\n /**\n * URL of the websocket.\n */\n url?: string;\n\n /**\n * Either a single protocol string or an array of protocol strings.\n * These strings are used to indicate sub-protocols, so that a single server\n * can implement multiple WebSocket sub-protocols (for example, you might want one server to be able\n * to handle different types of interactions depending on the specified protocol).\n * If you don't specify a protocol string, an empty string is assumed.\n */\n protocol?: string | string[];\n\n /**\n * Sets the `binaryType` property of the underlying WebSocket.\n */\n binaryType?: 'blob' | 'arraybuffer';\n\n /**\n * The property name to distigunish this type for the store.\n * Default: 'type'\n */\n typeKey?: string;\n\n /**\n * Interval to try and reconnect.\n * Default: 5000\n */\n reconnectInterval?: number;\n\n /**\n * Number of reconnect attemps.\n * Default: 10\n */\n reconnectAttempts?: number;\n\n /**\n * Serializer to call before sending messages\n * Default: `json.stringify`\n */\n serializer?: (data: any) => string;\n\n /**\n * Deseralizer before publishing the message.\n */\n deserializer?: (e: MessageEvent) => any;\n}\n\n/**\n * Action to connect to the websocket. Optionally pass a URL.\n */\nexport class ConnectWebSocket {\n static readonly type = '[WebSocket] Connect';\n\n constructor(public payload?: NgxsWebsocketPluginOptions) {}\n}\n\n/**\n * Action triggered when a error ocurrs\n */\nexport class WebsocketMessageError {\n static readonly type = '[WebSocket] Message Error';\n\n constructor(public payload: any) {}\n}\n\n/**\n * Action to disconnect the websocket.\n */\nexport class DisconnectWebSocket {\n static readonly type = '[WebSocket] Disconnect';\n}\n\n/**\n * Action triggered when websocket is connected\n */\nexport class WebSocketConnected {\n static readonly type = '[WebSocket] Connected';\n}\n\n/**\n * Action triggered when websocket is disconnected\n */\nexport class WebSocketDisconnected {\n static readonly type = '[WebSocket] Disconnected';\n}\n\n/**\n * Action to send to the server.\n */\nexport class SendWebSocketMessage {\n static readonly type = '[WebSocket] Send Message';\n\n constructor(public payload: any) {}\n}\n\n/**\n * Action dispatched when the user tries to connect if the connection already exists.\n */\nexport class WebSocketConnectionUpdated {\n static readonly type = '[WebSocket] Connection Updated';\n}\n\n/**\n * This error is thrown where there is no `type` (or custom `typeKey`) property\n * on the message that came from the server side socket\n */\nexport class TypeKeyPropertyMissingError extends Error {\n constructor(typeKey: string) {\n super(`Property ${typeKey} is missing on the socket message`);\n }\n}\n","import { Injectable, Inject, OnDestroy, NgZone } from '@angular/core';\nimport { Actions, Store, getValue, ofActionDispatched } from '@ngxs/store';\nimport { ReplaySubject, Subject, fromEvent } from 'rxjs';\nimport { takeUntil } from 'rxjs/operators';\n\nimport {\n ConnectWebSocket,\n DisconnectWebSocket,\n SendWebSocketMessage,\n NGXS_WEBSOCKET_OPTIONS,\n NgxsWebsocketPluginOptions,\n WebsocketMessageError,\n WebSocketDisconnected,\n TypeKeyPropertyMissingError,\n WebSocketConnectionUpdated,\n WebSocketConnected\n} from './symbols';\n\n@Injectable({ providedIn: 'root' })\nexport class WebSocketHandler implements OnDestroy {\n private _socket: WebSocket | null = null;\n\n private readonly _socketClosed$ = new Subject<void>();\n\n private readonly _typeKey = this._options.typeKey!;\n\n private readonly _destroy$ = new ReplaySubject<void>(1);\n\n constructor(\n private _store: Store,\n private _ngZone: NgZone,\n private _actions$: Actions,\n @Inject(NGXS_WEBSOCKET_OPTIONS) private _options: NgxsWebsocketPluginOptions\n ) {\n this._setupActionsListeners();\n }\n\n ngOnDestroy(): void {\n this._disconnect(/* forcelyCloseSocket */ true);\n this._destroy$.next();\n }\n\n private _setupActionsListeners(): void {\n this._actions$\n .pipe(ofActionDispatched(ConnectWebSocket), takeUntil(this._destroy$))\n .subscribe(({ payload }) => {\n this.connect(payload);\n });\n\n this._actions$\n .pipe(ofActionDispatched(DisconnectWebSocket), takeUntil(this._destroy$))\n .subscribe(() => {\n this._disconnect(/* forcelyCloseSocket */ true);\n });\n\n this._actions$\n .pipe(ofActionDispatched(SendWebSocketMessage), takeUntil(this._destroy$))\n .subscribe(({ payload }) => {\n this.send(payload);\n });\n }\n\n private connect(options?: NgxsWebsocketPluginOptions): void {\n if (this._socket) {\n this._closeConnection(/* forcelyCloseSocket */ true);\n this._store.dispatch(new WebSocketConnectionUpdated());\n }\n\n // TODO(arturovt): we should not override default config values because this breaks support for having multiple socket connections.\n if (options) {\n if (options.serializer) {\n this._options.serializer = options.serializer;\n }\n\n if (options.deserializer) {\n this._options.deserializer = options.deserializer;\n }\n }\n\n this._ngZone.runOutsideAngular(() => {\n // We either use options provided in the `ConnectWebSocket` action\n // or fallback to default config values.\n const url = options?.url || this._options.url!;\n const protocol = options?.protocol || this._options.protocol;\n const binaryType = options?.binaryType || this._options.binaryType;\n\n const socket = (this._socket = protocol\n ? new WebSocket(url, protocol)\n : new WebSocket(url));\n\n if (binaryType) {\n socket.binaryType = binaryType;\n }\n\n fromEvent(socket, 'open')\n .pipe(takeUntil(this._socketClosed$))\n .subscribe(() => this._store.dispatch(new WebSocketConnected()));\n\n fromEvent<MessageEvent>(socket, 'message')\n .pipe(takeUntil(this._socketClosed$))\n .subscribe(event => {\n const message = this._options.deserializer!(event);\n const type = getValue(message, this._typeKey);\n if (!type) {\n throw new TypeKeyPropertyMissingError(this._typeKey);\n }\n this._store.dispatch({ ...message, type });\n });\n\n fromEvent(socket, 'error')\n .pipe(takeUntil(this._socketClosed$))\n .subscribe(error => {\n // The error event indicates that an error has occurred during the\n // WebSocket communication, and it is often appropriate to close the\n // WebSocket connection when such an error occurs.\n // We need to call `_disconnect()` after the error event has been fired.\n // This ensures that the WebSocket connection is properly closed to prevent\n // potential resource leaks.\n this._disconnect(/* forcelyCloseSocket */ true);\n this._store.dispatch(new WebsocketMessageError(error));\n });\n\n fromEvent<CloseEvent>(socket, 'close')\n .pipe(takeUntil(this._socketClosed$))\n .subscribe(event => {\n if (event.wasClean) {\n // It is not necessary to call `socket.close()` after the `close` event\n // has been fired. In fact, calling `socket.close()` within the `close`\n // event handler or immediately after the event has been fired can lead\n // to unexpected behavior.\n this._disconnect(/* forcelyCloseSocket */ false);\n } else {\n // If the WebSocket `close` event has been fired and its `wasClean`\n // property is falsy, it indicates that the WebSocket connection was\n // closed in an unexpected or abnormal manner.\n // We should call `socket.close()` in this scenario, we can ensure that\n // the WebSocket connection is properly closed.\n this._disconnect(/* forcelyCloseSocket */ true);\n this._store.dispatch(new WebsocketMessageError(event));\n }\n });\n });\n }\n\n private _disconnect(forcelyCloseSocket: boolean): void {\n if (this._socket) {\n this._closeConnection(forcelyCloseSocket);\n this._store.dispatch(new WebSocketDisconnected());\n }\n }\n\n private send(data: any): void {\n if (!this._socket) {\n throw new Error('You must connect to the socket before sending any data');\n }\n\n try {\n this._socket.send(this._options.serializer!(data));\n } catch (error) {\n this._store.dispatch(new WebsocketMessageError(error));\n }\n }\n\n private _closeConnection(forcelyCloseSocket: boolean): void {\n if (forcelyCloseSocket) {\n this._socket?.close();\n }\n this._socket = null;\n this._socketClosed$.next();\n }\n}\n","import { APP_INITIALIZER } from '@angular/core';\n\nimport { WebSocketHandler } from './websocket-handler';\nimport { USER_OPTIONS, NGXS_WEBSOCKET_OPTIONS, NgxsWebsocketPluginOptions } from './symbols';\n\nexport function ɵwebsocketOptionsFactory(options: NgxsWebsocketPluginOptions) {\n return {\n reconnectInterval: 5000,\n reconnectAttempts: 10,\n typeKey: 'type',\n deserializer(e: MessageEvent) {\n return JSON.parse(e.data);\n },\n serializer(value: any) {\n return JSON.stringify(value);\n },\n ...options\n };\n}\n\nexport function ɵgetProviders(options?: NgxsWebsocketPluginOptions) {\n return [\n { provide: USER_OPTIONS, useValue: options },\n {\n provide: NGXS_WEBSOCKET_OPTIONS,\n useFactory: ɵwebsocketOptionsFactory,\n deps: [USER_OPTIONS]\n },\n {\n provide: APP_INITIALIZER,\n useFactory: () => () => {},\n deps: [WebSocketHandler],\n multi: true\n }\n ];\n}\n","import {\n NgModule,\n ModuleWithProviders,\n EnvironmentProviders,\n makeEnvironmentProviders\n} from '@angular/core';\n\nimport { ɵgetProviders } from './providers';\nimport { NgxsWebsocketPluginOptions } from './symbols';\n\n@NgModule()\nexport class NgxsWebsocketPluginModule {\n static forRoot(\n options?: NgxsWebsocketPluginOptions\n ): ModuleWithProviders<NgxsWebsocketPluginModule> {\n return {\n ngModule: NgxsWebsocketPluginModule,\n providers: ɵgetProviders(options)\n };\n }\n}\n\nexport function withNgxsWebSocketPlugin(\n options?: NgxsWebsocketPluginOptions\n): EnvironmentProviders {\n return makeEnvironmentProviders(ɵgetProviders(options));\n}\n","/**\n * The public api for consumers of @ngxs/websocket-plugin\n */\nexport * from './src/public_api';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;AAIA,MAAM,WAAW,GAAG,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,CAAC;AAErD,MAAA,sBAAsB,GAAG,IAAI,cAAc,CACtD,WAAW,GAAG,wBAAwB,GAAG,EAAE,EAC3C;AAEK,MAAM,YAAY,GAAG,IAAI,cAAc,CAAC,WAAW,GAAG,cAAc,GAAG,EAAE,CAAC,CAAC;AAoDlF;;AAEG;MACU,gBAAgB,CAAA;AAG3B,IAAA,WAAA,CAAmB,OAAoC,EAAA;QAApC,IAAO,CAAA,OAAA,GAAP,OAAO,CAA6B;KAAI;;AAF3C,gBAAI,CAAA,IAAA,GAAG,qBAAqB,CAAC;AAK/C;;AAEG;MACU,qBAAqB,CAAA;AAGhC,IAAA,WAAA,CAAmB,OAAY,EAAA;QAAZ,IAAO,CAAA,OAAA,GAAP,OAAO,CAAK;KAAI;;AAFnB,qBAAI,CAAA,IAAA,GAAG,2BAA2B,CAAC;AAKrD;;AAEG;MACU,mBAAmB,CAAA;;AACd,mBAAI,CAAA,IAAA,GAAG,wBAAwB,CAAC;AAGlD;;AAEG;MACU,kBAAkB,CAAA;;AACb,kBAAI,CAAA,IAAA,GAAG,uBAAuB,CAAC;AAGjD;;AAEG;MACU,qBAAqB,CAAA;;AAChB,qBAAI,CAAA,IAAA,GAAG,0BAA0B,CAAC;AAGpD;;AAEG;MACU,oBAAoB,CAAA;AAG/B,IAAA,WAAA,CAAmB,OAAY,EAAA;QAAZ,IAAO,CAAA,OAAA,GAAP,OAAO,CAAK;KAAI;;AAFnB,oBAAI,CAAA,IAAA,GAAG,0BAA0B,CAAC;AAKpD;;AAEG;MACU,0BAA0B,CAAA;;AACrB,0BAAI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AO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;SAC9B;AACD,QAAA,GAAG,OAAO;KACX,CAAC;AACJ,CAAC;AAEK,SAAU,aAAa,CAAC,OAAoC,EAAA;IAChE,OAAO;AACL,QAAA,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE;AAC5C,QAAA;AACE,YAAA,OAAO,EAAE,sBAAsB;AAC/B,YAAA,UAAU,EAAE,wBAAwB;YACpC,IAAI,EAAE,CAAC,YAAY,CAAC;AACrB,SAAA;AACD,QAAA;AACE,YAAA,OAAO,EAAE,eAAe;AACxB,YAAA,UAAU,EAAE,MAAM,SAAQ;YAC1B,IAAI,EAAE,CAAC,gBAAgB,CAAC;AACxB,YAAA,KAAK,EAAE,IAAI;AACZ,SAAA;KACF,CAAC;AACJ;;MCxBa,yBAAyB,CAAA;IACpC,OAAO,OAAO,CACZ,OAAoC,EAAA;QAEpC,OAAO;AACL,YAAA,QAAQ,EAAE,yBAAyB;AACnC,YAAA,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC;SAClC,CAAC;KACH;;yIARU,yBAAyB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA,CAAA;0IAAzB,yBAAyB,EAAA,CAAA,CAAA;0IAAzB,yBAAyB,EAAA,CAAA,CAAA;2FAAzB,yBAAyB,EAAA,UAAA,EAAA,CAAA;kBADrC,QAAQ;;AAYH,SAAU,uBAAuB,CACrC,OAAoC,EAAA;AAEpC,IAAA,OAAO,wBAAwB,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;AAC1D;;AC1BA;;AAEG;;ACFH;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ngxs/websocket-plugin",
3
3
  "description": "Websocket plugin for @ngxs/store",
4
- "version": "3.8.1-dev.master-07536db",
4
+ "version": "3.8.1-dev.master-db96f65",
5
5
  "sideEffects": true,
6
6
  "peerDependencies": {
7
7
  "@angular/core": ">=12.0.0 <17.0.0",
@@ -0,0 +1,31 @@
1
+ import { WebSocketHandler } from './websocket-handler';
2
+ import { NgxsWebsocketPluginOptions } from './symbols';
3
+ export declare function ɵwebsocketOptionsFactory(options: NgxsWebsocketPluginOptions): {
4
+ url?: string | undefined;
5
+ protocol?: string | string[] | undefined;
6
+ binaryType?: "blob" | "arraybuffer" | undefined;
7
+ typeKey: string;
8
+ reconnectInterval: number;
9
+ reconnectAttempts: number;
10
+ serializer: (data: any) => string;
11
+ deserializer: (e: MessageEvent<any>) => any;
12
+ };
13
+ export declare function ɵgetProviders(options?: NgxsWebsocketPluginOptions): ({
14
+ provide: import("@angular/core").InjectionToken<unknown>;
15
+ useValue: NgxsWebsocketPluginOptions | undefined;
16
+ useFactory?: undefined;
17
+ deps?: undefined;
18
+ multi?: undefined;
19
+ } | {
20
+ provide: import("@angular/core").InjectionToken<NgxsWebsocketPluginOptions>;
21
+ useFactory: typeof ɵwebsocketOptionsFactory;
22
+ deps: import("@angular/core").InjectionToken<unknown>[];
23
+ useValue?: undefined;
24
+ multi?: undefined;
25
+ } | {
26
+ provide: import("@angular/core").InjectionToken<readonly (() => void | import("rxjs").Observable<unknown> | Promise<unknown>)[]>;
27
+ useFactory: () => () => void;
28
+ deps: (typeof WebSocketHandler)[];
29
+ multi: boolean;
30
+ useValue?: undefined;
31
+ })[];
package/src/symbols.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { InjectionToken } from '@angular/core';
2
- export declare const NGXS_WEBSOCKET_OPTIONS: InjectionToken<unknown>;
2
+ export declare const NGXS_WEBSOCKET_OPTIONS: InjectionToken<NgxsWebsocketPluginOptions>;
3
+ export declare const USER_OPTIONS: InjectionToken<unknown>;
3
4
  export interface NgxsWebsocketPluginOptions {
4
5
  /**
5
6
  * URL of the websocket.
@@ -42,7 +43,6 @@ export interface NgxsWebsocketPluginOptions {
42
43
  */
43
44
  deserializer?: (e: MessageEvent) => any;
44
45
  }
45
- export declare function noop(..._args: any[]): () => void;
46
46
  /**
47
47
  * Action to connect to the websocket. Optionally pass a URL.
48
48
  */
@@ -1,37 +1,23 @@
1
- import { OnDestroy } from '@angular/core';
1
+ import { OnDestroy, NgZone } from '@angular/core';
2
2
  import { Actions, Store } from '@ngxs/store';
3
3
  import { NgxsWebsocketPluginOptions } from './symbols';
4
4
  import * as i0 from "@angular/core";
5
5
  export declare class WebSocketHandler implements OnDestroy {
6
- private store;
7
- private actions$;
8
- private options;
9
- private socket;
10
- private config;
11
- private typeKey;
12
- private subscription;
13
- constructor(store: Store, actions$: Actions, options: NgxsWebsocketPluginOptions);
6
+ private _store;
7
+ private _ngZone;
8
+ private _actions$;
9
+ private _options;
10
+ private _socket;
11
+ private readonly _socketClosed$;
12
+ private readonly _typeKey;
13
+ private readonly _destroy$;
14
+ constructor(_store: Store, _ngZone: NgZone, _actions$: Actions, _options: NgxsWebsocketPluginOptions);
14
15
  ngOnDestroy(): void;
15
- private setupActionsListeners;
16
+ private _setupActionsListeners;
16
17
  private connect;
17
- private disconnect;
18
+ private _disconnect;
18
19
  private send;
19
- /**
20
- * Don't enlarge the `connect` method
21
- */
22
- private mergeConfigWithOptions;
23
- /**
24
- * To ensure we don't have any memory leaks
25
- * e.g. if the user occasionally dispatched `ConnectWebSocket` twice
26
- * then the previous subscription will still live in the memory
27
- * to prevent such behavior - we close the previous connection if it exists
28
- */
29
- private updateConnection;
30
- /**
31
- * Used in many places so it's better to move the code into function
32
- */
33
- private dispatchWebSocketDisconnected;
34
- private closeConnection;
20
+ private _closeConnection;
35
21
  static ɵfac: i0.ɵɵFactoryDeclaration<WebSocketHandler, never>;
36
22
  static ɵprov: i0.ɵɵInjectableDeclaration<WebSocketHandler>;
37
23
  }
@@ -1,17 +1,6 @@
1
- import { ModuleWithProviders, InjectionToken, EnvironmentProviders } from '@angular/core';
1
+ import { ModuleWithProviders, EnvironmentProviders } from '@angular/core';
2
2
  import { NgxsWebsocketPluginOptions } from './symbols';
3
3
  import * as i0 from "@angular/core";
4
- export declare function websocketOptionsFactory(options: NgxsWebsocketPluginOptions): {
5
- url?: string | undefined;
6
- protocol?: string | string[] | undefined;
7
- binaryType?: "blob" | "arraybuffer" | undefined;
8
- typeKey: string;
9
- reconnectInterval: number;
10
- reconnectAttempts: number;
11
- serializer: (data: any) => string;
12
- deserializer: (e: MessageEvent<any>) => any;
13
- };
14
- export declare const USER_OPTIONS: InjectionToken<unknown>;
15
4
  export declare class NgxsWebsocketPluginModule {
16
5
  static forRoot(options?: NgxsWebsocketPluginOptions): ModuleWithProviders<NgxsWebsocketPluginModule>;
17
6
  static ɵfac: i0.ɵɵFactoryDeclaration<NgxsWebsocketPluginModule, never>;