@casual-simulation/aux-websocket 3.2.7-alpha.6226622763
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/LICENSE.txt +21 -0
- package/README.md +3 -0
- package/WebsocketConnectionClient.d.ts +18 -0
- package/WebsocketConnectionClient.js +66 -0
- package/WebsocketConnectionClient.js.map +1 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/index.js.map +1 -0
- package/package.json +45 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Casual Simulation, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { ReconnectableSocketInterface } from '@casual-simulation/websocket';
|
|
3
|
+
import { ConnectionClient, ClientConnectionState, WebsocketMessage, ConnectionInfo } from '@casual-simulation/aux-common';
|
|
4
|
+
export declare class WebsocketConnectionClient implements ConnectionClient {
|
|
5
|
+
private _socket;
|
|
6
|
+
private _connectionStateChanged;
|
|
7
|
+
private _events;
|
|
8
|
+
private _requestCounter;
|
|
9
|
+
get info(): ConnectionInfo;
|
|
10
|
+
event<T>(name: string): Observable<T>;
|
|
11
|
+
disconnect(): void;
|
|
12
|
+
connect(): void;
|
|
13
|
+
send(message: WebsocketMessage): void;
|
|
14
|
+
constructor(socket: ReconnectableSocketInterface);
|
|
15
|
+
get connectionState(): Observable<ClientConnectionState>;
|
|
16
|
+
get isConnected(): boolean;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=WebsocketConnectionClient.d.ts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { BehaviorSubject, merge, } from 'rxjs';
|
|
2
|
+
import { map, tap, filter, share, } from 'rxjs/operators';
|
|
3
|
+
import { WebsocketEventTypes, } from '@casual-simulation/aux-common';
|
|
4
|
+
export class WebsocketConnectionClient {
|
|
5
|
+
get info() {
|
|
6
|
+
return this._connectionStateChanged.value.info;
|
|
7
|
+
}
|
|
8
|
+
event(name) {
|
|
9
|
+
return this._events.pipe(filter(([type, requestId, message]) => message.type === name), map(([type, requestId, message]) => message));
|
|
10
|
+
}
|
|
11
|
+
disconnect() {
|
|
12
|
+
this._socket.close();
|
|
13
|
+
}
|
|
14
|
+
connect() {
|
|
15
|
+
this._socket.open();
|
|
16
|
+
}
|
|
17
|
+
send(message) {
|
|
18
|
+
this._requestCounter++;
|
|
19
|
+
socketEmit(this._socket, this._requestCounter, message);
|
|
20
|
+
}
|
|
21
|
+
constructor(socket) {
|
|
22
|
+
this._requestCounter = 0;
|
|
23
|
+
this._socket = socket;
|
|
24
|
+
this._connectionStateChanged =
|
|
25
|
+
new BehaviorSubject({
|
|
26
|
+
connected: false,
|
|
27
|
+
info: null,
|
|
28
|
+
});
|
|
29
|
+
this._events = socketEvents(this._socket);
|
|
30
|
+
const connected = this._socket.onOpen.pipe(tap(() => console.log('[ApiaryConnectionClient] Connected.')), map(() => ({
|
|
31
|
+
connected: true,
|
|
32
|
+
info: null,
|
|
33
|
+
})));
|
|
34
|
+
const disconnected = this._socket.onClose.pipe(tap((reason) => console.log('[SocketManger] Disconnected. Reason:', reason)), map(() => ({
|
|
35
|
+
connected: false,
|
|
36
|
+
info: null,
|
|
37
|
+
})));
|
|
38
|
+
merge(connected, disconnected).subscribe(this._connectionStateChanged);
|
|
39
|
+
}
|
|
40
|
+
get connectionState() {
|
|
41
|
+
return this._connectionStateChanged;
|
|
42
|
+
}
|
|
43
|
+
get isConnected() {
|
|
44
|
+
return this._connectionStateChanged.value.connected;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function socketEmit(socket, requestId, message) {
|
|
48
|
+
let event = [
|
|
49
|
+
WebsocketEventTypes.Message,
|
|
50
|
+
requestId,
|
|
51
|
+
message,
|
|
52
|
+
];
|
|
53
|
+
socket.send(JSON.stringify(event));
|
|
54
|
+
}
|
|
55
|
+
function socketEvents(socket) {
|
|
56
|
+
return socket.onMessage.pipe(map((message) => safeParse(message.data)), filter((data) => !!data && Array.isArray(data) && data.length >= 3), share());
|
|
57
|
+
}
|
|
58
|
+
function safeParse(json) {
|
|
59
|
+
try {
|
|
60
|
+
return JSON.parse(json);
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=WebsocketConnectionClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebsocketConnectionClient.js","sourceRoot":"","sources":["WebsocketConnectionClient.ts"],"names":[],"mappings":"AAAA,OAAO,E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C,CAAC,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,EACnE,KAAK,EAAE,CACV,CAAC;AACN,CAAC;AAED,SAAS,SAAS,CAAC,IAAY;IAC3B,IAAI;QACA,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;KAC3B;IAAC,OAAO,GAAG,EAAE;QACV,OAAO,IAAI,CAAC;KACf;AACL,CAAC"}
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@casual-simulation/aux-websocket",
|
|
3
|
+
"version": "3.2.7-alpha.6226622763",
|
|
4
|
+
"description": "Websocket integration with AUX services",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"author": "Casual Simulation, Inc.",
|
|
7
|
+
"homepage": "https://github.com/casual-simulation/casualos",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"main": "index.js",
|
|
10
|
+
"types": "index.d.ts",
|
|
11
|
+
"module": "index",
|
|
12
|
+
"directories": {
|
|
13
|
+
"lib": "."
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"/README.md",
|
|
17
|
+
"/LICENSE.txt",
|
|
18
|
+
"**/*.js",
|
|
19
|
+
"**/*.js.map",
|
|
20
|
+
"**/*.d.ts"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/casual-simulation/casualos.git"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"watch": "tsc --watch",
|
|
28
|
+
"watch:player": "npm run watch",
|
|
29
|
+
"build": "echo \"Nothing to do.\"",
|
|
30
|
+
"test": "jest",
|
|
31
|
+
"test:watch": "jest --watchAll"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/casual-simulation/casualos/issues"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@casual-simulation/aux-common": "^3.2.7-alpha.6226622763",
|
|
41
|
+
"@casual-simulation/websocket": "^3.1.11",
|
|
42
|
+
"rxjs": "7.5.7"
|
|
43
|
+
},
|
|
44
|
+
"gitHead": "90c8d333924255b93b9654dc100fc74181b6138b"
|
|
45
|
+
}
|