@ngxs/websocket-plugin 19.0.0 → 20.0.0-dev.master-5e7c96c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { InjectionToken, inject, NgZone, DestroyRef, Injectable, APP_INITIALIZER, NgModule, makeEnvironmentProviders } from '@angular/core';
|
|
3
|
+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
3
4
|
import { Store, Actions, ofActionDispatched } from '@ngxs/store';
|
|
4
5
|
import { getValue } from '@ngxs/store/plugins';
|
|
5
|
-
import { Subject,
|
|
6
|
+
import { Subject, fromEvent, takeUntil } from 'rxjs';
|
|
6
7
|
|
|
7
8
|
const NGXS_WEBSOCKET_OPTIONS = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_WEBSOCKET_OPTIONS' : '');
|
|
8
9
|
const USER_OPTIONS = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'USER_OPTIONS' : '');
|
|
@@ -10,7 +11,8 @@ const USER_OPTIONS = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDe
|
|
|
10
11
|
* Action to connect to the websocket. Optionally pass a URL.
|
|
11
12
|
*/
|
|
12
13
|
class ConnectWebSocket {
|
|
13
|
-
|
|
14
|
+
payload;
|
|
15
|
+
static type = '[WebSocket] Connect';
|
|
14
16
|
constructor(payload) {
|
|
15
17
|
this.payload = payload;
|
|
16
18
|
}
|
|
@@ -19,7 +21,8 @@ class ConnectWebSocket {
|
|
|
19
21
|
* Action triggered when a error ocurrs
|
|
20
22
|
*/
|
|
21
23
|
class WebSocketMessageError {
|
|
22
|
-
|
|
24
|
+
payload;
|
|
25
|
+
static type = '[WebSocket] Message Error';
|
|
23
26
|
constructor(payload) {
|
|
24
27
|
this.payload = payload;
|
|
25
28
|
}
|
|
@@ -28,25 +31,26 @@ class WebSocketMessageError {
|
|
|
28
31
|
* Action to disconnect the websocket.
|
|
29
32
|
*/
|
|
30
33
|
class DisconnectWebSocket {
|
|
31
|
-
static
|
|
34
|
+
static type = '[WebSocket] Disconnect';
|
|
32
35
|
}
|
|
33
36
|
/**
|
|
34
37
|
* Action triggered when websocket is connected
|
|
35
38
|
*/
|
|
36
39
|
class WebSocketConnected {
|
|
37
|
-
static
|
|
40
|
+
static type = '[WebSocket] Connected';
|
|
38
41
|
}
|
|
39
42
|
/**
|
|
40
43
|
* Action triggered when websocket is disconnected
|
|
41
44
|
*/
|
|
42
45
|
class WebSocketDisconnected {
|
|
43
|
-
static
|
|
46
|
+
static type = '[WebSocket] Disconnected';
|
|
44
47
|
}
|
|
45
48
|
/**
|
|
46
49
|
* Action to send to the server.
|
|
47
50
|
*/
|
|
48
51
|
class SendWebSocketMessage {
|
|
49
|
-
|
|
52
|
+
payload;
|
|
53
|
+
static type = '[WebSocket] Send Message';
|
|
50
54
|
constructor(payload) {
|
|
51
55
|
this.payload = payload;
|
|
52
56
|
}
|
|
@@ -55,7 +59,7 @@ class SendWebSocketMessage {
|
|
|
55
59
|
* Action dispatched when the user tries to connect if the connection already exists.
|
|
56
60
|
*/
|
|
57
61
|
class WebSocketConnectionUpdated {
|
|
58
|
-
static
|
|
62
|
+
static type = '[WebSocket] Connection Updated';
|
|
59
63
|
}
|
|
60
64
|
/**
|
|
61
65
|
* This error is thrown where there is no `type` (or custom `typeKey`) property
|
|
@@ -68,35 +72,31 @@ class TypeKeyPropertyMissingError extends Error {
|
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
class WebSocketHandler {
|
|
75
|
+
_store = inject(Store);
|
|
76
|
+
_ngZone = inject(NgZone);
|
|
77
|
+
_actions$ = inject(Actions);
|
|
78
|
+
_options = inject(NGXS_WEBSOCKET_OPTIONS);
|
|
79
|
+
_socket = null;
|
|
80
|
+
_socketClosed$ = new Subject();
|
|
81
|
+
_typeKey = this._options.typeKey;
|
|
82
|
+
_destroyRef = inject(DestroyRef);
|
|
71
83
|
constructor() {
|
|
72
|
-
this._store = inject(Store);
|
|
73
|
-
this._ngZone = inject(NgZone);
|
|
74
|
-
this._actions$ = inject(Actions);
|
|
75
|
-
this._options = inject(NGXS_WEBSOCKET_OPTIONS);
|
|
76
|
-
this._socket = null;
|
|
77
|
-
this._socketClosed$ = new Subject();
|
|
78
|
-
this._typeKey = this._options.typeKey;
|
|
79
|
-
this._destroy$ = new ReplaySubject(1);
|
|
80
84
|
this._setupActionsListeners();
|
|
81
|
-
|
|
82
|
-
destroyRef.onDestroy(() => {
|
|
83
|
-
this._closeConnection(/* forcelyCloseSocket */ true);
|
|
84
|
-
this._destroy$.next();
|
|
85
|
-
});
|
|
85
|
+
this._destroyRef.onDestroy(() => this._closeConnection(/* forcelyCloseSocket */ true));
|
|
86
86
|
}
|
|
87
87
|
_setupActionsListeners() {
|
|
88
88
|
this._actions$
|
|
89
|
-
.pipe(ofActionDispatched(ConnectWebSocket),
|
|
89
|
+
.pipe(ofActionDispatched(ConnectWebSocket), takeUntilDestroyed(this._destroyRef))
|
|
90
90
|
.subscribe(({ payload }) => {
|
|
91
91
|
this.connect(payload);
|
|
92
92
|
});
|
|
93
93
|
this._actions$
|
|
94
|
-
.pipe(ofActionDispatched(DisconnectWebSocket),
|
|
94
|
+
.pipe(ofActionDispatched(DisconnectWebSocket), takeUntilDestroyed(this._destroyRef))
|
|
95
95
|
.subscribe(() => {
|
|
96
96
|
this._disconnect(/* forcelyCloseSocket */ true);
|
|
97
97
|
});
|
|
98
98
|
this._actions$
|
|
99
|
-
.pipe(ofActionDispatched(SendWebSocketMessage),
|
|
99
|
+
.pipe(ofActionDispatched(SendWebSocketMessage), takeUntilDestroyed(this._destroyRef))
|
|
100
100
|
.subscribe(({ payload }) => {
|
|
101
101
|
this.send(payload);
|
|
102
102
|
});
|
|
@@ -198,10 +198,10 @@ class WebSocketHandler {
|
|
|
198
198
|
this._socket = null;
|
|
199
199
|
this._socketClosed$.next();
|
|
200
200
|
}
|
|
201
|
-
/** @nocollapse */ static
|
|
202
|
-
/** @nocollapse */ static
|
|
201
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: WebSocketHandler, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
202
|
+
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: WebSocketHandler, providedIn: 'root' });
|
|
203
203
|
}
|
|
204
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
204
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: WebSocketHandler, decorators: [{
|
|
205
205
|
type: Injectable,
|
|
206
206
|
args: [{ providedIn: 'root' }]
|
|
207
207
|
}], ctorParameters: () => [] });
|
|
@@ -244,11 +244,11 @@ class NgxsWebSocketPluginModule {
|
|
|
244
244
|
providers: ɵgetProviders(options)
|
|
245
245
|
};
|
|
246
246
|
}
|
|
247
|
-
/** @nocollapse */ static
|
|
248
|
-
/** @nocollapse */ static
|
|
249
|
-
/** @nocollapse */ static
|
|
247
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsWebSocketPluginModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
248
|
+
/** @nocollapse */ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.0.3", ngImport: i0, type: NgxsWebSocketPluginModule });
|
|
249
|
+
/** @nocollapse */ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsWebSocketPluginModule });
|
|
250
250
|
}
|
|
251
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
251
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsWebSocketPluginModule, decorators: [{
|
|
252
252
|
type: NgModule
|
|
253
253
|
}] });
|
|
254
254
|
function withNgxsWebSocketPlugin(options) {
|
|
@@ -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/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\nexport const NGXS_WEBSOCKET_OPTIONS = new InjectionToken<NgxsWebSocketPluginOptions>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_WEBSOCKET_OPTIONS' : ''\n);\n\nexport const USER_OPTIONS = new InjectionToken(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'USER_OPTIONS' : ''\n);\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, NgZone, inject, DestroyRef } from '@angular/core';\nimport { Actions, Store, ofActionDispatched } from '@ngxs/store';\nimport { getValue } from '@ngxs/store/plugins';\nimport { ReplaySubject, Subject, fromEvent, takeUntil } from 'rxjs';\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 {\n private _store = inject(Store);\n private _ngZone = inject(NgZone);\n private _actions$ = inject(Actions);\n private _options = inject(NGXS_WEBSOCKET_OPTIONS);\n\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 this._setupActionsListeners();\n\n const destroyRef = inject(DestroyRef);\n destroyRef.onDestroy(() => {\n this._closeConnection(/* forcelyCloseSocket */ true);\n this._destroy$.next();\n });\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/**\n * The private api for consumers of @ngxs/websocket-plugin\n */\nexport * from './src/private_api';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;MAIa,sBAAsB,GAAG,IAAI,cAAc,CACtD,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,GAAG,wBAAwB,GAAG,EAAE;AAGxE,MAAM,YAAY,GAAG,IAAI,cAAc,CAC5C,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,GAAG,cAAc,GAA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../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\nexport const NGXS_WEBSOCKET_OPTIONS = new InjectionToken<NgxsWebSocketPluginOptions>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_WEBSOCKET_OPTIONS' : ''\n);\n\nexport const USER_OPTIONS = new InjectionToken(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'USER_OPTIONS' : ''\n);\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, NgZone, inject, DestroyRef } from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { Actions, Store, ofActionDispatched } from '@ngxs/store';\nimport { getValue } from '@ngxs/store/plugins';\nimport { Subject, fromEvent, takeUntil } from 'rxjs';\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 {\n private _store = inject(Store);\n private _ngZone = inject(NgZone);\n private _actions$ = inject(Actions);\n private _options = inject(NGXS_WEBSOCKET_OPTIONS);\n\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 _destroyRef = inject(DestroyRef);\n\n constructor() {\n this._setupActionsListeners();\n\n this._destroyRef.onDestroy(() => this._closeConnection(/* forcelyCloseSocket */ true));\n }\n\n private _setupActionsListeners(): void {\n this._actions$\n .pipe(ofActionDispatched(ConnectWebSocket), takeUntilDestroyed(this._destroyRef))\n .subscribe(({ payload }) => {\n this.connect(payload);\n });\n\n this._actions$\n .pipe(ofActionDispatched(DisconnectWebSocket), takeUntilDestroyed(this._destroyRef))\n .subscribe(() => {\n this._disconnect(/* forcelyCloseSocket */ true);\n });\n\n this._actions$\n .pipe(ofActionDispatched(SendWebSocketMessage), takeUntilDestroyed(this._destroyRef))\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/**\n * The private api for consumers of @ngxs/websocket-plugin\n */\nexport * from './src/private_api';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;MAIa,sBAAsB,GAAG,IAAI,cAAc,CACtD,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,GAAG,wBAAwB,GAAG,EAAE;AAGxE,MAAM,YAAY,GAAG,IAAI,cAAc,CAC5C,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,GAAG,cAAc,GAAG,EAAE,CACpE;AAoDD;;AAEG;MACU,gBAAgB,CAAA;AAGR,IAAA,OAAA;AAFnB,IAAA,OAAgB,IAAI,GAAG,qBAAqB;AAE5C,IAAA,WAAA,CAAmB,OAAoC,EAAA;QAApC,IAAO,CAAA,OAAA,GAAP,OAAO;;;AAG5B;;AA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,OAAO,EAAE,sBAAsB;AAC/B,YAAA,UAAU,EAAE,wBAAwB;YACpC,IAAI,EAAE,CAAC,YAAY;AACpB,SAAA;AACD,QAAA;AACE,YAAA,OAAO,EAAE,eAAe;AACxB,YAAA,UAAU,EAAE,MAAM,SAAQ;YAC1B,IAAI,EAAE,CAAC,gBAAgB,CAAC;AACxB,YAAA,KAAK,EAAE;AACR;KACF;AACH;;MCxBa,yBAAyB,CAAA;IACpC,OAAO,OAAO,CACZ,OAAoC,EAAA;QAEpC,OAAO;AACL,YAAA,QAAQ,EAAE,yBAAyB;AACnC,YAAA,SAAS,EAAE,aAAa,CAAC,OAAO;SACjC;;0HAPQ,yBAAyB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA;2HAAzB,yBAAyB,EAAA,CAAA;2HAAzB,yBAAyB,EAAA,CAAA;;2FAAzB,yBAAyB,EAAA,UAAA,EAAA,CAAA;kBADrC;;AAYK,SAAU,uBAAuB,CACrC,OAAoC,EAAA;AAEpC,IAAA,OAAO,wBAAwB,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AACzD;;AC1BA;;AAEG;;ACFH;;AAEG;;;;"}
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import {
|
|
2
|
+
import { ModuleWithProviders, EnvironmentProviders, InjectionToken } from '@angular/core';
|
|
3
3
|
|
|
4
4
|
declare const NGXS_WEBSOCKET_OPTIONS: InjectionToken<NgxsWebSocketPluginOptions>;
|
|
5
5
|
interface NgxsWebSocketPluginOptions {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngxs/websocket-plugin",
|
|
3
3
|
"description": "WebSocket plugin for @ngxs/store",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "20.0.0-dev.master-5e7c96c",
|
|
5
5
|
"sideEffects": true,
|
|
6
6
|
"peerDependencies": {
|
|
7
|
-
"@
|
|
8
|
-
"@
|
|
9
|
-
"rxjs": ">=
|
|
7
|
+
"@angular/core": ">=20.0.0 <21.0.0",
|
|
8
|
+
"@ngxs/store": "^20.0.0 || ^20.0.0-dev",
|
|
9
|
+
"rxjs": ">=7.0.0"
|
|
10
10
|
},
|
|
11
11
|
"module": "fesm2022/ngxs-websocket-plugin.mjs",
|
|
12
12
|
"typings": "index.d.ts",
|
|
@@ -66,4 +66,4 @@
|
|
|
66
66
|
"type": "opencollective",
|
|
67
67
|
"url": "https://opencollective.com/ngxs"
|
|
68
68
|
}
|
|
69
|
-
}
|
|
69
|
+
}
|