@typetron/websockets 0.4.0-rc6 → 0.4.0-rc8
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/index.d.ts +8 -8
- package/index.d.ts.map +1 -1
- package/index.js +22 -23
- package/index.js.map +1 -1
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { Observable, ReplaySubject, Subject } from 'rxjs';
|
|
2
|
-
import {
|
|
2
|
+
import { ActionErrorResponse, ActionRequest, ActionResponse } from '@typetron/framework/Router/Websockets/types';
|
|
3
3
|
export declare class Websocket {
|
|
4
4
|
url: string;
|
|
5
5
|
protocols?: string | string[] | undefined;
|
|
6
6
|
socket?: WebSocket;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
errors$: Subject<
|
|
7
|
+
actionMessages$: Subject<ActionResponse<unknown>>;
|
|
8
|
+
queuedActions$: ReplaySubject<ActionRequest>;
|
|
9
|
+
errors$: Subject<ActionErrorResponse>;
|
|
10
10
|
onConnectCallback: () => void;
|
|
11
11
|
constructor(url: string, protocols?: string | string[] | undefined);
|
|
12
12
|
get isConnected(): boolean;
|
|
13
13
|
connect(url?: string, protocols?: string | string[]): void;
|
|
14
14
|
onConnect(callback: () => void): void;
|
|
15
15
|
reconnect(): void;
|
|
16
|
-
emit<T>(
|
|
17
|
-
on<T>(
|
|
16
|
+
emit<T>(action: string, request?: ActionRequest['message']): void;
|
|
17
|
+
on<T>(action: string): Observable<T>;
|
|
18
18
|
onError({ except }: {
|
|
19
19
|
except?: string[];
|
|
20
|
-
}): Observable<
|
|
21
|
-
request<T>(
|
|
20
|
+
}): Observable<ActionResponse<unknown>>;
|
|
21
|
+
request<T>(action: string, message?: ActionRequest['message']): Promise<T>;
|
|
22
22
|
}
|
|
23
23
|
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.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G,OAAO,CAAC,CAAC,CAAC;CASnF"}
|
package/index.js
CHANGED
|
@@ -8,8 +8,8 @@ class Websocket {
|
|
|
8
8
|
constructor(url, protocols) {
|
|
9
9
|
this.url = url;
|
|
10
10
|
this.protocols = protocols;
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
11
|
+
this.actionMessages$ = new rxjs_1.Subject();
|
|
12
|
+
this.queuedActions$ = new rxjs_1.ReplaySubject();
|
|
13
13
|
this.errors$ = new rxjs_1.Subject();
|
|
14
14
|
this.connect(url, protocols);
|
|
15
15
|
}
|
|
@@ -19,18 +19,18 @@ class Websocket {
|
|
|
19
19
|
connect(url, protocols) {
|
|
20
20
|
const socket = new WebSocket(url ?? this.url, protocols ?? this.protocols);
|
|
21
21
|
this.socket = socket;
|
|
22
|
-
socket.onmessage = (
|
|
23
|
-
const message = JSON.parse(
|
|
24
|
-
this.
|
|
22
|
+
socket.onmessage = (action) => {
|
|
23
|
+
const message = JSON.parse(action.data);
|
|
24
|
+
this.actionMessages$.next(message);
|
|
25
25
|
};
|
|
26
26
|
socket.onopen = () => {
|
|
27
27
|
this.onConnectCallback?.();
|
|
28
|
-
this.
|
|
28
|
+
this.queuedActions$.subscribe(message => {
|
|
29
29
|
socket.send(JSON.stringify(message));
|
|
30
30
|
});
|
|
31
31
|
};
|
|
32
|
-
socket.onclose = (
|
|
33
|
-
this.
|
|
32
|
+
socket.onclose = (action) => {
|
|
33
|
+
this.queuedActions$ = new rxjs_1.ReplaySubject();
|
|
34
34
|
this.reconnect();
|
|
35
35
|
};
|
|
36
36
|
}
|
|
@@ -44,27 +44,26 @@ class Websocket {
|
|
|
44
44
|
}, 1000);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
emit(
|
|
48
|
-
const
|
|
49
|
-
this.
|
|
47
|
+
emit(action, request) {
|
|
48
|
+
const actionMessage = { action, message: request };
|
|
49
|
+
this.queuedActions$.next(actionMessage);
|
|
50
50
|
}
|
|
51
|
-
on(
|
|
52
|
-
return this.
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return (0, rxjs_1.throwError)(eventMessage);
|
|
51
|
+
on(action) {
|
|
52
|
+
return this.actionMessages$.pipe((0, operators_1.filter)(actionMessage => actionMessage.action === action), (0, operators_1.switchMap)(actionMessage => {
|
|
53
|
+
if (actionMessage.status === types_1.WebsocketMessageStatus.Error) {
|
|
54
|
+
this.errors$.next(actionMessage);
|
|
55
|
+
return (0, rxjs_1.throwError)(actionMessage);
|
|
57
56
|
}
|
|
58
|
-
return (0, rxjs_1.of)(
|
|
59
|
-
}), (0, operators_1.map)(
|
|
57
|
+
return (0, rxjs_1.of)(actionMessage);
|
|
58
|
+
}), (0, operators_1.map)(actionMessage => actionMessage.message));
|
|
60
59
|
}
|
|
61
60
|
onError({ except }) {
|
|
62
|
-
return this.errors$.pipe((0, operators_1.filter)(
|
|
61
|
+
return this.errors$.pipe((0, operators_1.filter)(actionMessage => !(except || []).includes(actionMessage.action)));
|
|
63
62
|
}
|
|
64
|
-
async request(
|
|
65
|
-
this.emit(
|
|
63
|
+
async request(action, message) {
|
|
64
|
+
this.emit(action, message);
|
|
66
65
|
return new Promise((resolve, reject) => {
|
|
67
|
-
this.on(
|
|
66
|
+
this.on(action).pipe((0, operators_1.take)(1)).subscribe({
|
|
68
67
|
next: resolve,
|
|
69
68
|
error: reject
|
|
70
69
|
});
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,+BAAyE;AACzE,8CAA6D;AAC7D,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,+BAAyE;AACzE,8CAA6D;AAC7D,uEAAwI;AAExI,MAAa,SAAS;IAQlB,YAAmB,GAAW,EAAS,SAA6B;QAAjD,QAAG,GAAH,GAAG,CAAQ;QAAS,cAAS,GAAT,SAAS,CAAoB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CAAC;IAED,KAAK,CAAC,OAAO,CAAI,MAAc,EAAE,OAAkC;QAC/D,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAC1B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACnC,IAAI,CAAC,EAAE,CAAI,MAAM,CAAC,CAAC,IAAI,CAAC,IAAA,gBAAI,EAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;gBACvC,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,MAAM;aAChB,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;IACN,CAAC;CACJ;AAjFD,8BAiFC"}
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"realtime"
|
|
11
11
|
],
|
|
12
12
|
"license": "MIT",
|
|
13
|
-
"version": "0.4.0-
|
|
13
|
+
"version": "0.4.0-rc8",
|
|
14
14
|
"author": {
|
|
15
15
|
"email": "ionel@typetron.org",
|
|
16
16
|
"name": "Ionel Lupu"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"rxjs": "~7.8.1"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@typetron/framework": "0.4.0-
|
|
28
|
+
"@typetron/framework": "0.4.0-rc8"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"typescript": "5.2.2"
|