@caitdesk/client 0.5.0 → 0.5.1
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 +39 -18
- package/package.json +19 -2
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ const client = new CaitDeskClient({
|
|
|
51
51
|
|
|
52
52
|
// Subscribe to an event's broadcast
|
|
53
53
|
await client.subscribe('event-id', {
|
|
54
|
-
onCaption: (text, seq) => console.log('Caption:', text),
|
|
54
|
+
onCaption: (text, seq, meta) => console.log('Caption:', text, meta?.latency),
|
|
55
55
|
onStatus: (status) => console.log('Event status:', status),
|
|
56
56
|
onViewerCount: (count) => console.log('Viewers:', count),
|
|
57
57
|
onError: (err) => console.error('Error:', err.message),
|
|
@@ -116,17 +116,6 @@ client.startEvent(eventId: string): Promise<{ success: boolean }>
|
|
|
116
116
|
client.stopEvent(eventId: string): Promise<{ success: boolean }>
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
-
### Standalone Functions
|
|
120
|
-
|
|
121
|
-
#### `checkEvent(apiUrl, eventId, fetchFn?)`
|
|
122
|
-
|
|
123
|
-
Public endpoint — no API key required. Returns `{ exists: boolean; joinable: boolean }`. Useful for validating an event ID before attempting a WebSocket connection. On network errors, returns `{ exists: false, joinable: false }`.
|
|
124
|
-
|
|
125
|
-
- `getMe()` — returns the authenticated user's info
|
|
126
|
-
- `getEvents()` — returns events assigned to you as captioner (scheduled and live only)
|
|
127
|
-
- `startEvent(eventId)` — start an event via REST (scheduled → live). Requires `captioner:control` scope
|
|
128
|
-
- `stopEvent(eventId)` — stop an event via REST (live → ended). Requires `captioner:control` scope
|
|
129
|
-
|
|
130
119
|
#### Connection
|
|
131
120
|
|
|
132
121
|
```ts
|
|
@@ -176,7 +165,7 @@ client.unsubscribe(): void
|
|
|
176
165
|
|
|
177
166
|
```ts
|
|
178
167
|
await client.subscribe(eventId, {
|
|
179
|
-
onCaption: (text, seq) => console.log('Caption:', text),
|
|
168
|
+
onCaption: (text, seq, meta) => console.log('Caption:', text, meta?.latency),
|
|
180
169
|
onStatus: (status) => console.log('Event status:', status),
|
|
181
170
|
onViewerCount: (count) => console.log('Viewers:', count),
|
|
182
171
|
onError: (err) => console.error('Error:', err.message),
|
|
@@ -190,6 +179,12 @@ client.unsubscribe();
|
|
|
190
179
|
|
|
191
180
|
The captioner connection (`connect`/`disconnect`) and broadcast subscription (`subscribe`/`unsubscribe`) are fully independent and can run simultaneously.
|
|
192
181
|
|
|
182
|
+
### Standalone Functions
|
|
183
|
+
|
|
184
|
+
#### `checkEvent(apiUrl, eventId, fetchFn?)`
|
|
185
|
+
|
|
186
|
+
Public endpoint — no API key required. Returns `{ exists: boolean; joinable: boolean }`. Useful for validating an event ID before attempting a WebSocket connection. On network errors, returns `{ exists: false, joinable: false }`.
|
|
187
|
+
|
|
193
188
|
### Configuration
|
|
194
189
|
|
|
195
190
|
```ts
|
|
@@ -232,15 +227,33 @@ interface User { id: string; email: string; name: string | null }
|
|
|
232
227
|
interface Event { id: string; organizationId: string; title: string; description: string | null; scheduledStart: string; scheduledEnd: string | null; status: string; clientName: string | null }
|
|
233
228
|
interface CaptionAck { type: 'ack'; timestamp: number; seq: number }
|
|
234
229
|
interface ControlAck { type: 'ack'; action: string }
|
|
235
|
-
interface ServerError { type: 'error'; code:
|
|
230
|
+
interface ServerError { type: 'error'; code: ErrorCodeValue; message: string; details?: Record<string, unknown> }
|
|
236
231
|
interface SlotDetail { position?: number; activeSince?: string }
|
|
237
232
|
```
|
|
238
233
|
|
|
234
|
+
#### Utility types
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
type ConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'reconnecting'
|
|
238
|
+
type SlotStatus = 'unknown' | 'active' | 'waiting'
|
|
239
|
+
type ControlActionValue = (typeof CONTROL_ACTION)[keyof typeof CONTROL_ACTION]
|
|
240
|
+
type ErrorCodeValue = (typeof ERROR_CODE)[keyof typeof ERROR_CODE]
|
|
241
|
+
interface EventCheckResult { exists: boolean; joinable: boolean }
|
|
242
|
+
```
|
|
243
|
+
|
|
239
244
|
#### Broadcast types
|
|
240
245
|
|
|
246
|
+
```ts
|
|
247
|
+
interface BroadcastCaptionMessage { type: 'caption'; eventId: string; seq: number; text: string; ts?: number; lineTs?: number[] }
|
|
248
|
+
interface BroadcastStatusMessage { type: 'status'; eventId: string; status: string; scheduledStart?: string }
|
|
249
|
+
interface BroadcastViewerCountMessage { type: 'viewers'; eventId: string; count: number }
|
|
250
|
+
interface BroadcastEventEndedMessage { type: 'event_ended'; eventId: string; message: string }
|
|
251
|
+
type BroadcastMessage = BroadcastCaptionMessage | BroadcastStatusMessage | BroadcastViewerCountMessage | BroadcastEventEndedMessage | ServerError
|
|
252
|
+
```
|
|
253
|
+
|
|
241
254
|
```ts
|
|
242
255
|
interface SubscribeConfig {
|
|
243
|
-
onCaption?: (text: string, seq: number) => void;
|
|
256
|
+
onCaption?: (text: string, seq: number, meta?: { ts?: number; lineTs?: number[]; latency?: number }) => void;
|
|
244
257
|
onStatus?: (status: string, detail?: { scheduledStart?: string }) => void;
|
|
245
258
|
onViewerCount?: (count: number) => void;
|
|
246
259
|
onError?: (error: ServerError) => void;
|
|
@@ -251,7 +264,7 @@ interface SubscribeConfig {
|
|
|
251
264
|
|
|
252
265
|
| Callback | When it fires |
|
|
253
266
|
| ---------------- | ------------------------------------------------------- |
|
|
254
|
-
| `onCaption` | New caption text received (full text state + seq)
|
|
267
|
+
| `onCaption` | New caption text received (full text state + seq + optional meta with `ts`, `lineTs`, `latency`) |
|
|
255
268
|
| `onStatus` | Event status changes (waiting/live/ended) |
|
|
256
269
|
| `onViewerCount` | Viewer count updates |
|
|
257
270
|
| `onError` | Server sends an error message |
|
|
@@ -261,10 +274,18 @@ interface SubscribeConfig {
|
|
|
261
274
|
### Constants
|
|
262
275
|
|
|
263
276
|
```ts
|
|
264
|
-
import { EVENT_STATUS, ERROR_CODE, RATE_LIMITS, CONNECTION_DEFAULTS } from '@caitdesk/client';
|
|
277
|
+
import { EVENT_STATUS, ERROR_CODE, RATE_LIMITS, CONNECTION_DEFAULTS, SESSION_ACTION, CONTROL_ACTION, WS_CLOSE_CODE } from '@caitdesk/client';
|
|
265
278
|
```
|
|
266
279
|
|
|
267
|
-
|
|
280
|
+
| Constant | Description |
|
|
281
|
+
|----------|-------------|
|
|
282
|
+
| `EVENT_STATUS` | Event status values (`DRAFT`, `SCHEDULED`, `LIVE`, `ENDED`, `ARCHIVED`, `CANCELLED`) |
|
|
283
|
+
| `ERROR_CODE` | Error codes from the API and gateway (auth, validation, WebSocket, rate limiting) |
|
|
284
|
+
| `RATE_LIMITS` | Gateway-enforced limits (max message rate, text lengths, timestamp drift) |
|
|
285
|
+
| `CONNECTION_DEFAULTS` | Reconnect timing (initial delay, max delay, multiplier, request timeout) |
|
|
286
|
+
| `SESSION_ACTION` | Slot management actions (`SLOT_GRANTED`, `SLOT_OCCUPIED`, `SLOT_REQUESTED`, `SLOT_REQUEST_CANCELLED`, `SLOT_RELEASE`) |
|
|
287
|
+
| `CONTROL_ACTION` | Event control actions (`START`, `STOP`, `PAUSE`, `RESUME`) |
|
|
288
|
+
| `WS_CLOSE_CODE` | WebSocket close codes with special meaning (`NORMAL`, `AUTH_FAILED`, `SLOT_FULL`) |
|
|
268
289
|
|
|
269
290
|
## API Key Scopes
|
|
270
291
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caitdesk/client",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Official TypeScript client for the CaitDesk captioner API",
|
|
6
6
|
"exports": {
|
|
@@ -26,5 +26,22 @@
|
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"typescript": "^5.7.2"
|
|
29
|
-
}
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"license": "Proprietary",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/caitdesk/caitdesk",
|
|
37
|
+
"directory": "packages/caitdesk-client"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"caitdesk",
|
|
41
|
+
"captions",
|
|
42
|
+
"captioner",
|
|
43
|
+
"client",
|
|
44
|
+
"websocket",
|
|
45
|
+
"real-time"
|
|
46
|
+
]
|
|
30
47
|
}
|