effect-cloudflare-webrtc 0.0.0-stage → 0.0.0
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 +439 -2
- package/dist/AudioSink-BybkMP2y.d.ts +54 -0
- package/dist/Readable-CJPSx6Uq.js +65 -0
- package/dist/Readable-CJPSx6Uq.js.map +1 -0
- package/dist/Realtime-B5OIHlLR.d.ts +129 -0
- package/dist/Realtime-B6TjV8su.js +195 -0
- package/dist/Realtime-B6TjV8su.js.map +1 -0
- package/dist/RealtimeClient-Bl0Tun5r.js +2488 -0
- package/dist/RealtimeClient-Bl0Tun5r.js.map +1 -0
- package/dist/RealtimeClient-ESFO5vfF.d.ts +412 -0
- package/dist/RealtimeClient-K7oKgsB9.d.ts +1000 -0
- package/dist/chunk-pbuEa-1d.js +13 -0
- package/dist/client/index.d.ts +275 -0
- package/dist/client/index.js +493 -0
- package/dist/client/index.js.map +1 -0
- package/dist/effect/client/index.d.ts +434 -0
- package/dist/effect/client/index.js +2 -0
- package/dist/effect/server/index.d.ts +2 -0
- package/dist/effect/server/index.js +2 -0
- package/dist/react/index.d.ts +44 -0
- package/dist/react/index.js +107 -0
- package/dist/react/index.js.map +1 -0
- package/dist/server/index.d.ts +23 -0
- package/dist/server/index.js +12 -0
- package/dist/server/index.js.map +1 -0
- package/package.json +92 -4
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import { b as ConnectionStats } from "./RealtimeClient-K7oKgsB9.js";
|
|
2
|
+
//#region src/client/Readable.d.ts
|
|
3
|
+
declare global {
|
|
4
|
+
interface SymbolConstructor {
|
|
5
|
+
/** The interoperability symbol of observable libraries, for example RxJS. */
|
|
6
|
+
readonly observable: symbol;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** What `rxjs.from()` and other observable libraries accept. */
|
|
10
|
+
interface InteropObservable<T> {
|
|
11
|
+
subscribe(
|
|
12
|
+
observer:
|
|
13
|
+
| ((value: T) => void)
|
|
14
|
+
| {
|
|
15
|
+
next?: (value: T) => void;
|
|
16
|
+
}
|
|
17
|
+
): {
|
|
18
|
+
unsubscribe(): void;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** A value that changes. It always has a current value. */
|
|
22
|
+
interface Readable<T> {
|
|
23
|
+
/** The current value. */
|
|
24
|
+
get(): T;
|
|
25
|
+
/**
|
|
26
|
+
* Calls the listener immediately with the current value, then for each
|
|
27
|
+
* change. Returns a function that stops the subscription.
|
|
28
|
+
*/
|
|
29
|
+
subscribe(listener: (value: T) => void): () => void;
|
|
30
|
+
/** For observable libraries: `rxjs.from(readable)` works. */
|
|
31
|
+
[Symbol.observable](): InteropObservable<T>;
|
|
32
|
+
}
|
|
33
|
+
/** A `Readable` that the application sets. */
|
|
34
|
+
interface Writable<T> extends Readable<T> {
|
|
35
|
+
set(value: T): void;
|
|
36
|
+
}
|
|
37
|
+
/** A `Readable` that the application sets, for example from a WebSocket. */
|
|
38
|
+
declare function writable<T>(initial: T): Writable<T>;
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/client/types.d.ts
|
|
41
|
+
interface TrackMetadata {
|
|
42
|
+
readonly sessionId: string;
|
|
43
|
+
readonly trackName: string;
|
|
44
|
+
readonly location: "remote";
|
|
45
|
+
}
|
|
46
|
+
/** The request got no response. */
|
|
47
|
+
interface ApiTransportError {
|
|
48
|
+
readonly _tag: "ApiTransportError";
|
|
49
|
+
readonly endpoint: string;
|
|
50
|
+
readonly cause: unknown;
|
|
51
|
+
}
|
|
52
|
+
/** A status that is not 2xx, or an `errorCode` in the body. */
|
|
53
|
+
interface ApiResponseError {
|
|
54
|
+
readonly _tag: "ApiResponseError";
|
|
55
|
+
readonly endpoint: string;
|
|
56
|
+
readonly status: number;
|
|
57
|
+
readonly errorCode?: string | undefined;
|
|
58
|
+
readonly errorDescription?: string | undefined;
|
|
59
|
+
}
|
|
60
|
+
/** A successful response with a body that is not the expected JSON. */
|
|
61
|
+
interface ApiInvalidResponse {
|
|
62
|
+
readonly _tag: "ApiInvalidResponse";
|
|
63
|
+
readonly endpoint: string;
|
|
64
|
+
readonly status: number;
|
|
65
|
+
readonly message: string;
|
|
66
|
+
}
|
|
67
|
+
/** The request was redirected, for example by an expired login. */
|
|
68
|
+
interface ApiAuthRedirect {
|
|
69
|
+
readonly _tag: "ApiAuthRedirect";
|
|
70
|
+
readonly endpoint: string;
|
|
71
|
+
}
|
|
72
|
+
interface PeerConnectionFailed {
|
|
73
|
+
readonly _tag: "PeerConnectionFailed";
|
|
74
|
+
readonly reason:
|
|
75
|
+
| "connection-failed"
|
|
76
|
+
| "connection-closed"
|
|
77
|
+
| "ice-failed"
|
|
78
|
+
| "ice-closed"
|
|
79
|
+
| "ice-disconnected-timeout";
|
|
80
|
+
}
|
|
81
|
+
/** A negotiation step did not complete. The session is replaced. */
|
|
82
|
+
interface NegotiationOutcomeUnknown {
|
|
83
|
+
readonly _tag: "NegotiationOutcomeUnknown";
|
|
84
|
+
readonly step: string;
|
|
85
|
+
readonly cause: unknown;
|
|
86
|
+
}
|
|
87
|
+
/** One track of a request was refused by the SFU. */
|
|
88
|
+
interface TrackError {
|
|
89
|
+
readonly _tag: "TrackError";
|
|
90
|
+
readonly trackName?: string | undefined;
|
|
91
|
+
readonly mid?: string | undefined;
|
|
92
|
+
readonly errorCode: string;
|
|
93
|
+
readonly errorDescription?: string | undefined;
|
|
94
|
+
}
|
|
95
|
+
interface TransceiverNotFound {
|
|
96
|
+
readonly _tag: "TransceiverNotFound";
|
|
97
|
+
readonly trackName?: string | undefined;
|
|
98
|
+
readonly mid?: string | undefined;
|
|
99
|
+
}
|
|
100
|
+
/** `replaceTrack` or `setParameters` rejected. */
|
|
101
|
+
interface SenderError {
|
|
102
|
+
readonly _tag: "SenderError";
|
|
103
|
+
readonly operation: "replaceTrack" | "setParameters";
|
|
104
|
+
readonly cause: unknown;
|
|
105
|
+
}
|
|
106
|
+
/** A browser call for devices or media rejected. */
|
|
107
|
+
interface MediaAccessError {
|
|
108
|
+
readonly _tag: "MediaAccessError";
|
|
109
|
+
readonly operation: "enumerateDevices" | "getUserMedia" | "getDisplayMedia";
|
|
110
|
+
/** The `name` of the browser error, for example "NotAllowedError". */
|
|
111
|
+
readonly errorName: string;
|
|
112
|
+
readonly message: string;
|
|
113
|
+
readonly cause: unknown;
|
|
114
|
+
}
|
|
115
|
+
/** No device gave a healthy track. */
|
|
116
|
+
interface DevicesExhausted {
|
|
117
|
+
readonly _tag: "DevicesExhausted";
|
|
118
|
+
readonly kind: "audioinput" | "videoinput";
|
|
119
|
+
}
|
|
120
|
+
/** A transformation of a content track failed. */
|
|
121
|
+
interface TransformFailed {
|
|
122
|
+
readonly _tag: "TransformFailed";
|
|
123
|
+
readonly cause: unknown;
|
|
124
|
+
}
|
|
125
|
+
/** The audio output device was not selected. */
|
|
126
|
+
interface SinkError {
|
|
127
|
+
readonly _tag: "SinkError";
|
|
128
|
+
readonly reason: "not-supported" | "rejected";
|
|
129
|
+
readonly cause?: unknown;
|
|
130
|
+
}
|
|
131
|
+
type ApiError =
|
|
132
|
+
| ApiTransportError
|
|
133
|
+
| ApiResponseError
|
|
134
|
+
| ApiInvalidResponse
|
|
135
|
+
| ApiAuthRedirect;
|
|
136
|
+
type SessionError = ApiError | PeerConnectionFailed | NegotiationOutcomeUnknown;
|
|
137
|
+
type PushError = ApiError | NegotiationOutcomeUnknown | TrackError;
|
|
138
|
+
type PullError =
|
|
139
|
+
| ApiError
|
|
140
|
+
| NegotiationOutcomeUnknown
|
|
141
|
+
| TrackError
|
|
142
|
+
| TransceiverNotFound;
|
|
143
|
+
type SourceError = DevicesExhausted | MediaAccessError | TransformFailed;
|
|
144
|
+
type SessionState =
|
|
145
|
+
/** No push and no pull is active. There is no peer connection. */ | {
|
|
146
|
+
readonly _tag: "Idle";
|
|
147
|
+
} /** The session and the ICE servers are requested. */
|
|
148
|
+
| {
|
|
149
|
+
readonly _tag: "Connecting";
|
|
150
|
+
readonly attempt: number;
|
|
151
|
+
} /** A peer connection exists. */
|
|
152
|
+
| {
|
|
153
|
+
readonly _tag: "Open";
|
|
154
|
+
readonly sessionId: string;
|
|
155
|
+
readonly peerConnection: RTCPeerConnection;
|
|
156
|
+
readonly connectionState: RTCPeerConnectionState;
|
|
157
|
+
} /** The session failed. A new one is made after the retry delay. */
|
|
158
|
+
| {
|
|
159
|
+
readonly _tag: "Reconnecting";
|
|
160
|
+
readonly error: SessionError;
|
|
161
|
+
readonly attempt: number;
|
|
162
|
+
} /** The retry policy ended. No new session is made. */
|
|
163
|
+
| {
|
|
164
|
+
readonly _tag: "Failed";
|
|
165
|
+
readonly error: SessionError;
|
|
166
|
+
};
|
|
167
|
+
type PushState = /** The source has not given a track. */ | {
|
|
168
|
+
readonly _tag: "WaitingForTrack";
|
|
169
|
+
} /** The session is not open. */
|
|
170
|
+
| {
|
|
171
|
+
readonly _tag: "WaitingForSession";
|
|
172
|
+
} /** The offer is in the queue or in progress. */
|
|
173
|
+
| {
|
|
174
|
+
readonly _tag: "Negotiating";
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The SFU accepted the track, and the track has sent no data yet. A track
|
|
178
|
+
* of an audio context sends no data before the first user gesture.
|
|
179
|
+
*/
|
|
180
|
+
| {
|
|
181
|
+
readonly _tag: "WaitingForData";
|
|
182
|
+
readonly transceiver: RTCRtpTransceiver;
|
|
183
|
+
}
|
|
184
|
+
| {
|
|
185
|
+
readonly _tag: "Published";
|
|
186
|
+
readonly metadata: TrackMetadata;
|
|
187
|
+
readonly transceiver: RTCRtpTransceiver;
|
|
188
|
+
} /** The last attempt failed. The next attempt comes after the retry delay. */
|
|
189
|
+
| {
|
|
190
|
+
readonly _tag: "Retrying";
|
|
191
|
+
readonly error: PushError;
|
|
192
|
+
readonly attempt: number;
|
|
193
|
+
} /** No more attempts are made. The track is closed. */
|
|
194
|
+
| {
|
|
195
|
+
readonly _tag: "Failed";
|
|
196
|
+
readonly error: unknown;
|
|
197
|
+
} /** `close()` was called. */
|
|
198
|
+
| {
|
|
199
|
+
readonly _tag: "Closed";
|
|
200
|
+
};
|
|
201
|
+
type PullState =
|
|
202
|
+
| {
|
|
203
|
+
readonly _tag: "WaitingForMetadata";
|
|
204
|
+
}
|
|
205
|
+
| {
|
|
206
|
+
readonly _tag: "WaitingForSession";
|
|
207
|
+
readonly metadata: TrackMetadata;
|
|
208
|
+
}
|
|
209
|
+
| {
|
|
210
|
+
readonly _tag: "Negotiating";
|
|
211
|
+
readonly metadata: TrackMetadata;
|
|
212
|
+
}
|
|
213
|
+
| {
|
|
214
|
+
readonly _tag: "Live";
|
|
215
|
+
readonly metadata: TrackMetadata;
|
|
216
|
+
readonly track: MediaStreamTrack;
|
|
217
|
+
readonly transceiver: RTCRtpTransceiver;
|
|
218
|
+
}
|
|
219
|
+
| {
|
|
220
|
+
readonly _tag: "Retrying";
|
|
221
|
+
readonly metadata: TrackMetadata;
|
|
222
|
+
readonly error: PullError;
|
|
223
|
+
readonly attempt: number;
|
|
224
|
+
} /** No more attempts are made. */
|
|
225
|
+
| {
|
|
226
|
+
readonly _tag: "Failed";
|
|
227
|
+
readonly error: unknown;
|
|
228
|
+
} /** `close()` was called. */
|
|
229
|
+
| {
|
|
230
|
+
readonly _tag: "Closed";
|
|
231
|
+
};
|
|
232
|
+
interface TransceiverEvent {
|
|
233
|
+
readonly direction: "send" | "receive";
|
|
234
|
+
readonly sessionId: string;
|
|
235
|
+
readonly transceiver: RTCRtpTransceiver;
|
|
236
|
+
}
|
|
237
|
+
type ApiHistoryEntry =
|
|
238
|
+
| {
|
|
239
|
+
readonly type: "request";
|
|
240
|
+
readonly method: string;
|
|
241
|
+
readonly endpoint: string;
|
|
242
|
+
readonly body: unknown;
|
|
243
|
+
}
|
|
244
|
+
| {
|
|
245
|
+
readonly type: "response";
|
|
246
|
+
readonly endpoint: string;
|
|
247
|
+
readonly status: number;
|
|
248
|
+
readonly body: unknown;
|
|
249
|
+
};
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/client/logging.d.ts
|
|
252
|
+
type LogLevel = "none" | "error" | "warn" | "info" | "debug";
|
|
253
|
+
interface LogEntry {
|
|
254
|
+
readonly level: Exclude<LogLevel, "none">;
|
|
255
|
+
/** The parts of the message, as for `console.log`. */
|
|
256
|
+
readonly message: ReadonlyArray<unknown>;
|
|
257
|
+
readonly date: Date;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Sets the log level of the media sources (`createMicrophoneSource` and the others) and of
|
|
261
|
+
* each client that has no `logLevel` option. Default: "warn".
|
|
262
|
+
*/
|
|
263
|
+
declare function setLogLevel(level: LogLevel): void;
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region src/client/RealtimeClient.d.ts
|
|
266
|
+
interface RealtimeClientOptions {
|
|
267
|
+
/** Path or full URL of the proxy route. Default: "/realtime". */
|
|
268
|
+
prefix?: string;
|
|
269
|
+
/** Added to the query string of each request. */
|
|
270
|
+
apiExtraParams?: string | URLSearchParams;
|
|
271
|
+
/** Added to each request. A function is called for each request. */
|
|
272
|
+
headers?: HeadersInit | (() => HeadersInit);
|
|
273
|
+
/** Skips the request for ICE servers. */
|
|
274
|
+
iceServers?: RTCIceServer[];
|
|
275
|
+
/** How many API requests and responses the history keeps. Default: 100. */
|
|
276
|
+
maxApiHistory?: number;
|
|
277
|
+
/** Use "include" for a cross-origin prefix. Default: "same-origin". */
|
|
278
|
+
credentials?: RequestCredentials;
|
|
279
|
+
/** Default: the level of `setLogLevel()`, which is "warn" at the start. */
|
|
280
|
+
logLevel?: LogLevel;
|
|
281
|
+
/** Replaces the `console` output. */
|
|
282
|
+
logger?: (entry: LogEntry) => void;
|
|
283
|
+
/** Retry delays. Default: 250 ms, factor 2, maximum 10 s, no end. */
|
|
284
|
+
retry?: {
|
|
285
|
+
/** Milliseconds. */ initialDelay?: number;
|
|
286
|
+
factor?: number /** Milliseconds. */;
|
|
287
|
+
maxDelay?: number /** After this number of attempts, the state becomes `Failed`. */;
|
|
288
|
+
maxAttempts?: number;
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* Set to false to remove the `traceparent` and `b3` request headers, for
|
|
292
|
+
* example for a cross-origin prefix. Default: true.
|
|
293
|
+
*/
|
|
294
|
+
tracePropagation?: boolean;
|
|
295
|
+
/**
|
|
296
|
+
* Called when a request is redirected, for example by an expired login.
|
|
297
|
+
* The requests continue to be tried again.
|
|
298
|
+
*/
|
|
299
|
+
onAuthRedirect?: () => void;
|
|
300
|
+
}
|
|
301
|
+
interface PushedTrack {
|
|
302
|
+
/** Stable for the life of the handle, also across reconnects. */
|
|
303
|
+
readonly trackName: string;
|
|
304
|
+
readonly state: Readable<PushState>;
|
|
305
|
+
/**
|
|
306
|
+
* `undefined` until the track is published, and during a reconnect. Send
|
|
307
|
+
* each value to the parties that pull the track.
|
|
308
|
+
*/
|
|
309
|
+
readonly metadata: Readable<TrackMetadata | undefined>;
|
|
310
|
+
/** Rejects with a `SenderError`. */
|
|
311
|
+
setSendEncodings(encodings: RTCRtpEncodingParameters[]): Promise<void>;
|
|
312
|
+
/** Stops the push and closes the track on the SFU. */
|
|
313
|
+
close(): Promise<void>;
|
|
314
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
315
|
+
}
|
|
316
|
+
interface PulledTrack {
|
|
317
|
+
readonly state: Readable<PullState>;
|
|
318
|
+
/** `undefined` until the track arrives, and while it is pulled again. */
|
|
319
|
+
readonly track: Readable<MediaStreamTrack | undefined>;
|
|
320
|
+
/** Changes the simulcast layer. Rejects with an API error. */
|
|
321
|
+
setPreferredRid(rid: string): Promise<void>;
|
|
322
|
+
/** Stops the pull and closes the track on the SFU. */
|
|
323
|
+
close(): Promise<void>;
|
|
324
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
325
|
+
}
|
|
326
|
+
interface RealtimeClient {
|
|
327
|
+
readonly sessionState: Readable<SessionState>;
|
|
328
|
+
/**
|
|
329
|
+
* Publishes a track until `close()`. With a `Readable`, each new track
|
|
330
|
+
* replaces the track before it, with no new negotiation.
|
|
331
|
+
*/
|
|
332
|
+
push(
|
|
333
|
+
source: MediaStreamTrack | Readable<MediaStreamTrack | undefined>,
|
|
334
|
+
options?: {
|
|
335
|
+
sendEncodings?: RTCRtpEncodingParameters[];
|
|
336
|
+
trackName?: string;
|
|
337
|
+
}
|
|
338
|
+
): PushedTrack;
|
|
339
|
+
/**
|
|
340
|
+
* Pulls a track until `close()`. With a `Readable`, new metadata pulls
|
|
341
|
+
* the new track.
|
|
342
|
+
*/
|
|
343
|
+
pull(
|
|
344
|
+
metadata: TrackMetadata | Readable<TrackMetadata | undefined>,
|
|
345
|
+
options?: {
|
|
346
|
+
preferredRid?: string;
|
|
347
|
+
}
|
|
348
|
+
): PulledTrack;
|
|
349
|
+
/** Each transceiver that is added (push) or resolved (pull). */
|
|
350
|
+
onTransceiver(listener: (event: TransceiverEvent) => void): () => void;
|
|
351
|
+
/**
|
|
352
|
+
* The statistics of the open session and of its tracks, at each interval.
|
|
353
|
+
* Nothing comes while no session is open. It does not keep a session open.
|
|
354
|
+
*/
|
|
355
|
+
onStats(
|
|
356
|
+
listener: (stats: ConnectionStats) => void,
|
|
357
|
+
options?: {
|
|
358
|
+
/** Milliseconds between two samples. Default: 2000. */ interval?: number;
|
|
359
|
+
}
|
|
360
|
+
): () => void;
|
|
361
|
+
/** Each API request and response when it occurs. */
|
|
362
|
+
onApiEvent(listener: (entry: ApiHistoryEntry) => void): () => void;
|
|
363
|
+
/** The last API requests and responses. */
|
|
364
|
+
getApiHistory(): ApiHistoryEntry[];
|
|
365
|
+
/** Closes all handles, the session, and the internal runtime. */
|
|
366
|
+
dispose(): Promise<void>;
|
|
367
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
368
|
+
}
|
|
369
|
+
/** Pushes local tracks to the Realtime SFU and pulls remote tracks from it. */
|
|
370
|
+
declare function createRealtimeClient(
|
|
371
|
+
options?: RealtimeClientOptions
|
|
372
|
+
): RealtimeClient;
|
|
373
|
+
//#endregion
|
|
374
|
+
export {
|
|
375
|
+
TransceiverEvent as A,
|
|
376
|
+
SenderError as C,
|
|
377
|
+
SourceError as D,
|
|
378
|
+
SinkError as E,
|
|
379
|
+
Writable as F,
|
|
380
|
+
writable as I,
|
|
381
|
+
TransformFailed as M,
|
|
382
|
+
InteropObservable as N,
|
|
383
|
+
TrackError as O,
|
|
384
|
+
Readable as P,
|
|
385
|
+
PushState as S,
|
|
386
|
+
SessionState as T,
|
|
387
|
+
NegotiationOutcomeUnknown as _,
|
|
388
|
+
createRealtimeClient as a,
|
|
389
|
+
PullState as b,
|
|
390
|
+
setLogLevel as c,
|
|
391
|
+
ApiHistoryEntry as d,
|
|
392
|
+
ApiInvalidResponse as f,
|
|
393
|
+
MediaAccessError as g,
|
|
394
|
+
DevicesExhausted as h,
|
|
395
|
+
RealtimeClientOptions as i,
|
|
396
|
+
TransceiverNotFound as j,
|
|
397
|
+
TrackMetadata as k,
|
|
398
|
+
ApiAuthRedirect as l,
|
|
399
|
+
ApiTransportError as m,
|
|
400
|
+
PushedTrack as n,
|
|
401
|
+
LogEntry as o,
|
|
402
|
+
ApiResponseError as p,
|
|
403
|
+
RealtimeClient as r,
|
|
404
|
+
LogLevel as s,
|
|
405
|
+
PulledTrack as t,
|
|
406
|
+
ApiError as u,
|
|
407
|
+
PeerConnectionFailed as v,
|
|
408
|
+
SessionError as w,
|
|
409
|
+
PushError as x,
|
|
410
|
+
PullError as y
|
|
411
|
+
};
|
|
412
|
+
//# sourceMappingURL=RealtimeClient-ESFO5vfF.d.ts.map
|