@mebius-io/web 0.2.0 → 0.4.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/dist/index.d.ts CHANGED
@@ -15,6 +15,18 @@ interface MebiusInitOptions {
15
15
  */
16
16
  gateway: string;
17
17
  }
18
+ /**
19
+ * One playback route Mebius has prepared for a stream, as returned alongside the
20
+ * token by your backend. Pass the list through untouched — Mebius orders it and
21
+ * picks from it. `kind` is a Mebius intent label, not a format: treat both fields
22
+ * as opaque.
23
+ */
24
+ interface MebiusDelivery {
25
+ /** Mebius intent label, e.g. `"fast"` or `"wide"`. Opaque to your app. */
26
+ kind: string;
27
+ /** A Mebius-relative path. Opaque to your app; Mebius resolves it. */
28
+ path: string;
29
+ }
18
30
  /** Options for {@link Mebius.connect}. */
19
31
  interface MebiusConnectOptions {
20
32
  /**
@@ -22,6 +34,29 @@ interface MebiusConnectOptions {
22
34
  * The app secret must never be embedded in client code.
23
35
  */
24
36
  token: string;
37
+ /**
38
+ * The `deliveries` list your backend received together with the token. Pass it
39
+ * through as-is and Mebius will pick the best route for each viewer's device,
40
+ * falling back automatically if one stops delivering frames.
41
+ *
42
+ * Optional: without it playback still works, but every viewer is served from
43
+ * Mebius origin rather than the nearest edge.
44
+ */
45
+ deliveries?: MebiusDelivery[];
46
+ /**
47
+ * Quality reporting credential from the same token response
48
+ * (`beaconToken`). Pass it through and Mebius shows this stream's publish and
49
+ * playback quality in your dashboard, and counts viewer minutes from it.
50
+ *
51
+ * Optional: without it the stream works exactly the same, you just see no
52
+ * quality data for it. Safe in the client — it can only report telemetry for
53
+ * this one stream.
54
+ */
55
+ beaconToken?: string;
56
+ /** Where to report it, from the same token response (`beaconUrl`). */
57
+ beaconUrl?: string;
58
+ /** Your own id for the person on this connection, if you want it in reports. */
59
+ userId?: string;
25
60
  }
26
61
  /** A media capture constraint: enable/disable, or a detailed constraint set. */
27
62
  type MediaConstraint = boolean | MediaTrackConstraints;
@@ -34,17 +69,21 @@ interface BroadcasterOptions {
34
69
  }
35
70
  /**
36
71
  * Playback mode.
72
+ * - `"auto"` — recommended. Mebius picks per viewer and falls back on its own.
37
73
  * - `"low-latency"` — minimal (sub-second) delay, best for interactive/real-time
38
74
  * viewing. Web browsers only.
75
+ * - `"balanced"` — a low delay that still scales to a large audience. Web
76
+ * browsers with Media Source support (i.e. not iOS Safari).
39
77
  * - `"scale"` — optimized for the largest audiences; higher delay. Plays on
40
78
  * every platform, including iOS Safari.
41
79
  *
42
80
  * Mebius picks the right delivery method for each mode automatically.
43
81
  */
44
- type PlaybackMode = "low-latency" | "scale";
82
+ type PlaybackMode = "auto" | "low-latency" | "balanced" | "scale";
45
83
  /** Options for {@link MebiusClient.createPlayer}. */
46
84
  interface PlayerOptions {
47
- mode: PlaybackMode;
85
+ /** Defaults to `"auto"` — let Mebius choose per viewer. */
86
+ mode?: PlaybackMode;
48
87
  }
49
88
  /**
50
89
  * Where a player renders video: a `<video>` element, or a CSS selector that
@@ -151,6 +190,15 @@ declare class SignalingClient {
151
190
  private headers;
152
191
  /** Append the access token as a query param (the form the engine enforces). */
153
192
  private withToken;
193
+ /**
194
+ * Absolute, tokenized URL for a gateway-relative delivery path handed to us
195
+ * by the gateway (`deliveries[].path`). The gateway decides which paths exist
196
+ * and in what order; the SDK only resolves them against its own base and
197
+ * attaches the access token. Anything that is not a plain gateway-relative
198
+ * path is rejected rather than fetched: an absolute URL there would send the
199
+ * token to a host we did not choose.
200
+ */
201
+ deliveryUrl(path: string): string;
154
202
  /** Playlist URL for scale-mode playback. */
155
203
  scalePlaylistUrl(streamId: string): string;
156
204
  private pathFor;
@@ -163,6 +211,13 @@ declare class SignalingClient {
163
211
  deleteResource(resourceUrl: string | null): Promise<void>;
164
212
  }
165
213
 
214
+ interface TelemetryTarget {
215
+ /** Absolute beacon URL, as returned with the token. */
216
+ url: string;
217
+ /** Beacon credential, as returned with the token. */
218
+ token: string;
219
+ }
220
+
166
221
  /**
167
222
  * Publishes the local camera/microphone to a Mebius stream.
168
223
  *
@@ -171,13 +226,16 @@ declare class SignalingClient {
171
226
  */
172
227
  declare class MebiusBroadcaster extends TypedEmitter<BroadcasterEventMap> {
173
228
  private readonly options;
229
+ private readonly telemetry;
230
+ private readonly userId?;
174
231
  private readonly transport;
175
232
  private stream;
176
233
  private facingMode;
177
234
  private statsTimer;
178
235
  private started;
236
+ private reporter;
179
237
  /** @internal */
180
- constructor(signaling: SignalingClient, options: BroadcasterOptions);
238
+ constructor(signaling: SignalingClient, options: BroadcasterOptions, telemetry?: TelemetryTarget | null, userId?: string | undefined);
181
239
  /** Begin broadcasting under the given stream id. */
182
240
  start(streamId: string): Promise<void>;
183
241
  /** Stop broadcasting and release the camera/microphone. */
@@ -202,22 +260,28 @@ declare class MebiusBroadcaster extends TypedEmitter<BroadcasterEventMap> {
202
260
  /**
203
261
  * Plays a Mebius stream into a `<video>` element.
204
262
  *
205
- * Create one with {@link MebiusClient.createPlayer}, choosing a playback
206
- * {@link PlaybackMode | mode}; Mebius selects the right delivery automatically.
263
+ * Create one with {@link MebiusClient.createPlayer}, optionally choosing a
264
+ * playback {@link PlaybackMode | mode}; Mebius selects the delivery route, and
265
+ * moves to the next one by itself if the current one stops producing frames.
207
266
  */
208
267
  declare class MebiusPlayer extends TypedEmitter<PlayerEventMap> {
209
- private readonly transport;
268
+ private readonly telemetry;
269
+ private readonly userId?;
270
+ private readonly candidates;
271
+ private transport;
210
272
  private video;
211
273
  private statsTimer;
212
274
  private playing;
275
+ private reporter;
213
276
  /** @internal */
214
- constructor(signaling: SignalingClient, options: PlayerOptions);
277
+ constructor(signaling: SignalingClient, options?: PlayerOptions, deliveries?: readonly MebiusDelivery[], telemetry?: TelemetryTarget | null, userId?: string | undefined);
215
278
  /** Start playing `streamId` into the given video element or selector. */
216
279
  play(streamId: string, viewTarget: ViewTarget): Promise<void>;
217
280
  /** Stop playback and detach from the video element. */
218
281
  stop(): Promise<void>;
219
282
  /** Set output volume in the range 0..1. */
220
283
  setVolume(volume: number): void;
284
+ private attach;
221
285
  private startStats;
222
286
  private stopStats;
223
287
  }
@@ -228,17 +292,32 @@ declare class MebiusPlayer extends TypedEmitter<PlayerEventMap> {
228
292
  */
229
293
  declare class MebiusClient extends TypedEmitter<ClientEventMap> {
230
294
  private readonly token;
295
+ private readonly deliveries;
296
+ private readonly telemetry;
297
+ private readonly userId?;
231
298
  private readonly signaling;
232
299
  private expiryTimer;
233
300
  private connected;
234
301
  /** @internal */
235
- constructor(config: MebiusInitOptions, token: string);
302
+ constructor(config: MebiusInitOptions, token: string, deliveries?: readonly MebiusDelivery[], telemetry?: TelemetryTarget | null, userId?: string | undefined);
236
303
  /** @internal Called by {@link Mebius.connect}. */
237
304
  open(): void;
238
305
  /** Create a broadcaster bound to this connection. */
239
306
  createBroadcaster(options?: BroadcasterOptions): MebiusBroadcaster;
240
307
  /** Create a player bound to this connection. */
241
- createPlayer(options: PlayerOptions): MebiusPlayer;
308
+ createPlayer(options?: PlayerOptions): MebiusPlayer;
309
+ /**
310
+ * Create a monitor: a player tuned for watching a stream you are interacting
311
+ * WITH rather than merely watching — the other side of a co-broadcast, where a
312
+ * second or two of delay makes the interaction feel broken.
313
+ *
314
+ * It is a player with the delay budget spent differently, not a different API:
315
+ * it starts on the real-time route and falls back on its own if that route
316
+ * delivers no frames. Apps used to hand-roll this (open a real-time view, run a
317
+ * timer, swap players when it stayed black); getting the fallback wrong showed a
318
+ * black frame to a live audience, so it belongs here rather than in every app.
319
+ */
320
+ createMonitor(): MebiusPlayer;
242
321
  /** Close the connection and release resources. */
243
322
  disconnect(reason?: string): void;
244
323
  private assertConnected;
@@ -264,4 +343,4 @@ declare const Mebius: {
264
343
  _reset(): void;
265
344
  };
266
345
 
267
- export { type BroadcastStats, type BroadcasterEventMap, type BroadcasterOptions, type ClientEventMap, Mebius, MebiusBroadcaster, MebiusClient, type MebiusConnectOptions, MebiusError, type MebiusErrorCode, type MebiusInitOptions, MebiusPlayer, type MediaConstraint, type PlaybackMode, type PlaybackStats, type PlayerEventMap, type PlayerOptions, type ViewTarget, mebiusError };
346
+ export { type BroadcastStats, type BroadcasterEventMap, type BroadcasterOptions, type ClientEventMap, Mebius, MebiusBroadcaster, MebiusClient, type MebiusConnectOptions, type MebiusDelivery, MebiusError, type MebiusErrorCode, type MebiusInitOptions, MebiusPlayer, type MediaConstraint, type PlaybackMode, type PlaybackStats, type PlayerEventMap, type PlayerOptions, type ViewTarget, mebiusError };