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.
@@ -0,0 +1,1000 @@
1
+ import * as Effect from "effect/Effect";
2
+ import * as Layer from "effect/Layer";
3
+ import * as Scope from "effect/Scope";
4
+ import * as Stream from "effect/Stream";
5
+ import * as Schema from "effect/Schema";
6
+ import * as Context from "effect/Context";
7
+ import * as Duration from "effect/Duration";
8
+ import * as _$effect_Cause0 from "effect/Cause";
9
+ import * as Schedule from "effect/Schedule";
10
+ import * as HttpClient from "effect/http/HttpClient";
11
+
12
+ //#region src/effect/client/internal/devicePriority.d.ts
13
+ interface DeviceReference {
14
+ readonly kind: MediaDeviceKind;
15
+ readonly label: string;
16
+ readonly deviceId?: string;
17
+ }
18
+ interface DeviceFailure extends DeviceReference {
19
+ readonly retryAt: number;
20
+ readonly failures: number;
21
+ }
22
+ //#endregion
23
+ //#region src/effect/client/Subscribable.d.ts
24
+ /** A value that changes. It always has a current value. */
25
+ interface Subscribable<A> {
26
+ /** The current value. */
27
+ readonly get: Effect.Effect<A>;
28
+ /** The current value, then each change. A slow consumer gets the newest value. */
29
+ readonly changes: Stream.Stream<A>;
30
+ }
31
+ //#endregion
32
+ //#region src/effect/client/DevicePreferences.d.ts
33
+ /** Where the preferences are kept. The default is `localStorage`. */
34
+ interface PreferenceStorage {
35
+ /** Can throw. */
36
+ readonly getItem: (key: string) => string | null;
37
+ /** Can throw. */
38
+ readonly setItem: (key: string, value: string) => void;
39
+ /** Each change that a different tab or a different instance made. */
40
+ readonly changes: Stream.Stream<unknown>;
41
+ /** Tells the other instances of this page about a change. */
42
+ readonly notify: () => void;
43
+ }
44
+ interface DeviceRanking {
45
+ readonly choices: readonly DeviceReference[];
46
+ readonly deprioritized: readonly DeviceFailure[];
47
+ }
48
+ type Change = (
49
+ device: MediaDeviceInfo,
50
+ devices?: readonly MediaDeviceInfo[]
51
+ ) => Effect.Effect<void>;
52
+ declare const DevicePreferences_base: Context.ServiceClass<
53
+ DevicePreferences,
54
+ "effect-cloudflare-webrtc/DevicePreferences",
55
+ {
56
+ readonly ranking: (kind: MediaDeviceKind) => Subscribable<DeviceRanking>;
57
+ readonly recovered: Change /** Most recent explicit choice. */;
58
+ readonly preferred: (
59
+ kind: MediaDeviceKind
60
+ ) => Subscribable<
61
+ DeviceReference | undefined
62
+ > /** Recorded failures, including expired entries retained for backoff. See ranking for retry times. */;
63
+ readonly deprioritized: (
64
+ kind: MediaDeviceKind
65
+ ) => Subscribable<
66
+ ReadonlyArray<DeviceFailure>
67
+ > /** Also removes the device from the deprioritized devices. */;
68
+ readonly setPreferred: Change;
69
+ readonly deprioritize: Change;
70
+ }
71
+ >;
72
+ /** The preferred device and the deprioritized devices of the user. */
73
+ declare class DevicePreferences extends DevicePreferences_base {
74
+ static layerStorage: (
75
+ storage: PreferenceStorage
76
+ ) => Layer.Layer<DevicePreferences>;
77
+ /** The preferences are lost when the page closes. */
78
+ static layerMemory: Layer.Layer<DevicePreferences>;
79
+ /**
80
+ * Keeps the preferences in `localStorage`, and follows the changes of
81
+ * other tabs. If `localStorage` is not available, the preferences stay in
82
+ * memory.
83
+ */
84
+ static layerLocalStorage: Layer.Layer<DevicePreferences>;
85
+ }
86
+ //#endregion
87
+ //#region src/effect/client/Errors.d.ts
88
+ declare const ApiTransportError_base: Schema.Class<
89
+ ApiTransportError,
90
+ Schema.TaggedStruct<
91
+ "ApiTransportError",
92
+ {
93
+ readonly endpoint: Schema.String;
94
+ readonly cause: Schema.Unknown;
95
+ }
96
+ >,
97
+ _$effect_Cause0.YieldableError
98
+ >;
99
+ /** The request got no response. The outcome on the server is not known. */
100
+ declare class ApiTransportError extends ApiTransportError_base {}
101
+ declare const ApiResponseError_base: Schema.Class<
102
+ ApiResponseError,
103
+ Schema.TaggedStruct<
104
+ "ApiResponseError",
105
+ {
106
+ readonly endpoint: Schema.String;
107
+ readonly status: Schema.Number;
108
+ readonly errorCode: Schema.optional<Schema.String>;
109
+ readonly errorDescription: Schema.optional<Schema.String>;
110
+ }
111
+ >,
112
+ _$effect_Cause0.YieldableError
113
+ >;
114
+ /**
115
+ * The server sent a response that is an error: a status that is not 2xx, or
116
+ * an `errorCode` in the body.
117
+ */
118
+ declare class ApiResponseError extends ApiResponseError_base {}
119
+ declare const ApiInvalidResponse_base: Schema.Class<
120
+ ApiInvalidResponse,
121
+ Schema.TaggedStruct<
122
+ "ApiInvalidResponse",
123
+ {
124
+ readonly endpoint: Schema.String;
125
+ readonly status: Schema.Number;
126
+ readonly message: Schema.String;
127
+ }
128
+ >,
129
+ _$effect_Cause0.YieldableError
130
+ >;
131
+ /**
132
+ * The server sent a successful response, but its body is not the expected
133
+ * JSON. The outcome on the server is not known.
134
+ */
135
+ declare class ApiInvalidResponse extends ApiInvalidResponse_base {}
136
+ declare const ApiAuthRedirect_base: Schema.Class<
137
+ ApiAuthRedirect,
138
+ Schema.TaggedStruct<
139
+ "ApiAuthRedirect",
140
+ {
141
+ readonly endpoint: Schema.String;
142
+ }
143
+ >,
144
+ _$effect_Cause0.YieldableError
145
+ >;
146
+ /**
147
+ * The request was redirected. With `redirect: "manual"` the browser reports
148
+ * status `0`. An expired Cloudflare Access session causes this.
149
+ */
150
+ declare class ApiAuthRedirect extends ApiAuthRedirect_base {}
151
+ declare const PeerConnectionFailedReason: Schema.Literals<
152
+ readonly [
153
+ "connection-failed",
154
+ "connection-closed",
155
+ "ice-failed",
156
+ "ice-closed",
157
+ "ice-disconnected-timeout"
158
+ ]
159
+ >;
160
+ type PeerConnectionFailedReason = typeof PeerConnectionFailedReason.Type;
161
+ declare const PeerConnectionFailed_base: Schema.Class<
162
+ PeerConnectionFailed,
163
+ Schema.TaggedStruct<
164
+ "PeerConnectionFailed",
165
+ {
166
+ readonly reason: Schema.Literals<
167
+ readonly [
168
+ "connection-failed",
169
+ "connection-closed",
170
+ "ice-failed",
171
+ "ice-closed",
172
+ "ice-disconnected-timeout"
173
+ ]
174
+ >;
175
+ }
176
+ >,
177
+ _$effect_Cause0.YieldableError
178
+ >;
179
+ /** The peer connection is not usable any more. */
180
+ declare class PeerConnectionFailed extends PeerConnectionFailed_base {}
181
+ declare const NegotiationOutcomeUnknown_base: Schema.Class<
182
+ NegotiationOutcomeUnknown,
183
+ Schema.TaggedStruct<
184
+ "NegotiationOutcomeUnknown",
185
+ {
186
+ readonly step: Schema.String;
187
+ readonly cause: Schema.Unknown;
188
+ }
189
+ >,
190
+ _$effect_Cause0.YieldableError
191
+ >;
192
+ /**
193
+ * A negotiation step did not complete, and the state of the session on the
194
+ * SFU is not known. The request is not repeated. The session is replaced.
195
+ */
196
+ declare class NegotiationOutcomeUnknown extends NegotiationOutcomeUnknown_base {}
197
+ declare const SessionFailed_base: Schema.Class<
198
+ SessionFailed,
199
+ Schema.TaggedStruct<
200
+ "SessionFailed",
201
+ {
202
+ readonly error: Schema.Union<
203
+ readonly [
204
+ typeof ApiTransportError,
205
+ typeof ApiResponseError,
206
+ typeof ApiInvalidResponse,
207
+ typeof ApiAuthRedirect,
208
+ typeof PeerConnectionFailed,
209
+ typeof NegotiationOutcomeUnknown
210
+ ]
211
+ >;
212
+ }
213
+ >,
214
+ _$effect_Cause0.YieldableError
215
+ >;
216
+ /**
217
+ * The session failed, and its retry policy ended. A push or a pull that waits
218
+ * for a session cannot continue.
219
+ */
220
+ declare class SessionFailed extends SessionFailed_base {}
221
+ declare const TrackError_base: Schema.Class<
222
+ TrackError,
223
+ Schema.TaggedStruct<
224
+ "TrackError",
225
+ {
226
+ readonly trackName: Schema.optional<Schema.String>;
227
+ readonly mid: Schema.optional<Schema.String>;
228
+ readonly errorCode: Schema.String;
229
+ readonly errorDescription: Schema.optional<Schema.String>;
230
+ }
231
+ >,
232
+ _$effect_Cause0.YieldableError
233
+ >;
234
+ /** One track of a request was refused by the SFU. */
235
+ declare class TrackError extends TrackError_base {}
236
+ declare const TransceiverNotFound_base: Schema.Class<
237
+ TransceiverNotFound,
238
+ Schema.TaggedStruct<
239
+ "TransceiverNotFound",
240
+ {
241
+ readonly trackName: Schema.optional<Schema.String>;
242
+ readonly mid: Schema.optional<Schema.String>;
243
+ }
244
+ >,
245
+ _$effect_Cause0.YieldableError
246
+ >;
247
+ /** The SFU answered, but the peer connection has no transceiver for the track. */
248
+ declare class TransceiverNotFound extends TransceiverNotFound_base {}
249
+ declare const SenderError_base: Schema.Class<
250
+ SenderError,
251
+ Schema.TaggedStruct<
252
+ "SenderError",
253
+ {
254
+ readonly operation: Schema.Literals<
255
+ readonly ["replaceTrack", "setParameters"]
256
+ >;
257
+ readonly cause: Schema.Unknown;
258
+ }
259
+ >,
260
+ _$effect_Cause0.YieldableError
261
+ >;
262
+ /** A browser call on a sender rejected (`replaceTrack`, `setParameters`). */
263
+ declare class SenderError extends SenderError_base {}
264
+ declare const MediaAccessError_base: Schema.Class<
265
+ MediaAccessError,
266
+ Schema.TaggedStruct<
267
+ "MediaAccessError",
268
+ {
269
+ readonly operation: Schema.Literals<
270
+ readonly ["enumerateDevices", "getUserMedia", "getDisplayMedia"]
271
+ > /** The `name` of the browser error, for example "NotAllowedError". */;
272
+ readonly errorName: Schema.String;
273
+ readonly message: Schema.String;
274
+ readonly cause: Schema.Unknown;
275
+ }
276
+ >,
277
+ _$effect_Cause0.YieldableError
278
+ >;
279
+ /** A browser call for devices or media rejected. */
280
+ declare class MediaAccessError extends MediaAccessError_base {}
281
+ declare const DevicesExhausted_base: Schema.Class<
282
+ DevicesExhausted,
283
+ Schema.TaggedStruct<
284
+ "DevicesExhausted",
285
+ {
286
+ readonly kind: Schema.Literals<readonly ["audioinput", "videoinput"]>;
287
+ }
288
+ >,
289
+ _$effect_Cause0.YieldableError
290
+ >;
291
+ /** No device of the list gave a healthy track. */
292
+ declare class DevicesExhausted extends DevicesExhausted_base {}
293
+ declare const TransformFailed_base: Schema.Class<
294
+ TransformFailed,
295
+ Schema.TaggedStruct<
296
+ "TransformFailed",
297
+ {
298
+ readonly cause: Schema.Unknown;
299
+ }
300
+ >,
301
+ _$effect_Cause0.YieldableError
302
+ >;
303
+ /** A transformation of a content track failed. */
304
+ declare class TransformFailed extends TransformFailed_base {}
305
+ declare const SinkError_base: Schema.Class<
306
+ SinkError,
307
+ Schema.TaggedStruct<
308
+ "SinkError",
309
+ {
310
+ readonly reason: Schema.Literals<readonly ["not-supported", "rejected"]>;
311
+ readonly cause: Schema.optional<Schema.Unknown>;
312
+ }
313
+ >,
314
+ _$effect_Cause0.YieldableError
315
+ >;
316
+ /** The audio output device was not selected. */
317
+ declare class SinkError extends SinkError_base {}
318
+ type ApiError =
319
+ | ApiTransportError
320
+ | ApiResponseError
321
+ | ApiInvalidResponse
322
+ | ApiAuthRedirect;
323
+ type SessionError = ApiError | PeerConnectionFailed | NegotiationOutcomeUnknown;
324
+ type PushError = ApiError | NegotiationOutcomeUnknown | TrackError;
325
+ type PullError =
326
+ | ApiError
327
+ | NegotiationOutcomeUnknown
328
+ | TrackError
329
+ | TransceiverNotFound;
330
+ type SourceError = DevicesExhausted | MediaAccessError;
331
+ //#endregion
332
+ //#region src/effect/client/MediaDevices.d.ts
333
+ type SafePermissionState = PermissionState | "unknown";
334
+ type PermissionKind = "camera" | "microphone";
335
+ /**
336
+ * The browser calls that the media sources use. The default is the real
337
+ * browser. Tests supply a fake.
338
+ */
339
+ interface MediaDevicesBackend {
340
+ readonly enumerateDevices: Effect.Effect<
341
+ ReadonlyArray<MediaDeviceInfo>,
342
+ MediaAccessError
343
+ >;
344
+ /** Each `devicechange` event. */
345
+ readonly deviceChanges: Stream.Stream<unknown>;
346
+ /** Fails when the Permissions API is not available or rejects the name. */
347
+ readonly permissionStatus: (
348
+ name: PermissionKind
349
+ ) => Effect.Effect<PermissionStatus, unknown>;
350
+ readonly getUserMedia: (
351
+ constraints: MediaStreamConstraints
352
+ ) => Effect.Effect<MediaStream, MediaAccessError>;
353
+ readonly getDisplayMedia: (
354
+ options: DisplayMediaStreamOptions
355
+ ) => Effect.Effect<MediaStream, MediaAccessError>;
356
+ /** Each time the page becomes visible. */
357
+ readonly pageVisible: Stream.Stream<unknown>;
358
+ }
359
+ declare const MediaDevices_base: Context.ServiceClass<
360
+ MediaDevices,
361
+ "effect-cloudflare-webrtc/MediaDevices",
362
+ {
363
+ /**
364
+ * The device list: at the start, after each device change, and after
365
+ * each permission change. A list that is equal to the last list is not
366
+ * given again. All consumers share one source.
367
+ */
368
+ readonly devices: Stream.Stream<
369
+ ReadonlyArray<MediaDeviceInfo>
370
+ > /** The device list now. */;
371
+ readonly enumerateDevices: Effect.Effect<
372
+ ReadonlyArray<MediaDeviceInfo>,
373
+ MediaAccessError
374
+ > /** The permission state and its changes. "unknown" if not available. */;
375
+ readonly permissionState: (
376
+ name: PermissionKind
377
+ ) => Stream.Stream<SafePermissionState> /** The tracks are stopped when the scope closes. */;
378
+ readonly getUserMedia: (
379
+ constraints: MediaStreamConstraints
380
+ ) => Effect.Effect<
381
+ MediaStream,
382
+ MediaAccessError,
383
+ Scope.Scope
384
+ > /** The tracks are stopped when the scope closes. */;
385
+ readonly getDisplayMedia: (
386
+ options: DisplayMediaStreamOptions
387
+ ) => Effect.Effect<
388
+ MediaStream,
389
+ MediaAccessError,
390
+ Scope.Scope
391
+ > /** Each time the page becomes visible. */;
392
+ readonly pageVisible: Stream.Stream<void>;
393
+ }
394
+ >;
395
+ /** Devices, permissions, and media capture. Tests replace this service. */
396
+ declare class MediaDevices extends MediaDevices_base {
397
+ static layerBackend: (
398
+ backend: MediaDevicesBackend
399
+ ) => Layer.Layer<MediaDevices>;
400
+ /** Uses `navigator.mediaDevices` and `navigator.permissions`. */
401
+ static layerBrowser: Layer.Layer<MediaDevices>;
402
+ }
403
+ /** The device list of the `MediaDevices` service. */
404
+ declare const devices: Stream.Stream<
405
+ ReadonlyArray<MediaDeviceInfo>,
406
+ never,
407
+ MediaDevices
408
+ >;
409
+ //#endregion
410
+ //#region src/effect/client/TrackMetadata.d.ts
411
+ /**
412
+ * What one party sends to a different party, so that it can pull the track.
413
+ * Use `Schema.decodeUnknownEffect(TrackMetadata)` to validate metadata that
414
+ * comes from the network.
415
+ */
416
+ declare const TrackMetadata: Schema.Struct<{
417
+ readonly sessionId: Schema.String;
418
+ readonly trackName: Schema.String;
419
+ readonly location: Schema.Literal<"remote">;
420
+ }>;
421
+ type TrackMetadata = typeof TrackMetadata.Type;
422
+ //#endregion
423
+ //#region src/effect/client/ConnectionStats.d.ts
424
+ /**
425
+ * One sample of the statistics of a session. Each count and each rate is for
426
+ * the time since the previous sample of the same RTP stream.
427
+ */
428
+ interface ConnectionStats {
429
+ readonly sessionId: string;
430
+ /** The selected ICE candidate pair. `null` while no pair is selected. */
431
+ readonly transport: TransportStats | null;
432
+ /** The pushed tracks. A track shows from its second sample. */
433
+ readonly sent: ReadonlyArray<SentTrackStats>;
434
+ /** The pulled tracks. A track shows from its second sample. */
435
+ readonly received: ReadonlyArray<ReceivedTrackStats>;
436
+ }
437
+ interface TransportStats {
438
+ /** The round-trip time to the SFU, from the last STUN check. */
439
+ readonly roundTripTimeMillis: number | null;
440
+ /** The estimate of the browser, in bits per second. */
441
+ readonly availableOutgoingBitrate: number | null;
442
+ /** The estimate of the browser, in bits per second. */
443
+ readonly availableIncomingBitrate: number | null;
444
+ }
445
+ interface SentTrackStats {
446
+ readonly trackName: string;
447
+ readonly kind: "audio" | "video";
448
+ /** One entry for each RTP stream: a simulcast track has one per layer. */
449
+ readonly streams: ReadonlyArray<SentStreamStats>;
450
+ }
451
+ interface SentStreamStats {
452
+ /** The simulcast layer. `null` for a track without simulcast. */
453
+ readonly rid: string | null;
454
+ /** Bits per second. */
455
+ readonly bitrate: number;
456
+ readonly packetsSent: number;
457
+ readonly framesPerSecond: number | null;
458
+ /** Why the browser sends less than the source gives. Video only. */
459
+ readonly qualityLimitationReason: QualityLimitationReason | null;
460
+ /**
461
+ * From the receiver reports of the SFU, which tell what arrived there.
462
+ * `null` until the first report.
463
+ */
464
+ readonly remote: RemoteReceptionStats | null;
465
+ }
466
+ type QualityLimitationReason = "none" | "cpu" | "bandwidth" | "other";
467
+ interface RemoteReceptionStats {
468
+ /** The packets that did not arrive at the SFU. */
469
+ readonly packetsLost: number;
470
+ /** The part of the packets that was lost, from 0 to 1, in the last report. */
471
+ readonly fractionLost: number | null;
472
+ readonly jitterMillis: number | null;
473
+ readonly roundTripTimeMillis: number | null;
474
+ }
475
+ interface ReceivedTrackStats {
476
+ readonly metadata: TrackMetadata;
477
+ readonly kind: "audio" | "video";
478
+ /** Bits per second. */
479
+ readonly bitrate: number;
480
+ readonly packetsReceived: number;
481
+ /** The packets that did not arrive from the SFU. */
482
+ readonly packetsLost: number;
483
+ readonly jitterMillis: number | null;
484
+ readonly framesPerSecond: number | null;
485
+ /** The number of video freezes. */
486
+ readonly freezeCount: number | null;
487
+ /**
488
+ * The part of the audio samples that the browser made up to hide lost
489
+ * packets, from 0 to 1.
490
+ */
491
+ readonly concealedFraction: number | null;
492
+ }
493
+ interface StatsOptions {
494
+ /** The time between two samples. Default: 2 seconds. */
495
+ readonly interval?: Duration.Input;
496
+ }
497
+ //#endregion
498
+ //#region src/effect/client/PeerConnections.d.ts
499
+ declare const PeerConnections_base: Context.ServiceClass<
500
+ PeerConnections,
501
+ "effect-cloudflare-webrtc/PeerConnections",
502
+ {
503
+ /** The peer connection is closed when the scope closes. */ readonly make: (
504
+ configuration: RTCConfiguration
505
+ ) => Effect.Effect<RTCPeerConnection, never, Scope.Scope>;
506
+ }
507
+ >;
508
+ /** Makes peer connections. Tests replace this service with a fake. */
509
+ declare class PeerConnections extends PeerConnections_base {
510
+ /** Uses the `RTCPeerConnection` of the browser. */
511
+ static layerBrowser: Layer.Layer<PeerConnections>;
512
+ }
513
+ //#endregion
514
+ //#region src/effect/client/internal/schemas.d.ts
515
+ declare const TracksResponse: Schema.Struct<{
516
+ readonly requiresImmediateRenegotiation: Schema.optional<Schema.Boolean>;
517
+ readonly sessionDescription: Schema.optional<
518
+ Schema.Struct<{
519
+ readonly type: Schema.Literals<readonly ["offer", "answer"]>;
520
+ readonly sdp: Schema.String;
521
+ }>
522
+ >;
523
+ readonly tracks: Schema.optional<
524
+ Schema.$Array<
525
+ Schema.Struct<{
526
+ readonly trackName: Schema.optional<Schema.String>;
527
+ readonly sessionId: Schema.optional<Schema.String>;
528
+ readonly mid: Schema.optional<Schema.NullOr<Schema.String>>;
529
+ readonly errorCode: Schema.optional<Schema.String>;
530
+ readonly errorDescription: Schema.optional<Schema.String>;
531
+ }>
532
+ >
533
+ >;
534
+ }>;
535
+ type TracksResponse = typeof TracksResponse.Type;
536
+ //#endregion
537
+ //#region src/effect/client/Config.d.ts
538
+ /**
539
+ * A retry policy. The input of the schedule is the error of the attempt that
540
+ * failed.
541
+ */
542
+ type RetrySchedule = Schedule.Schedule<unknown, unknown>;
543
+ interface RealtimeConfig {
544
+ /** Path or full URL of the proxy route. Default: "/realtime". */
545
+ readonly prefix?: string;
546
+ /** Added to the query string of each request. */
547
+ readonly apiExtraParams?: string | URLSearchParams;
548
+ /**
549
+ * Added to each request. A function is called for each request, for
550
+ * example for a token that changes.
551
+ */
552
+ readonly headers?: HeadersInit | (() => HeadersInit);
553
+ /** Skips the request for ICE servers. */
554
+ readonly iceServers?: ReadonlyArray<RTCIceServer>;
555
+ /** How many API requests and responses the history keeps. Default: 100. */
556
+ readonly maxApiHistory?: number;
557
+ /**
558
+ * `HttpClient` adds `traceparent` and `b3` headers to each request.
559
+ * Default: true, the default of Effect. Set to false to remove them, for
560
+ * example for a cross-origin prefix.
561
+ */
562
+ readonly tracePropagation?: boolean;
563
+ /**
564
+ * Applies when the session cannot be made or fails.
565
+ * Default: 250 ms, factor 2, maximum 10 s, no end.
566
+ */
567
+ readonly sessionRetry?: RetrySchedule;
568
+ /**
569
+ * Applies to each push and pull.
570
+ * Default: 250 ms, factor 2, maximum 10 s, no end.
571
+ */
572
+ readonly trackRetry?: RetrySchedule;
573
+ /**
574
+ * How long `iceConnectionState` can stay `disconnected` before the session
575
+ * is replaced. Default: 7 s.
576
+ */
577
+ readonly iceDisconnectedTimeout?: Duration.Input;
578
+ /**
579
+ * The time limit of each API request except a pull (see `pullTimeout`),
580
+ * of each browser SDP call and of the wait for a stable
581
+ * signaling state. Default: 5 s.
582
+ */
583
+ readonly negotiationTimeout?: Duration.Input;
584
+ /**
585
+ * The time limit of a request that pulls remote tracks. The SFU answers
586
+ * it only when each remote track has media, or when it stops waiting for
587
+ * the media, which takes about 8 s. A pull request that runs out of time
588
+ * replaces the session. Default: 15 s.
589
+ */
590
+ readonly pullTimeout?: Duration.Input;
591
+ /** The maximum number of tracks in one request. Default: 32. */
592
+ readonly maxBatchSize?: number;
593
+ /**
594
+ * How long the session stays open after the last push or pull closes.
595
+ * Default: 5 s.
596
+ */
597
+ readonly sessionIdleTimeout?: Duration.Input;
598
+ /**
599
+ * A session must stay connected for this time before the retry delay of
600
+ * the session starts again from its first value. Default: 10 s.
601
+ */
602
+ readonly sessionStableAfter?: Duration.Input;
603
+ }
604
+ declare const defaultRetrySchedule: RetrySchedule;
605
+ //#endregion
606
+ //#region src/effect/client/RealtimeApi.d.ts
607
+ /** One entry of the API history. Useful for logs and for debugging. */
608
+ type ApiHistoryEntry =
609
+ | {
610
+ readonly type: "request";
611
+ readonly method: string;
612
+ readonly endpoint: string;
613
+ readonly body: unknown;
614
+ }
615
+ | {
616
+ readonly type: "response";
617
+ readonly endpoint: string;
618
+ readonly status: number;
619
+ readonly body: unknown;
620
+ };
621
+ /** The header that carries the session token to `routeRealtimeRequest`. */
622
+ declare const sessionTokenHeader = "x-realtime-session-token";
623
+ /** Identifies a session in a request. */
624
+ interface SessionAuth {
625
+ readonly sessionId: string;
626
+ /** From `sessions/new`, when the server route locks the session. */
627
+ readonly token: string | undefined;
628
+ }
629
+ interface PullTrackRequest {
630
+ readonly sessionId: string;
631
+ readonly trackName: string;
632
+ /** The simulcast layer. The empty string means no preference. */
633
+ readonly preferredRid: string | undefined;
634
+ }
635
+ interface UpdateTrackRequest extends PullTrackRequest {
636
+ readonly mid: string;
637
+ }
638
+ declare const RealtimeApi_base: Context.ServiceClass<
639
+ RealtimeApi,
640
+ "effect-cloudflare-webrtc/RealtimeApi",
641
+ {
642
+ readonly newSession: Effect.Effect<SessionAuth, ApiError>;
643
+ readonly iceServers: Effect.Effect<
644
+ ReadonlyArray<RTCIceServer>,
645
+ ApiError
646
+ > /** Publishes local tracks. `offer` is the SDP of the local offer. */;
647
+ readonly pushTracks: (
648
+ session: SessionAuth,
649
+ offer: string,
650
+ tracks: ReadonlyArray<{
651
+ readonly trackName: string;
652
+ readonly mid: string;
653
+ }>
654
+ ) => Effect.Effect<
655
+ TracksResponse,
656
+ ApiError
657
+ > /** Subscribes to remote tracks. The response can contain an offer. */;
658
+ readonly pullTracks: (
659
+ session: SessionAuth,
660
+ tracks: ReadonlyArray<PullTrackRequest>
661
+ ) => Effect.Effect<
662
+ TracksResponse,
663
+ ApiError
664
+ > /** Sends the answer to an offer of the SFU. */;
665
+ readonly renegotiate: (
666
+ session: SessionAuth,
667
+ answer: string
668
+ ) => Effect.Effect<
669
+ void,
670
+ ApiError
671
+ > /** Changes the simulcast layer of pulled tracks. */;
672
+ readonly updateTracks: (
673
+ session: SessionAuth,
674
+ tracks: ReadonlyArray<UpdateTrackRequest>
675
+ ) => Effect.Effect<TracksResponse, ApiError>;
676
+ /** Closes tracks. `offer` is the SDP of the local offer. */
677
+ /**
678
+ * With no offer, the tracks are closed with `force` and with no
679
+ * negotiation.
680
+ */
681
+ readonly closeTracks: (
682
+ session: SessionAuth,
683
+ offer: string | undefined,
684
+ mids: ReadonlyArray<string>
685
+ ) => Effect.Effect<
686
+ TracksResponse,
687
+ ApiError
688
+ > /** The last requests and responses. */;
689
+ readonly history: Effect.Effect<
690
+ ReadonlyArray<ApiHistoryEntry>
691
+ > /** Each request and response when it occurs. */;
692
+ readonly events: Stream.Stream<ApiHistoryEntry>;
693
+ }
694
+ >;
695
+ /**
696
+ * Typed requests to the server route (`routeRealtimeRequest`), which
697
+ * forwards them to the Realtime SFU API.
698
+ */
699
+ declare class RealtimeApi extends RealtimeApi_base {
700
+ /** Needs an `HttpClient`. Use `redirect: "manual"` in a browser. */
701
+ static layer: (
702
+ config?: RealtimeConfig
703
+ ) => Layer.Layer<RealtimeApi, never, HttpClient.HttpClient>;
704
+ }
705
+ //#endregion
706
+ //#region src/effect/client/internal/Negotiator.d.ts
707
+ /** A transceiver that was added (push) or resolved (pull). */
708
+ interface TransceiverEvent {
709
+ readonly direction: "send" | "receive";
710
+ readonly sessionId: string;
711
+ readonly transceiver: RTCRtpTransceiver;
712
+ }
713
+ //#endregion
714
+ //#region src/effect/client/RealtimeClient.d.ts
715
+ type SessionState =
716
+ /** No push and no pull is active. There is no peer connection. */ | {
717
+ readonly _tag: "Idle";
718
+ } /** The session and the ICE servers are requested. */
719
+ | {
720
+ readonly _tag: "Connecting";
721
+ readonly attempt: number;
722
+ } /** A peer connection exists. Negotiation is possible. */
723
+ | {
724
+ readonly _tag: "Open";
725
+ readonly sessionId: string;
726
+ readonly peerConnection: RTCPeerConnection;
727
+ readonly connectionState: RTCPeerConnectionState;
728
+ } /** The session failed. A new one is made after the retry delay. */
729
+ | {
730
+ readonly _tag: "Reconnecting";
731
+ readonly error: SessionError;
732
+ readonly attempt: number;
733
+ } /** The retry policy of the session ended. No new session is made. */
734
+ | {
735
+ readonly _tag: "Failed";
736
+ readonly error: SessionError;
737
+ };
738
+ interface PushOptions {
739
+ /** Used when the transceiver is added. A later value is applied with `setSendEncodings`. */
740
+ readonly sendEncodings?: ReadonlyArray<RTCRtpEncodingParameters>;
741
+ /** Default: a random UUID. */
742
+ readonly trackName?: string;
743
+ }
744
+ type PushState<E = never> = /** The source has not given a track. */ | {
745
+ readonly _tag: "WaitingForTrack";
746
+ } /** The session is not open. */
747
+ | {
748
+ readonly _tag: "WaitingForSession";
749
+ } /** The offer is in the queue or in progress. */
750
+ | {
751
+ readonly _tag: "Negotiating";
752
+ }
753
+ /**
754
+ * The SFU accepted the track, and the track has sent no data yet. Other
755
+ * parties cannot pull it. This state has no time limit: a track of an
756
+ * audio context sends no data before the first user gesture, and a muted
757
+ * source sends no data until it is unmuted.
758
+ */
759
+ | {
760
+ readonly _tag: "WaitingForData";
761
+ readonly transceiver: RTCRtpTransceiver;
762
+ }
763
+ | {
764
+ readonly _tag: "Published";
765
+ readonly metadata: TrackMetadata;
766
+ readonly transceiver: RTCRtpTransceiver;
767
+ } /** The last attempt failed. The next attempt comes after the retry delay. */
768
+ | {
769
+ readonly _tag: "Retrying";
770
+ readonly error: PushError;
771
+ readonly attempt: number;
772
+ }
773
+ /**
774
+ * The source failed, the session failed, or no more attempts are made. The
775
+ * track is closed.
776
+ */
777
+ | {
778
+ readonly _tag: "Failed";
779
+ readonly error: E | PushError | SessionFailed;
780
+ };
781
+ interface PushedTrack<E = never> {
782
+ /** Stable for the life of the handle, also across reconnects. */
783
+ readonly trackName: string;
784
+ readonly state: Subscribable<PushState<E>>;
785
+ /**
786
+ * The metadata each time the track is published: at the start, and after
787
+ * each reconnect. Send it to the parties that pull the track.
788
+ */
789
+ readonly metadata: Stream.Stream<TrackMetadata>;
790
+ /**
791
+ * Applies new encodings to the sender. A value that is set during a
792
+ * negotiation is applied when the transceiver is ready. The value is also
793
+ * used after a reconnect.
794
+ */
795
+ readonly setSendEncodings: (
796
+ encodings: ReadonlyArray<RTCRtpEncodingParameters>
797
+ ) => Effect.Effect<void, SenderError>;
798
+ }
799
+ interface PullOptions {
800
+ /**
801
+ * The first simulcast layer. The first pull of a track supplies it. Change
802
+ * it with `setPreferredRid`.
803
+ */
804
+ readonly preferredRid?: string;
805
+ }
806
+ type PullState<E = never> =
807
+ | {
808
+ readonly _tag: "WaitingForMetadata";
809
+ }
810
+ | {
811
+ readonly _tag: "WaitingForSession";
812
+ readonly metadata: TrackMetadata;
813
+ }
814
+ | {
815
+ readonly _tag: "Negotiating";
816
+ readonly metadata: TrackMetadata;
817
+ }
818
+ | {
819
+ readonly _tag: "Live";
820
+ readonly metadata: TrackMetadata;
821
+ readonly track: MediaStreamTrack;
822
+ readonly transceiver: RTCRtpTransceiver;
823
+ }
824
+ | {
825
+ readonly _tag: "Retrying";
826
+ readonly metadata: TrackMetadata;
827
+ readonly error: PullError;
828
+ readonly attempt: number;
829
+ }
830
+ /**
831
+ * The metadata stream failed, the session failed, or no more attempts are
832
+ * made.
833
+ */
834
+ | {
835
+ readonly _tag: "Failed";
836
+ readonly error: E | PullError | SessionFailed;
837
+ };
838
+ interface PulledTrack<E = never> {
839
+ readonly state: Subscribable<PullState<E>>;
840
+ /**
841
+ * Each new track: at the start, after a change of the metadata, and after
842
+ * a reconnect.
843
+ */
844
+ readonly track: Stream.Stream<MediaStreamTrack>;
845
+ /**
846
+ * Changes the simulcast layer of the track. No new track is made. A value
847
+ * that is set during a negotiation is sent when the track is live. The
848
+ * value belongs to the track, so a call on any pull of the track sets it,
849
+ * and it is also used when the track is pulled again.
850
+ */
851
+ readonly setPreferredRid: (
852
+ rid: string
853
+ ) => Effect.Effect<void, ApiError | TrackError>;
854
+ }
855
+ declare const RealtimeClient_base: Context.ServiceClass<
856
+ RealtimeClient,
857
+ "effect-cloudflare-webrtc/RealtimeClient",
858
+ {
859
+ readonly sessionState: Subscribable<SessionState> /** Publishes a track while the scope is open. */;
860
+ readonly push: <E = never, R = never>(
861
+ source: Stream.Stream<MediaStreamTrack, E, R>,
862
+ options?: PushOptions
863
+ ) => Effect.Effect<
864
+ PushedTrack<E>,
865
+ never,
866
+ R | Scope.Scope
867
+ > /** Pulls a track while the scope is open. */;
868
+ readonly pull: <E = never, R = never>(
869
+ metadata: TrackMetadata | Stream.Stream<TrackMetadata, E, R>,
870
+ options?: PullOptions
871
+ ) => Effect.Effect<
872
+ PulledTrack<E>,
873
+ never,
874
+ R | Scope.Scope
875
+ > /** Each transceiver that is added (push) or resolved (pull). No replay. */;
876
+ readonly transceivers: Stream.Stream<TransceiverEvent>;
877
+ /**
878
+ * The statistics of the open session and of its pushed and pulled
879
+ * tracks, at each interval. It gives nothing while no session is open,
880
+ * and starts again with each new session. It does not keep a session
881
+ * open. Each run reads the statistics on its own.
882
+ */
883
+ readonly stats: (
884
+ options?: StatsOptions
885
+ ) => Stream.Stream<ConnectionStats> /** The last API requests and responses. */;
886
+ readonly history: Effect.Effect<
887
+ ReadonlyArray<ApiHistoryEntry>
888
+ > /** Each API request and response when it occurs. */;
889
+ readonly apiEvents: Stream.Stream<ApiHistoryEntry>;
890
+ }
891
+ >;
892
+ /** Pushes local tracks to the Realtime SFU and pulls remote tracks from it. */
893
+ declare class RealtimeClient extends RealtimeClient_base {
894
+ /** Needs `RealtimeApi` and `PeerConnections`. */
895
+ static layer: (
896
+ config?: RealtimeConfig
897
+ ) => Layer.Layer<RealtimeClient, never, RealtimeApi | PeerConnections>;
898
+ /**
899
+ * All defaults for a browser: `fetch`, `RTCPeerConnection`, the devices
900
+ * of the browser, and device preferences in `localStorage`.
901
+ */
902
+ static layerBrowser: (
903
+ config?: RealtimeConfig & {
904
+ /** Use "include" for a cross-origin prefix. Default: "same-origin". */ readonly credentials?: RequestCredentials;
905
+ }
906
+ ) => Layer.Layer<RealtimeClient | MediaDevices | DevicePreferences>;
907
+ }
908
+ /**
909
+ * Pushes a track while the stream runs, and gives the metadata each time
910
+ * the track is published. Ending the stream closes the track. The stream
911
+ * fails when the push has the `Failed` state.
912
+ *
913
+ * The stream is not shared. Each run is one more push.
914
+ */
915
+ declare const pushStream: <E = never, R = never>(
916
+ source: Stream.Stream<MediaStreamTrack, E, R>,
917
+ options?: PushOptions
918
+ ) => Stream.Stream<
919
+ TrackMetadata,
920
+ E | PushError | SessionFailed,
921
+ R | RealtimeClient
922
+ >;
923
+ /**
924
+ * Pulls a track while the stream runs, and gives each new track. Ending the
925
+ * stream closes the track. The stream fails when the pull has the `Failed`
926
+ * state.
927
+ *
928
+ * The stream is not shared. Each run is one more pull.
929
+ */
930
+ declare const pullStream: <E = never, R = never>(
931
+ metadata: TrackMetadata | Stream.Stream<TrackMetadata, E, R>,
932
+ options?: PullOptions
933
+ ) => Stream.Stream<
934
+ MediaStreamTrack,
935
+ E | PullError | SessionFailed,
936
+ R | RealtimeClient
937
+ >;
938
+ //#endregion
939
+ export {
940
+ TransformFailed as $,
941
+ MediaDevicesBackend as A,
942
+ MediaAccessError as B,
943
+ RemoteReceptionStats as C,
944
+ TransportStats as D,
945
+ StatsOptions as E,
946
+ ApiError as F,
947
+ PushError as G,
948
+ PeerConnectionFailed as H,
949
+ ApiInvalidResponse as I,
950
+ SessionFailed as J,
951
+ SenderError as K,
952
+ ApiResponseError as L,
953
+ SafePermissionState as M,
954
+ devices as N,
955
+ TrackMetadata as O,
956
+ ApiAuthRedirect as P,
957
+ TransceiverNotFound as Q,
958
+ ApiTransportError as R,
959
+ ReceivedTrackStats as S,
960
+ SentTrackStats as T,
961
+ PeerConnectionFailedReason as U,
962
+ NegotiationOutcomeUnknown as V,
963
+ PullError as W,
964
+ SourceError as X,
965
+ SinkError as Y,
966
+ TrackError as Z,
967
+ RetrySchedule as _,
968
+ PushState as a,
969
+ DeviceReference as at,
970
+ ConnectionStats as b,
971
+ SessionState as c,
972
+ TransceiverEvent as d,
973
+ DevicePreferences as et,
974
+ ApiHistoryEntry as f,
975
+ RealtimeConfig as g,
976
+ sessionTokenHeader as h,
977
+ PushOptions as i,
978
+ DeviceFailure as it,
979
+ PermissionKind as j,
980
+ MediaDevices as k,
981
+ pullStream as l,
982
+ SessionAuth as m,
983
+ PullState as n,
984
+ PreferenceStorage as nt,
985
+ PushedTrack as o,
986
+ RealtimeApi as p,
987
+ SessionError as q,
988
+ PulledTrack as r,
989
+ Subscribable as rt,
990
+ RealtimeClient as s,
991
+ PullOptions as t,
992
+ DeviceRanking as tt,
993
+ pushStream as u,
994
+ defaultRetrySchedule as v,
995
+ SentStreamStats as w,
996
+ QualityLimitationReason as x,
997
+ PeerConnections as y,
998
+ DevicesExhausted as z
999
+ };
1000
+ //# sourceMappingURL=RealtimeClient-K7oKgsB9.d.ts.map