@casual-simulation/aux-websocket-aws 3.8.2-alpha.19511653187 → 3.10.2
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 +133 -2
- package/package.json +44 -45
package/README.md
CHANGED
|
@@ -1,3 +1,134 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @casual-simulation/aux-websocket-aws
|
|
2
2
|
|
|
3
|
-
AWS API Gateway
|
|
3
|
+
AWS API Gateway WebSocket integration layer for CasualOS (AUX) services, providing specialized handling for AWS API Gateway's WebSocket message size limitations.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides a WebSocket client specifically designed for connecting to CasualOS (AUX) services hosted on AWS API Gateway. It extends the standard WebSocket protocol with automatic large message handling through S3 upload/download mechanisms, working around AWS API Gateway's 32KB message size limit.
|
|
8
|
+
|
|
9
|
+
## Main Export
|
|
10
|
+
|
|
11
|
+
### `ApiGatewayWebsocketConnectionClient`
|
|
12
|
+
|
|
13
|
+
A specialized WebSocket client that implements the `ConnectionClient` interface with AWS API Gateway-specific features, particularly automatic handling of large messages through S3 presigned URLs.
|
|
14
|
+
|
|
15
|
+
**Features:**
|
|
16
|
+
|
|
17
|
+
- **Automatic Large Message Handling**: Messages exceeding 32KB are automatically uploaded to S3 via presigned URLs
|
|
18
|
+
- **Message Size Detection**: Automatically detects when messages exceed AWS API Gateway limits
|
|
19
|
+
- **Upload/Download Protocol**: Implements a custom protocol for transferring large messages via HTTP
|
|
20
|
+
- **Transparent to Application**: Large message handling is completely transparent to the application layer
|
|
21
|
+
- **Connection State Management**: Full connection state tracking via RxJS observables
|
|
22
|
+
- **Error Handling**: Dedicated error stream for connection and protocol errors
|
|
23
|
+
- **Type-Safe**: Built with TypeScript for full type safety
|
|
24
|
+
|
|
25
|
+
**Key Methods:**
|
|
26
|
+
|
|
27
|
+
- `connect()` - Establish WebSocket connection to AWS API Gateway
|
|
28
|
+
- `disconnect()` - Close WebSocket connection
|
|
29
|
+
- `send(message)` - Send a message (automatically handles large messages)
|
|
30
|
+
- `event<T>(name)` - Subscribe to specific event types
|
|
31
|
+
- `connectionState` - Observable of connection state changes
|
|
32
|
+
- `onError` - Observable of error events
|
|
33
|
+
|
|
34
|
+
**Usage:**
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { ApiGatewayWebsocketConnectionClient } from '@casual-simulation/aux-websocket-aws';
|
|
38
|
+
import { ReconnectableSocket } from '@casual-simulation/websocket';
|
|
39
|
+
|
|
40
|
+
// Create underlying WebSocket connection to AWS API Gateway
|
|
41
|
+
const socket = new ReconnectableSocket(
|
|
42
|
+
'wss://your-api-gateway-id.execute-api.region.amazonaws.com/stage'
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
// Create AWS API Gateway-aware client
|
|
46
|
+
const client = new ApiGatewayWebsocketConnectionClient(socket);
|
|
47
|
+
|
|
48
|
+
// Listen for connection state changes
|
|
49
|
+
client.connectionState.subscribe((state) => {
|
|
50
|
+
console.log('Connected:', state.connected);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Listen for specific event types
|
|
54
|
+
client.event('device').subscribe((event) => {
|
|
55
|
+
console.log('Device event:', event);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Handle errors
|
|
59
|
+
client.onError.subscribe((error) => {
|
|
60
|
+
console.error('WebSocket error:', error);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Connect and send messages
|
|
64
|
+
client.connect();
|
|
65
|
+
|
|
66
|
+
// Small messages sent directly through WebSocket
|
|
67
|
+
client.send({
|
|
68
|
+
type: 'login',
|
|
69
|
+
data: { userId: '123' },
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Large messages automatically handled via S3
|
|
73
|
+
client.send({
|
|
74
|
+
type: 'largeData',
|
|
75
|
+
payload: veryLargeDataObject, // Automatically uploaded to S3
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Large Message Handling
|
|
80
|
+
|
|
81
|
+
When a message exceeds the `MAX_MESSAGE_SIZE` (32KB), the client automatically:
|
|
82
|
+
|
|
83
|
+
1. **Requests Upload URL**: Sends an upload request to the server
|
|
84
|
+
2. **Receives Presigned URL**: Server responds with S3 presigned URL
|
|
85
|
+
3. **Uploads to S3**: Client uploads message data to S3 via HTTP
|
|
86
|
+
4. **Requests Download**: Client notifies server of S3 location
|
|
87
|
+
5. **Server Downloads**: Server downloads from S3 and processes message
|
|
88
|
+
|
|
89
|
+
This entire process is transparent to the application - just call `send()` with any size message.
|
|
90
|
+
|
|
91
|
+
## Message Size Limit
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
MAX_MESSAGE_SIZE = 32_000 bytes (32KB)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Messages larger than this threshold trigger the automatic upload/download protocol.
|
|
98
|
+
|
|
99
|
+
## WebSocket Event Protocol
|
|
100
|
+
|
|
101
|
+
The client implements an extended WebSocket event protocol:
|
|
102
|
+
|
|
103
|
+
- `WebsocketEventTypes.Message` - Standard message event
|
|
104
|
+
- `WebsocketEventTypes.UploadRequest` - Request S3 upload URL
|
|
105
|
+
- `WebsocketEventTypes.UploadResponse` - Receive S3 upload URL
|
|
106
|
+
- `WebsocketEventTypes.DownloadRequest` - Request download from S3
|
|
107
|
+
- `WebsocketEventTypes.Error` - Error event
|
|
108
|
+
|
|
109
|
+
## Dependencies
|
|
110
|
+
|
|
111
|
+
- **@casual-simulation/websocket**: Low-level WebSocket management
|
|
112
|
+
- **@casual-simulation/aux-common**: AUX common types and interfaces
|
|
113
|
+
- **axios**: HTTP client for S3 uploads/downloads
|
|
114
|
+
- **rxjs**: Observable-based event handling
|
|
115
|
+
|
|
116
|
+
## Installation
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
npm install @casual-simulation/aux-websocket-aws
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## When to Use This Package
|
|
123
|
+
|
|
124
|
+
Use this package when:
|
|
125
|
+
|
|
126
|
+
- Connecting to CasualOS services hosted on AWS API Gateway
|
|
127
|
+
- You need to send messages that may exceed 32KB
|
|
128
|
+
- You want transparent large message handling
|
|
129
|
+
|
|
130
|
+
Use `@casual-simulation/aux-websocket` instead when:
|
|
131
|
+
|
|
132
|
+
- Connecting to non-AWS WebSocket endpoints
|
|
133
|
+
- All messages are guaranteed to be under 32KB
|
|
134
|
+
- You don't need AWS-specific features
|
package/package.json
CHANGED
|
@@ -1,46 +1,45 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
2
|
+
"name": "@casual-simulation/aux-websocket-aws",
|
|
3
|
+
"version": "3.10.2",
|
|
4
|
+
"description": "AWS API Gateway Websocket integration with AUX services",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"author": "Casual Simulation, Inc.",
|
|
7
|
+
"homepage": "https://github.com/casual-simulation/casualos",
|
|
8
|
+
"license": "AGPL-3.0-only",
|
|
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
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/casual-simulation/casualos/issues"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@casual-simulation/aux-common": "^3.10.2",
|
|
34
|
+
"@casual-simulation/websocket": "^3.10.2",
|
|
35
|
+
"axios": "1.7.7",
|
|
36
|
+
"rxjs": "8.0.0-alpha.14"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"watch": "tsc --watch",
|
|
40
|
+
"watch:player": "npm run watch",
|
|
41
|
+
"build": "echo \"Nothing to do.\"",
|
|
42
|
+
"test": "jest",
|
|
43
|
+
"test:watch": "jest --watchAll"
|
|
44
|
+
}
|
|
45
|
+
}
|