@synapse-sdk/client 0.1.0 → 0.3.3

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.
@@ -0,0 +1,151 @@
1
+ import * as Moq from "@moq/net";
2
+ import { type FecParams, type FecWasm, type MediaFrame, type TopicContract, type TrackDesc, type Tlv } from "@synapse-sdk/core";
3
+ import { Handle, type Event as HandleEvent, type Intent } from "./channel.ts";
4
+ import { type FecPubStats } from "./fec.ts";
5
+ import type { Node } from "./node.ts";
6
+ import { type Session } from "./session.ts";
7
+ import type { Envelope, PublishOptions, Publisher, PublisherStats, SubStats, SubscribeOptions, Subscription, Verdict } from "./types.ts";
8
+ export type Warn = (msg: string) => void;
9
+ /** The publisher shared by every `publisher(topic)` handle of one topic on this node. */
10
+ export declare class TopicPublisher<TIn, TOut> implements Intent {
11
+ #private;
12
+ readonly node: Node;
13
+ readonly contract: TopicContract<TIn, TOut>;
14
+ private readonly wasm;
15
+ readonly warn: Warn;
16
+ readonly name: string;
17
+ readonly registerSvc = "synapse/topic/register";
18
+ readonly unregisterSvc = "synapse/topic/unregister";
19
+ readonly desc: TrackDesc;
20
+ readonly fecParams: FecParams | undefined;
21
+ readonly fecStats: FecPubStats | undefined;
22
+ published: number;
23
+ droppedDisconnected: number;
24
+ handles: number;
25
+ readonly handle: Handle;
26
+ constructor(node: Node, contract: TopicContract<TIn, TOut>, maxDatagram: number, wasm: FecWasm | undefined, warn: Warn);
27
+ get verdict(): Verdict;
28
+ get isBound(): boolean;
29
+ registerArgs(bind: string): unknown;
30
+ unregisterArgs(bind: string): unknown;
31
+ /** Admitted: the broadcast is created, the descriptor written, the data track made, then announced (WP §7.1). */
32
+ install(s: Session, bind: string, _mailbox: (e: HandleEvent) => void): void;
33
+ retract(): void;
34
+ setVerdict(v: Verdict): void;
35
+ /**
36
+ * Publishes one frame (SDK §13: synchronous, never awaits the network). While nothing is installed
37
+ * (between sessions, a refused register being asked again) the frame is dropped and counted. A
38
+ * `stream` frame over moq's cap, a plain datagram over the session's datagram size, or a `fec`
39
+ * frame the codec refuses is refused (`invalid_input`) without taking a `seq`.
40
+ */
41
+ publishFrame(type: number, flags: number, tUs: number, tlvs: Tlv[], body: Uint8Array): void;
42
+ /**
43
+ * The typed form: validates against the contract's schema and encodes msgpack; a raw topic's bytes
44
+ * go as given, and on a `video/*` topic as a `MEDIA` frame whose `KEY`/`CONFIG`/`RECOVERY` flags
45
+ * are read off the bitstream (Rust `Publisher<RawBody>::publish`).
46
+ */
47
+ publish(value: TIn, opts?: PublishOptions): void;
48
+ /** An encoder's frame with the flags it already carries and its `STAGES` stamps (no re-parse); `tUs` 0 = now. The video helper's path (Rust `publish_media_frame`), not a user verb. */
49
+ publishMediaFrame(f: MediaFrame): void;
50
+ stats(): PublisherStats;
51
+ }
52
+ /**
53
+ * The key of a publisher handle's encoder-frame path, the JS spelling of Rust's `pub(crate)
54
+ * publish_media_frame`: `@synapse-sdk/media`'s `videoPublisher` reaches it by the same
55
+ * `Symbol.for` key (the two packages share no module), so it is on no public type.
56
+ */
57
+ export declare const PUBLISH_MEDIA_FRAME: unique symbol;
58
+ /** The application's handle: the last one closed ends the publisher's task (`unregister`). */
59
+ export declare class PublisherHandle<TIn, TOut> implements Publisher<TIn> {
60
+ #private;
61
+ private readonly p;
62
+ private readonly onLast;
63
+ constructor(p: TopicPublisher<TIn, TOut>, onLast: () => void);
64
+ get topic(): string;
65
+ get verdict(): Verdict;
66
+ ready(): Promise<void>;
67
+ publish(value: TIn, opts?: PublishOptions): void;
68
+ /** `@synapse-sdk/media`'s video publisher: an encoder's frame with its flags and `STAGES` (see `PUBLISH_MEDIA_FRAME`). */
69
+ [PUBLISH_MEDIA_FRAME](f: MediaFrame): void;
70
+ stats(): PublisherStats;
71
+ close(): void;
72
+ [Symbol.asyncDispose](): Promise<void>;
73
+ }
74
+ /** Resolves the codec a `fec` topic needs (once per process). */
75
+ export declare function wasmFor(contract: TopicContract<unknown, unknown>): Promise<FecWasm | undefined>;
76
+ /** What a source gives when its track ended. */
77
+ declare const END: unique symbol;
78
+ /**
79
+ * One plain publisher the read takes from (Rust `Source`). A stream source is read synchronously
80
+ * by `next()` (`tryRecvGroup` / `tryReadFrame`, as Rust's poll); when nothing is buffered it holds
81
+ * exactly one pending read (`recvGroup` / `readFrame`) as the wake, whose result is the first item
82
+ * of the next drain. A datagram source has one reader (one `recvDatagram` at a time) filling
83
+ * `held`: latest mode keeps one (the newest `seq`), every-message mode at most `DATAGRAM_RING`.
84
+ */
85
+ interface Source {
86
+ path: string;
87
+ prefix: string;
88
+ publisher: string;
89
+ dom: string;
90
+ /** The request for the publisher's broadcast: closed with the source. */
91
+ req: Moq.Origin.Requesting;
92
+ sub: Moq.Track.Subscriber;
93
+ /** Read as a stream (groups of frames) or as datagrams: the catalog's delivery for the topic. */
94
+ stream: boolean;
95
+ /** A stream source: the group being read. */
96
+ group: Moq.Group.Consumer | undefined;
97
+ /** A stream source: the pending read that wakes the read when nothing is buffered. */
98
+ wait: Promise<void> | undefined;
99
+ /** A stream source: what that pending read gave (a frame, or the track's end), taken first. */
100
+ ready: Uint8Array | typeof END | undefined;
101
+ /** A datagram source: the datagrams its reader took and the read has not. */
102
+ held: Uint8Array[];
103
+ /** A datagram source in latest mode: the `seq` of the one held. */
104
+ heldSeq: number | undefined;
105
+ /** A datagram source: its reader saw the track end; the end is given once `held` is drained. */
106
+ done: boolean;
107
+ /** The `seq` last returned (latest mode): not newer is superseded. */
108
+ last: number | undefined;
109
+ ended: boolean;
110
+ }
111
+ export declare class TopicSubscription<T> implements Subscription<T> {
112
+ #private;
113
+ readonly node: Node;
114
+ readonly contract: TopicContract<unknown, T>;
115
+ readonly opts: SubscribeOptions;
116
+ readonly warn: Warn;
117
+ readonly topic: string;
118
+ readonly stats: SubStats;
119
+ readonly latest: boolean;
120
+ constructor(node: Node, contract: TopicContract<unknown, T>, opts: SubscribeOptions, warn: Warn);
121
+ get signal(): AbortSignal;
122
+ get ownDom(): string;
123
+ /** The follow task hands a plain publisher here (a datagram source's reader starts); the waiting `next()` is woken. */
124
+ addSource(src: Source): void;
125
+ /** The publisher leaves the read: its subscription and request are closed, a payload it gave is never returned. */
126
+ removeSource(src: Source): void;
127
+ /** A `fec` follower's frame: latest mode replaces the publisher's pending one. */
128
+ pushFec(env: Envelope<T>): void;
129
+ dropFecOf(publisher: string): void;
130
+ /** A new session (or none): the `fec` frames and a batch held by `throttleMs` are the previous session's and go. */
131
+ clearFec(): void;
132
+ /**
133
+ * The established descriptor's `content_type` (the catalog's, the runtime's statement), set by the
134
+ * follow task from each snapshot: bodies decode by it, not by what this subscription declared.
135
+ */
136
+ contentType: string | undefined;
137
+ /** The decoding step: header facts plus the body by the established `content_type` (msgpack → a value, validated when the contract has a schema; anything else → bytes), or `mismatch` and dropped. */
138
+ envelope(payload: Uint8Array, publisher: string, dom: string): Envelope<T> | undefined;
139
+ /**
140
+ * The next batch, never empty; `undefined` once the subscription or the node ended. Drains what
141
+ * every source has ready, synchronously (at most `DRAIN_PER_READ` per source), and the `fec`
142
+ * frames; with nothing to return it waits for a source's pending read or reader, a `fec` frame,
143
+ * a change of the set or the end of a `throttleMs` interval, and drains again.
144
+ */
145
+ next(): Promise<Envelope<T>[] | undefined>;
146
+ [Symbol.asyncIterator](): AsyncGenerator<Envelope<T>[], void, undefined>;
147
+ /** Ends the subscription: the follow task stops, every track is closed, a pending `next()` returns `undefined`. */
148
+ unsubscribe(): void;
149
+ [Symbol.asyncDispose](): Promise<void>;
150
+ }
151
+ export {};