@ceralive/cerastream 2026.6.0-rc.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 +88 -0
- package/dist/client.d.ts +58 -0
- package/dist/client.js +274 -0
- package/dist/config.d.ts +16 -0
- package/dist/config.js +54 -0
- package/dist/constants.d.ts +31 -0
- package/dist/constants.js +35 -0
- package/dist/envelope.d.ts +49 -0
- package/dist/envelope.js +52 -0
- package/dist/errors.d.ts +71 -0
- package/dist/errors.js +95 -0
- package/dist/events.d.ts +334 -0
- package/dist/events.js +97 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +13 -0
- package/dist/messages.d.ts +394 -0
- package/dist/messages.js +152 -0
- package/dist/paths.d.ts +14 -0
- package/dist/paths.js +72 -0
- package/dist/transport.d.ts +30 -0
- package/dist/transport.js +98 -0
- package/dist/types.d.ts +110 -0
- package/dist/types.js +69 -0
- package/package.json +41 -0
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Thrown by every contract-stub function body (Task 17). The schema in this
|
|
4
|
+
* package is real and frozen; the IPC client/transport is implemented in Task 31.
|
|
5
|
+
* Every stub throws this so callers fail loud and honest, never silently no-op.
|
|
6
|
+
*/
|
|
7
|
+
export declare class NotImplementedError extends Error {
|
|
8
|
+
constructor(symbol: string);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Thrown when the engine returns a JSON-RPC error response (Task 31). Carries the
|
|
12
|
+
* numeric JSON-RPC code, the stable string `data.code` (a {@link RpcErrorCode}
|
|
13
|
+
* when it is a member of the frozen Tier-1 enum, or a transport-tier protocol
|
|
14
|
+
* string such as `cerastream.protocol.parse_error`), and the human message.
|
|
15
|
+
*/
|
|
16
|
+
export declare class CerastreamRpcError extends Error {
|
|
17
|
+
/** Numeric JSON-RPC `error.code`. */
|
|
18
|
+
readonly code: number;
|
|
19
|
+
/** Stable string `error.data.code`, when the server supplied one. */
|
|
20
|
+
readonly dataCode: string | undefined;
|
|
21
|
+
/** The request id this error answered, when present. */
|
|
22
|
+
readonly requestId: number | string | null;
|
|
23
|
+
constructor(code: number, message: string, dataCode: string | undefined, requestId: number | string | null);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Thrown when the control connection is lost (socket closed/errored) while a
|
|
27
|
+
* request was in flight, or when {@link connect} cannot reach the engine and
|
|
28
|
+
* auto-reconnect is disabled.
|
|
29
|
+
*/
|
|
30
|
+
export declare class CerastreamConnectionError extends Error {
|
|
31
|
+
/** The underlying transport error, when there was one. */
|
|
32
|
+
readonly cause: unknown;
|
|
33
|
+
constructor(message: string, cause?: unknown);
|
|
34
|
+
}
|
|
35
|
+
/** Thrown when a request exceeds the configured per-request timeout. */
|
|
36
|
+
export declare class CerastreamTimeoutError extends Error {
|
|
37
|
+
constructor(method: string, timeoutMs: number);
|
|
38
|
+
}
|
|
39
|
+
export declare const rpcErrorCodeSchema: z.ZodEnum<{
|
|
40
|
+
"cerastream.protocol.unsupported_version": "cerastream.protocol.unsupported_version";
|
|
41
|
+
"cerastream.params.invalid": "cerastream.params.invalid";
|
|
42
|
+
"cerastream.state.not_streaming": "cerastream.state.not_streaming";
|
|
43
|
+
"cerastream.state.already_streaming": "cerastream.state.already_streaming";
|
|
44
|
+
"cerastream.device.not_found": "cerastream.device.not_found";
|
|
45
|
+
"cerastream.bitrate.out_of_range": "cerastream.bitrate.out_of_range";
|
|
46
|
+
"cerastream.preview.unsupported_tier": "cerastream.preview.unsupported_tier";
|
|
47
|
+
"cerastream.internal": "cerastream.internal";
|
|
48
|
+
}>;
|
|
49
|
+
export type RpcErrorCode = z.infer<typeof rpcErrorCodeSchema>;
|
|
50
|
+
/**
|
|
51
|
+
* Numeric JSON-RPC `error.code` for each Tier 1 string code (schema.md Error
|
|
52
|
+
* codes table). `-32000…-32099` is the JSON-RPC application range; `-32602` /
|
|
53
|
+
* `-32603` are the reserved invalid-params / internal-error codes.
|
|
54
|
+
*/
|
|
55
|
+
export declare const RPC_ERROR_NUMERIC: Readonly<Record<RpcErrorCode, number>>;
|
|
56
|
+
export declare const processErrorCodeSchema: z.ZodEnum<{
|
|
57
|
+
srtla_initial_connect_failed: "srtla_initial_connect_failed";
|
|
58
|
+
srtla_no_connections: "srtla_no_connections";
|
|
59
|
+
capture_audio_error: "capture_audio_error";
|
|
60
|
+
capture_video_error: "capture_video_error";
|
|
61
|
+
pipeline_stall: "pipeline_stall";
|
|
62
|
+
srt_connect_failed: "srt_connect_failed";
|
|
63
|
+
srt_connection_lost: "srt_connection_lost";
|
|
64
|
+
}>;
|
|
65
|
+
export type ProcessErrorCode = z.infer<typeof processErrorCodeSchema>;
|
|
66
|
+
/** Origin of a Tier 2 runtime error (the notification channel CeraUI routes on). */
|
|
67
|
+
export declare const processErrorSourceSchema: z.ZodEnum<{
|
|
68
|
+
srtla: "srtla";
|
|
69
|
+
engine: "engine";
|
|
70
|
+
}>;
|
|
71
|
+
export type ProcessErrorSource = z.infer<typeof processErrorSourceSchema>;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Thrown by every contract-stub function body (Task 17). The schema in this
|
|
4
|
+
* package is real and frozen; the IPC client/transport is implemented in Task 31.
|
|
5
|
+
* Every stub throws this so callers fail loud and honest, never silently no-op.
|
|
6
|
+
*/
|
|
7
|
+
export class NotImplementedError extends Error {
|
|
8
|
+
constructor(symbol) {
|
|
9
|
+
super(`${symbol}: not yet implemented`);
|
|
10
|
+
this.name = "NotImplementedError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Thrown when the engine returns a JSON-RPC error response (Task 31). Carries the
|
|
15
|
+
* numeric JSON-RPC code, the stable string `data.code` (a {@link RpcErrorCode}
|
|
16
|
+
* when it is a member of the frozen Tier-1 enum, or a transport-tier protocol
|
|
17
|
+
* string such as `cerastream.protocol.parse_error`), and the human message.
|
|
18
|
+
*/
|
|
19
|
+
export class CerastreamRpcError extends Error {
|
|
20
|
+
/** Numeric JSON-RPC `error.code`. */
|
|
21
|
+
code;
|
|
22
|
+
/** Stable string `error.data.code`, when the server supplied one. */
|
|
23
|
+
dataCode;
|
|
24
|
+
/** The request id this error answered, when present. */
|
|
25
|
+
requestId;
|
|
26
|
+
constructor(code, message, dataCode, requestId) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.name = "CerastreamRpcError";
|
|
29
|
+
this.code = code;
|
|
30
|
+
this.dataCode = dataCode;
|
|
31
|
+
this.requestId = requestId;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Thrown when the control connection is lost (socket closed/errored) while a
|
|
36
|
+
* request was in flight, or when {@link connect} cannot reach the engine and
|
|
37
|
+
* auto-reconnect is disabled.
|
|
38
|
+
*/
|
|
39
|
+
export class CerastreamConnectionError extends Error {
|
|
40
|
+
/** The underlying transport error, when there was one. */
|
|
41
|
+
cause;
|
|
42
|
+
constructor(message, cause) {
|
|
43
|
+
super(message);
|
|
44
|
+
this.name = "CerastreamConnectionError";
|
|
45
|
+
this.cause = cause;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Thrown when a request exceeds the configured per-request timeout. */
|
|
49
|
+
export class CerastreamTimeoutError extends Error {
|
|
50
|
+
constructor(method, timeoutMs) {
|
|
51
|
+
super(`request \`${method}\` timed out after ${timeoutMs}ms`);
|
|
52
|
+
this.name = "CerastreamTimeoutError";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// ---- Tier 1: synchronous RPC errors (error response) ----
|
|
56
|
+
// Stable string `error.data.code` namespaced cerastream.<domain>.<reason>.
|
|
57
|
+
export const rpcErrorCodeSchema = z.enum([
|
|
58
|
+
"cerastream.protocol.unsupported_version",
|
|
59
|
+
"cerastream.params.invalid",
|
|
60
|
+
"cerastream.state.not_streaming",
|
|
61
|
+
"cerastream.state.already_streaming",
|
|
62
|
+
"cerastream.device.not_found",
|
|
63
|
+
"cerastream.bitrate.out_of_range",
|
|
64
|
+
"cerastream.preview.unsupported_tier",
|
|
65
|
+
"cerastream.internal",
|
|
66
|
+
]);
|
|
67
|
+
/**
|
|
68
|
+
* Numeric JSON-RPC `error.code` for each Tier 1 string code (schema.md Error
|
|
69
|
+
* codes table). `-32000…-32099` is the JSON-RPC application range; `-32602` /
|
|
70
|
+
* `-32603` are the reserved invalid-params / internal-error codes.
|
|
71
|
+
*/
|
|
72
|
+
export const RPC_ERROR_NUMERIC = {
|
|
73
|
+
"cerastream.protocol.unsupported_version": -32000,
|
|
74
|
+
"cerastream.params.invalid": -32602,
|
|
75
|
+
"cerastream.state.not_streaming": -32001,
|
|
76
|
+
"cerastream.state.already_streaming": -32002,
|
|
77
|
+
"cerastream.device.not_found": -32003,
|
|
78
|
+
"cerastream.bitrate.out_of_range": -32004,
|
|
79
|
+
"cerastream.preview.unsupported_tier": -32005,
|
|
80
|
+
"cerastream.internal": -32603,
|
|
81
|
+
};
|
|
82
|
+
// ---- Tier 2: asynchronous runtime error-event codes ----
|
|
83
|
+
// Maps 1:1 onto CeraUI's PROCESS_ERROR_CODES (the TRANSITIONAL stderr table) so
|
|
84
|
+
// Task 32 is a table swap, not a rewrite (ADR-0002 Error-Code Namespace).
|
|
85
|
+
export const processErrorCodeSchema = z.enum([
|
|
86
|
+
"srtla_initial_connect_failed",
|
|
87
|
+
"srtla_no_connections",
|
|
88
|
+
"capture_audio_error",
|
|
89
|
+
"capture_video_error",
|
|
90
|
+
"pipeline_stall",
|
|
91
|
+
"srt_connect_failed",
|
|
92
|
+
"srt_connection_lost",
|
|
93
|
+
]);
|
|
94
|
+
/** Origin of a Tier 2 runtime error (the notification channel CeraUI routes on). */
|
|
95
|
+
export const processErrorSourceSchema = z.enum(["srtla", "engine"]);
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const statusEventSchema: z.ZodObject<{
|
|
3
|
+
type: z.ZodLiteral<"status">;
|
|
4
|
+
seq: z.ZodNumber;
|
|
5
|
+
state: z.ZodEnum<{
|
|
6
|
+
idle: "idle";
|
|
7
|
+
starting: "starting";
|
|
8
|
+
streaming: "streaming";
|
|
9
|
+
stopping: "stopping";
|
|
10
|
+
}>;
|
|
11
|
+
streaming: z.ZodBoolean;
|
|
12
|
+
active_input: z.ZodOptional<z.ZodString>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
export type StatusEvent = z.infer<typeof statusEventSchema>;
|
|
15
|
+
export declare const switchEventSchema: z.ZodObject<{
|
|
16
|
+
type: z.ZodLiteral<"switch">;
|
|
17
|
+
seq: z.ZodNumber;
|
|
18
|
+
active_input: z.ZodString;
|
|
19
|
+
mode: z.ZodEnum<{
|
|
20
|
+
manual: "manual";
|
|
21
|
+
auto: "auto";
|
|
22
|
+
}>;
|
|
23
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
export type SwitchEvent = z.infer<typeof switchEventSchema>;
|
|
26
|
+
export declare const deviceEventSchema: z.ZodObject<{
|
|
27
|
+
type: z.ZodLiteral<"device">;
|
|
28
|
+
seq: z.ZodNumber;
|
|
29
|
+
change: z.ZodEnum<{
|
|
30
|
+
added: "added";
|
|
31
|
+
removed: "removed";
|
|
32
|
+
}>;
|
|
33
|
+
device: z.ZodObject<{
|
|
34
|
+
input_id: z.ZodString;
|
|
35
|
+
device_path: z.ZodString;
|
|
36
|
+
display_name: z.ZodString;
|
|
37
|
+
media_class: z.ZodEnum<{
|
|
38
|
+
video: "video";
|
|
39
|
+
audio: "audio";
|
|
40
|
+
}>;
|
|
41
|
+
caps: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
42
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
43
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
44
|
+
framerate: z.ZodOptional<z.ZodString>;
|
|
45
|
+
}, z.core.$strip>>>;
|
|
46
|
+
}, z.core.$strip>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
export type DeviceEvent = z.infer<typeof deviceEventSchema>;
|
|
49
|
+
export declare const bitrateEventSchema: z.ZodObject<{
|
|
50
|
+
type: z.ZodLiteral<"bitrate">;
|
|
51
|
+
seq: z.ZodNumber;
|
|
52
|
+
current_bitrate: z.ZodNumber;
|
|
53
|
+
max_bitrate: z.ZodNumber;
|
|
54
|
+
}, z.core.$strip>;
|
|
55
|
+
export type BitrateEvent = z.infer<typeof bitrateEventSchema>;
|
|
56
|
+
export declare const srtStatsEventSchema: z.ZodObject<{
|
|
57
|
+
type: z.ZodLiteral<"srt-stats">;
|
|
58
|
+
seq: z.ZodNumber;
|
|
59
|
+
rtt_ms: z.ZodNumber;
|
|
60
|
+
send_buffer: z.ZodNumber;
|
|
61
|
+
pkt_loss: z.ZodNumber;
|
|
62
|
+
}, z.core.$strip>;
|
|
63
|
+
export type SrtStatsEvent = z.infer<typeof srtStatsEventSchema>;
|
|
64
|
+
export declare const runtimeErrorEventSchema: z.ZodObject<{
|
|
65
|
+
type: z.ZodLiteral<"error">;
|
|
66
|
+
seq: z.ZodNumber;
|
|
67
|
+
code: z.ZodEnum<{
|
|
68
|
+
srtla_initial_connect_failed: "srtla_initial_connect_failed";
|
|
69
|
+
srtla_no_connections: "srtla_no_connections";
|
|
70
|
+
capture_audio_error: "capture_audio_error";
|
|
71
|
+
capture_video_error: "capture_video_error";
|
|
72
|
+
pipeline_stall: "pipeline_stall";
|
|
73
|
+
srt_connect_failed: "srt_connect_failed";
|
|
74
|
+
srt_connection_lost: "srt_connection_lost";
|
|
75
|
+
}>;
|
|
76
|
+
source: z.ZodEnum<{
|
|
77
|
+
srtla: "srtla";
|
|
78
|
+
engine: "engine";
|
|
79
|
+
}>;
|
|
80
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
81
|
+
}, z.core.$strip>;
|
|
82
|
+
export type RuntimeErrorEvent = z.infer<typeof runtimeErrorEventSchema>;
|
|
83
|
+
export declare const previewEventSchema: z.ZodObject<{
|
|
84
|
+
type: z.ZodLiteral<"preview">;
|
|
85
|
+
seq: z.ZodNumber;
|
|
86
|
+
session_id: z.ZodString;
|
|
87
|
+
phase: z.ZodString;
|
|
88
|
+
}, z.core.$strip>;
|
|
89
|
+
export type PreviewEvent = z.infer<typeof previewEventSchema>;
|
|
90
|
+
/** Discriminated union of every v1 event payload (the inner `params`). */
|
|
91
|
+
export declare const eventParamsSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
92
|
+
type: z.ZodLiteral<"status">;
|
|
93
|
+
seq: z.ZodNumber;
|
|
94
|
+
state: z.ZodEnum<{
|
|
95
|
+
idle: "idle";
|
|
96
|
+
starting: "starting";
|
|
97
|
+
streaming: "streaming";
|
|
98
|
+
stopping: "stopping";
|
|
99
|
+
}>;
|
|
100
|
+
streaming: z.ZodBoolean;
|
|
101
|
+
active_input: z.ZodOptional<z.ZodString>;
|
|
102
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
103
|
+
type: z.ZodLiteral<"switch">;
|
|
104
|
+
seq: z.ZodNumber;
|
|
105
|
+
active_input: z.ZodString;
|
|
106
|
+
mode: z.ZodEnum<{
|
|
107
|
+
manual: "manual";
|
|
108
|
+
auto: "auto";
|
|
109
|
+
}>;
|
|
110
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
111
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
112
|
+
type: z.ZodLiteral<"device">;
|
|
113
|
+
seq: z.ZodNumber;
|
|
114
|
+
change: z.ZodEnum<{
|
|
115
|
+
added: "added";
|
|
116
|
+
removed: "removed";
|
|
117
|
+
}>;
|
|
118
|
+
device: z.ZodObject<{
|
|
119
|
+
input_id: z.ZodString;
|
|
120
|
+
device_path: z.ZodString;
|
|
121
|
+
display_name: z.ZodString;
|
|
122
|
+
media_class: z.ZodEnum<{
|
|
123
|
+
video: "video";
|
|
124
|
+
audio: "audio";
|
|
125
|
+
}>;
|
|
126
|
+
caps: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
127
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
128
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
129
|
+
framerate: z.ZodOptional<z.ZodString>;
|
|
130
|
+
}, z.core.$strip>>>;
|
|
131
|
+
}, z.core.$strip>;
|
|
132
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
133
|
+
type: z.ZodLiteral<"bitrate">;
|
|
134
|
+
seq: z.ZodNumber;
|
|
135
|
+
current_bitrate: z.ZodNumber;
|
|
136
|
+
max_bitrate: z.ZodNumber;
|
|
137
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
138
|
+
type: z.ZodLiteral<"srt-stats">;
|
|
139
|
+
seq: z.ZodNumber;
|
|
140
|
+
rtt_ms: z.ZodNumber;
|
|
141
|
+
send_buffer: z.ZodNumber;
|
|
142
|
+
pkt_loss: z.ZodNumber;
|
|
143
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
144
|
+
type: z.ZodLiteral<"error">;
|
|
145
|
+
seq: z.ZodNumber;
|
|
146
|
+
code: z.ZodEnum<{
|
|
147
|
+
srtla_initial_connect_failed: "srtla_initial_connect_failed";
|
|
148
|
+
srtla_no_connections: "srtla_no_connections";
|
|
149
|
+
capture_audio_error: "capture_audio_error";
|
|
150
|
+
capture_video_error: "capture_video_error";
|
|
151
|
+
pipeline_stall: "pipeline_stall";
|
|
152
|
+
srt_connect_failed: "srt_connect_failed";
|
|
153
|
+
srt_connection_lost: "srt_connection_lost";
|
|
154
|
+
}>;
|
|
155
|
+
source: z.ZodEnum<{
|
|
156
|
+
srtla: "srtla";
|
|
157
|
+
engine: "engine";
|
|
158
|
+
}>;
|
|
159
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
160
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
161
|
+
type: z.ZodLiteral<"preview">;
|
|
162
|
+
seq: z.ZodNumber;
|
|
163
|
+
session_id: z.ZodString;
|
|
164
|
+
phase: z.ZodString;
|
|
165
|
+
}, z.core.$strip>], "type">;
|
|
166
|
+
export type EventParams = z.infer<typeof eventParamsSchema>;
|
|
167
|
+
/** Full event envelope: { jsonrpc, method:"event", params } with typed params. */
|
|
168
|
+
export declare const cerastreamEventSchema: z.ZodObject<{
|
|
169
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
170
|
+
method: z.ZodLiteral<"event">;
|
|
171
|
+
params: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
172
|
+
type: z.ZodLiteral<"status">;
|
|
173
|
+
seq: z.ZodNumber;
|
|
174
|
+
state: z.ZodEnum<{
|
|
175
|
+
idle: "idle";
|
|
176
|
+
starting: "starting";
|
|
177
|
+
streaming: "streaming";
|
|
178
|
+
stopping: "stopping";
|
|
179
|
+
}>;
|
|
180
|
+
streaming: z.ZodBoolean;
|
|
181
|
+
active_input: z.ZodOptional<z.ZodString>;
|
|
182
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
183
|
+
type: z.ZodLiteral<"switch">;
|
|
184
|
+
seq: z.ZodNumber;
|
|
185
|
+
active_input: z.ZodString;
|
|
186
|
+
mode: z.ZodEnum<{
|
|
187
|
+
manual: "manual";
|
|
188
|
+
auto: "auto";
|
|
189
|
+
}>;
|
|
190
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
191
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
192
|
+
type: z.ZodLiteral<"device">;
|
|
193
|
+
seq: z.ZodNumber;
|
|
194
|
+
change: z.ZodEnum<{
|
|
195
|
+
added: "added";
|
|
196
|
+
removed: "removed";
|
|
197
|
+
}>;
|
|
198
|
+
device: z.ZodObject<{
|
|
199
|
+
input_id: z.ZodString;
|
|
200
|
+
device_path: z.ZodString;
|
|
201
|
+
display_name: z.ZodString;
|
|
202
|
+
media_class: z.ZodEnum<{
|
|
203
|
+
video: "video";
|
|
204
|
+
audio: "audio";
|
|
205
|
+
}>;
|
|
206
|
+
caps: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
207
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
208
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
209
|
+
framerate: z.ZodOptional<z.ZodString>;
|
|
210
|
+
}, z.core.$strip>>>;
|
|
211
|
+
}, z.core.$strip>;
|
|
212
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
213
|
+
type: z.ZodLiteral<"bitrate">;
|
|
214
|
+
seq: z.ZodNumber;
|
|
215
|
+
current_bitrate: z.ZodNumber;
|
|
216
|
+
max_bitrate: z.ZodNumber;
|
|
217
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
218
|
+
type: z.ZodLiteral<"srt-stats">;
|
|
219
|
+
seq: z.ZodNumber;
|
|
220
|
+
rtt_ms: z.ZodNumber;
|
|
221
|
+
send_buffer: z.ZodNumber;
|
|
222
|
+
pkt_loss: z.ZodNumber;
|
|
223
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
224
|
+
type: z.ZodLiteral<"error">;
|
|
225
|
+
seq: z.ZodNumber;
|
|
226
|
+
code: z.ZodEnum<{
|
|
227
|
+
srtla_initial_connect_failed: "srtla_initial_connect_failed";
|
|
228
|
+
srtla_no_connections: "srtla_no_connections";
|
|
229
|
+
capture_audio_error: "capture_audio_error";
|
|
230
|
+
capture_video_error: "capture_video_error";
|
|
231
|
+
pipeline_stall: "pipeline_stall";
|
|
232
|
+
srt_connect_failed: "srt_connect_failed";
|
|
233
|
+
srt_connection_lost: "srt_connection_lost";
|
|
234
|
+
}>;
|
|
235
|
+
source: z.ZodEnum<{
|
|
236
|
+
srtla: "srtla";
|
|
237
|
+
engine: "engine";
|
|
238
|
+
}>;
|
|
239
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
240
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
241
|
+
type: z.ZodLiteral<"preview">;
|
|
242
|
+
seq: z.ZodNumber;
|
|
243
|
+
session_id: z.ZodString;
|
|
244
|
+
phase: z.ZodString;
|
|
245
|
+
}, z.core.$strip>], "type">;
|
|
246
|
+
}, z.core.$strip>;
|
|
247
|
+
export type CerastreamEvent = z.infer<typeof cerastreamEventSchema>;
|
|
248
|
+
/** The seven event topics (schema.md "Events" table) — count-assertion source. */
|
|
249
|
+
export declare const EVENT_TOPICS: readonly ["status", "switch", "device", "bitrate", "srt-stats", "error", "preview"];
|
|
250
|
+
export type EventTopicName = (typeof EVENT_TOPICS)[number];
|
|
251
|
+
/** topic → payload Zod schema. Tests assert every topic is represented here. */
|
|
252
|
+
export declare const eventSchemas: {
|
|
253
|
+
readonly status: z.ZodObject<{
|
|
254
|
+
type: z.ZodLiteral<"status">;
|
|
255
|
+
seq: z.ZodNumber;
|
|
256
|
+
state: z.ZodEnum<{
|
|
257
|
+
idle: "idle";
|
|
258
|
+
starting: "starting";
|
|
259
|
+
streaming: "streaming";
|
|
260
|
+
stopping: "stopping";
|
|
261
|
+
}>;
|
|
262
|
+
streaming: z.ZodBoolean;
|
|
263
|
+
active_input: z.ZodOptional<z.ZodString>;
|
|
264
|
+
}, z.core.$strip>;
|
|
265
|
+
readonly switch: z.ZodObject<{
|
|
266
|
+
type: z.ZodLiteral<"switch">;
|
|
267
|
+
seq: z.ZodNumber;
|
|
268
|
+
active_input: z.ZodString;
|
|
269
|
+
mode: z.ZodEnum<{
|
|
270
|
+
manual: "manual";
|
|
271
|
+
auto: "auto";
|
|
272
|
+
}>;
|
|
273
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
274
|
+
}, z.core.$strip>;
|
|
275
|
+
readonly device: z.ZodObject<{
|
|
276
|
+
type: z.ZodLiteral<"device">;
|
|
277
|
+
seq: z.ZodNumber;
|
|
278
|
+
change: z.ZodEnum<{
|
|
279
|
+
added: "added";
|
|
280
|
+
removed: "removed";
|
|
281
|
+
}>;
|
|
282
|
+
device: z.ZodObject<{
|
|
283
|
+
input_id: z.ZodString;
|
|
284
|
+
device_path: z.ZodString;
|
|
285
|
+
display_name: z.ZodString;
|
|
286
|
+
media_class: z.ZodEnum<{
|
|
287
|
+
video: "video";
|
|
288
|
+
audio: "audio";
|
|
289
|
+
}>;
|
|
290
|
+
caps: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
291
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
292
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
293
|
+
framerate: z.ZodOptional<z.ZodString>;
|
|
294
|
+
}, z.core.$strip>>>;
|
|
295
|
+
}, z.core.$strip>;
|
|
296
|
+
}, z.core.$strip>;
|
|
297
|
+
readonly bitrate: z.ZodObject<{
|
|
298
|
+
type: z.ZodLiteral<"bitrate">;
|
|
299
|
+
seq: z.ZodNumber;
|
|
300
|
+
current_bitrate: z.ZodNumber;
|
|
301
|
+
max_bitrate: z.ZodNumber;
|
|
302
|
+
}, z.core.$strip>;
|
|
303
|
+
readonly "srt-stats": z.ZodObject<{
|
|
304
|
+
type: z.ZodLiteral<"srt-stats">;
|
|
305
|
+
seq: z.ZodNumber;
|
|
306
|
+
rtt_ms: z.ZodNumber;
|
|
307
|
+
send_buffer: z.ZodNumber;
|
|
308
|
+
pkt_loss: z.ZodNumber;
|
|
309
|
+
}, z.core.$strip>;
|
|
310
|
+
readonly error: z.ZodObject<{
|
|
311
|
+
type: z.ZodLiteral<"error">;
|
|
312
|
+
seq: z.ZodNumber;
|
|
313
|
+
code: z.ZodEnum<{
|
|
314
|
+
srtla_initial_connect_failed: "srtla_initial_connect_failed";
|
|
315
|
+
srtla_no_connections: "srtla_no_connections";
|
|
316
|
+
capture_audio_error: "capture_audio_error";
|
|
317
|
+
capture_video_error: "capture_video_error";
|
|
318
|
+
pipeline_stall: "pipeline_stall";
|
|
319
|
+
srt_connect_failed: "srt_connect_failed";
|
|
320
|
+
srt_connection_lost: "srt_connection_lost";
|
|
321
|
+
}>;
|
|
322
|
+
source: z.ZodEnum<{
|
|
323
|
+
srtla: "srtla";
|
|
324
|
+
engine: "engine";
|
|
325
|
+
}>;
|
|
326
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
327
|
+
}, z.core.$strip>;
|
|
328
|
+
readonly preview: z.ZodObject<{
|
|
329
|
+
type: z.ZodLiteral<"preview">;
|
|
330
|
+
seq: z.ZodNumber;
|
|
331
|
+
session_id: z.ZodString;
|
|
332
|
+
phase: z.ZodString;
|
|
333
|
+
}, z.core.$strip>;
|
|
334
|
+
};
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { processErrorCodeSchema, processErrorSourceSchema, } from "./errors.js";
|
|
3
|
+
import { captureDeviceSchema, inputModeSchema, streamStateSchema, } from "./types.js";
|
|
4
|
+
// Server → client `event` notifications, delivered after `subscribe-events`
|
|
5
|
+
// (schema.md "Events"). Each event is the inner `params` of an rpcEventSchema:
|
|
6
|
+
// { type, seq, … }. `type` discriminates; `seq` is a per-type monotonic counter.
|
|
7
|
+
const seq = z.number().int().nonnegative();
|
|
8
|
+
// status — stream state change + heartbeat
|
|
9
|
+
export const statusEventSchema = z.object({
|
|
10
|
+
type: z.literal("status"),
|
|
11
|
+
seq,
|
|
12
|
+
state: streamStateSchema,
|
|
13
|
+
streaming: z.boolean(),
|
|
14
|
+
active_input: z.string().optional(),
|
|
15
|
+
});
|
|
16
|
+
// switch — active input changed (manual or failover)
|
|
17
|
+
export const switchEventSchema = z.object({
|
|
18
|
+
type: z.literal("switch"),
|
|
19
|
+
seq,
|
|
20
|
+
active_input: z.string(),
|
|
21
|
+
mode: inputModeSchema,
|
|
22
|
+
reason: z.string().optional(),
|
|
23
|
+
});
|
|
24
|
+
// device — GstDeviceMonitor hotplug
|
|
25
|
+
export const deviceEventSchema = z.object({
|
|
26
|
+
type: z.literal("device"),
|
|
27
|
+
seq,
|
|
28
|
+
change: z.enum(["added", "removed"]),
|
|
29
|
+
device: captureDeviceSchema,
|
|
30
|
+
});
|
|
31
|
+
// bitrate — adaptive controller adjusted encode bitrate
|
|
32
|
+
export const bitrateEventSchema = z.object({
|
|
33
|
+
type: z.literal("bitrate"),
|
|
34
|
+
seq,
|
|
35
|
+
current_bitrate: z.number().int(),
|
|
36
|
+
max_bitrate: z.number().int(),
|
|
37
|
+
});
|
|
38
|
+
// srt-stats — periodic transport stats
|
|
39
|
+
export const srtStatsEventSchema = z.object({
|
|
40
|
+
type: z.literal("srt-stats"),
|
|
41
|
+
seq,
|
|
42
|
+
rtt_ms: z.number(),
|
|
43
|
+
send_buffer: z.number().int(),
|
|
44
|
+
pkt_loss: z.number(),
|
|
45
|
+
});
|
|
46
|
+
// error — runtime error (replaces stderr scraping). Tier 2 code; engine reports
|
|
47
|
+
// facts, CeraUI decides what to show (suppressIfSrtlaNotified is a client policy).
|
|
48
|
+
export const runtimeErrorEventSchema = z.object({
|
|
49
|
+
type: z.literal("error"),
|
|
50
|
+
seq,
|
|
51
|
+
code: processErrorCodeSchema, // Tier 2 (errors.ts)
|
|
52
|
+
source: processErrorSourceSchema,
|
|
53
|
+
reason: z.string().optional(), // structured replacement for the stderr <reason>
|
|
54
|
+
});
|
|
55
|
+
// preview — preview session lifecycle
|
|
56
|
+
export const previewEventSchema = z.object({
|
|
57
|
+
type: z.literal("preview"),
|
|
58
|
+
seq,
|
|
59
|
+
session_id: z.string(),
|
|
60
|
+
phase: z.string(),
|
|
61
|
+
});
|
|
62
|
+
/** Discriminated union of every v1 event payload (the inner `params`). */
|
|
63
|
+
export const eventParamsSchema = z.discriminatedUnion("type", [
|
|
64
|
+
statusEventSchema,
|
|
65
|
+
switchEventSchema,
|
|
66
|
+
deviceEventSchema,
|
|
67
|
+
bitrateEventSchema,
|
|
68
|
+
srtStatsEventSchema,
|
|
69
|
+
runtimeErrorEventSchema,
|
|
70
|
+
previewEventSchema,
|
|
71
|
+
]);
|
|
72
|
+
/** Full event envelope: { jsonrpc, method:"event", params } with typed params. */
|
|
73
|
+
export const cerastreamEventSchema = z.object({
|
|
74
|
+
jsonrpc: z.literal("2.0"),
|
|
75
|
+
method: z.literal("event"),
|
|
76
|
+
params: eventParamsSchema,
|
|
77
|
+
});
|
|
78
|
+
/** The seven event topics (schema.md "Events" table) — count-assertion source. */
|
|
79
|
+
export const EVENT_TOPICS = [
|
|
80
|
+
"status",
|
|
81
|
+
"switch",
|
|
82
|
+
"device",
|
|
83
|
+
"bitrate",
|
|
84
|
+
"srt-stats",
|
|
85
|
+
"error",
|
|
86
|
+
"preview",
|
|
87
|
+
];
|
|
88
|
+
/** topic → payload Zod schema. Tests assert every topic is represented here. */
|
|
89
|
+
export const eventSchemas = {
|
|
90
|
+
status: statusEventSchema,
|
|
91
|
+
switch: switchEventSchema,
|
|
92
|
+
device: deviceEventSchema,
|
|
93
|
+
bitrate: bitrateEventSchema,
|
|
94
|
+
"srt-stats": srtStatsEventSchema,
|
|
95
|
+
error: runtimeErrorEventSchema,
|
|
96
|
+
preview: previewEventSchema,
|
|
97
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./constants.js";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * from "./envelope.js";
|
|
4
|
+
export * from "./types.js";
|
|
5
|
+
export * from "./messages.js";
|
|
6
|
+
export * from "./events.js";
|
|
7
|
+
export * from "./paths.js";
|
|
8
|
+
export * from "./config.js";
|
|
9
|
+
export * from "./client.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @ceralive/cerastream — control-IPC schema + type-safe client for the cerastream
|
|
2
|
+
// Rust streaming engine. The Zod schemas + types are the frozen public contract
|
|
3
|
+
// (ADR-0002 / schema.md); the client drives that contract over a Bun-native
|
|
4
|
+
// NDJSON/UDS transport (Task 31).
|
|
5
|
+
export * from "./constants.js";
|
|
6
|
+
export * from "./errors.js";
|
|
7
|
+
export * from "./envelope.js";
|
|
8
|
+
export * from "./types.js";
|
|
9
|
+
export * from "./messages.js";
|
|
10
|
+
export * from "./events.js";
|
|
11
|
+
export * from "./paths.js";
|
|
12
|
+
export * from "./config.js";
|
|
13
|
+
export * from "./client.js";
|