@midsummer-ai/sdk 0.1.0-staging.4546 → 0.1.0-staging.4552

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.
@@ -1,4 +1,4 @@
1
- import { a as CallToken } from "../protocol-_2SNN1Nz.mjs";
1
+ import { a as CallToken } from "../protocol-Cda1THdm.mjs";
2
2
  import { CallTokenInput } from "./index.mjs";
3
3
  //#region src/calls/contract.d.ts
4
4
  interface CallsWorld {
package/calls/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { s as Json } from "../index-c616Dbux.mjs";
2
- import { a as CallToken, c as Layer, d as TrackName, r as CallErrorCode } from "../protocol-_2SNN1Nz.mjs";
2
+ import { a as CallToken, c as Layer, d as TrackName, r as CallErrorCode } from "../protocol-Cda1THdm.mjs";
3
3
  //#region src/calls/index.d.ts
4
4
  /** The most a message sent with `send` carries, as JSON. */
5
5
  declare const MAX_MESSAGE_BYTES: number;
package/calls/index.mjs CHANGED
@@ -347,7 +347,44 @@ function sfuMedia(ctx, auto, declined, offer) {
347
347
  timed();
348
348
  }
349
349
  };
350
- const set = offer ? serial(() => answer(offer)).then(() => true, (error) => {
350
+ /**
351
+ * The tracks asked for before the join's offer is answered, which the room's first reading does: they go with that
352
+ * answer, in one trip, where a pull of their own waited for it and then made another. Undefined once it is sent.
353
+ */
354
+ let early = offer ? [] : void 0;
355
+ let earlyDone;
356
+ const first = async (offered) => {
357
+ let asked = [];
358
+ try {
359
+ await pc.setRemoteDescription(offered);
360
+ await pc.setLocalDescription(await pc.createAnswer());
361
+ asked = early ?? [];
362
+ early = void 0;
363
+ const chunk = asked.filter((track) => publishes(track.of, track.name) && !find(track.of, track.name)).slice(0, PULL_MAX);
364
+ const were = new Map(chunk.map((track) => [track.of, connections.get(track.of)]));
365
+ const answered = await ctx.post("answer", {
366
+ participant: ctx.me,
367
+ answer: sdpOf(pc.localDescription),
368
+ ...chunk.length ? { pull: chunk } : {}
369
+ });
370
+ timed();
371
+ if (chunk.length && answered.offer && answered.tracks) await took(chunk, were, {
372
+ offer: answered.offer,
373
+ tracks: answered.tracks
374
+ });
375
+ } finally {
376
+ early = void 0;
377
+ timed();
378
+ for (const track of asked) pending.delete(key(track.of, track.name));
379
+ }
380
+ const rest = asked.filter((track) => publishes(track.of, track.name) && !find(track.of, track.name));
381
+ if (rest.length && !closed) pull(rest).catch(ctx.failed);
382
+ if (missed) {
383
+ missed = false;
384
+ want(false);
385
+ }
386
+ };
387
+ const set = offer ? (earlyDone = serial(() => first(offer))).then(() => true, (error) => {
351
388
  ctx.failed(error);
352
389
  return false;
353
390
  }) : Promise.resolve(true);
@@ -443,40 +480,46 @@ function sfuMedia(ctx, auto, declined, offer) {
443
480
  ctx.failed(error);
444
481
  });
445
482
  }
483
+ /** Takes what a pull brought: keeps each track's mid, answers the offer, and drops what came from a connection its sender has since left. */
484
+ async function took(chunk, asked, pulledNow) {
485
+ for (const track of pulledNow.tracks) {
486
+ const layer = chunk.find((each) => each.of === track.of && each.name === track.name)?.layer;
487
+ pulled.set(track.mid, {
488
+ of: track.of,
489
+ name: track.name,
490
+ ...layer ? { layer } : {}
491
+ });
492
+ }
493
+ await answer(pulledNow.offer);
494
+ for (const track of pulledNow.tracks) askKey(track.of, track.name);
495
+ const old = pulledNow.tracks.filter((track) => pulled.has(track.mid) && connections.get(track.of) !== asked.get(track.of));
496
+ for (const track of old) {
497
+ if (pulled.get(track.mid)?.track) ctx.ended(track.of, track.name);
498
+ pulled.delete(track.mid);
499
+ }
500
+ if (old.length) {
501
+ missed = true;
502
+ await ctx.post("unpull", {
503
+ participant: ctx.me,
504
+ mids: old.map((track) => track.mid)
505
+ });
506
+ }
507
+ }
446
508
  const pull = (tracks) => {
447
509
  for (const track of tracks) pending.add(key(track.of, track.name));
510
+ if (early && earlyDone) {
511
+ early.push(...tracks);
512
+ return earlyDone;
513
+ }
448
514
  return serial(async () => {
449
515
  try {
450
516
  const still = tracks.filter((track) => publishes(track.of, track.name) && !find(track.of, track.name));
451
517
  for (let at = 0; at < still.length && !closed; at += PULL_MAX) {
452
518
  const chunk = still.slice(at, at + PULL_MAX);
453
- const asked = new Map(chunk.map((track) => [track.of, connections.get(track.of)]));
454
- const pulledNow = await ctx.post("pull", {
519
+ await took(chunk, new Map(chunk.map((track) => [track.of, connections.get(track.of)])), await ctx.post("pull", {
455
520
  participant: ctx.me,
456
521
  tracks: chunk
457
- });
458
- for (const track of pulledNow.tracks) {
459
- const layer = chunk.find((each) => each.of === track.of && each.name === track.name)?.layer;
460
- pulled.set(track.mid, {
461
- of: track.of,
462
- name: track.name,
463
- ...layer ? { layer } : {}
464
- });
465
- }
466
- await answer(pulledNow.offer);
467
- for (const track of pulledNow.tracks) askKey(track.of, track.name);
468
- const old = pulledNow.tracks.filter((track) => pulled.has(track.mid) && connections.get(track.of) !== asked.get(track.of));
469
- for (const track of old) {
470
- if (pulled.get(track.mid)?.track) ctx.ended(track.of, track.name);
471
- pulled.delete(track.mid);
472
- }
473
- if (old.length) {
474
- missed = true;
475
- await ctx.post("unpull", {
476
- participant: ctx.me,
477
- mids: old.map((track) => track.mid)
478
- });
479
- }
522
+ }));
480
523
  }
481
524
  } finally {
482
525
  for (const track of tracks) pending.delete(key(track.of, track.name));
@@ -515,6 +558,7 @@ function sfuMedia(ctx, auto, declined, offer) {
515
558
  publish: (tracks) => serial(async () => {
516
559
  const made = tracks.map(({ name, track }) => ({
517
560
  name,
561
+ track,
518
562
  transceiver: pc.addTransceiver(track, {
519
563
  direction: "sendonly",
520
564
  ...name === "camera" && layersOf(track) ? { sendEncodings: layersOf(track) } : {},
@@ -523,12 +567,14 @@ function sfuMedia(ctx, auto, declined, offer) {
523
567
  }));
524
568
  await pc.setLocalDescription(await pc.createOffer());
525
569
  try {
570
+ const sentIn = (name, track) => name === "camera" && (layersOf(track)?.length ?? 1) < SIMULCAST.length ? { layers: layersOf(track)?.length ?? 1 } : {};
526
571
  const answered = await ctx.post("publish", {
527
572
  participant: ctx.me,
528
573
  offer: sdpOf(pc.localDescription),
529
- tracks: made.map(({ name, transceiver }) => ({
574
+ tracks: made.map(({ name, track, transceiver }) => ({
530
575
  mid: transceiver.mid ?? "",
531
- name
576
+ name,
577
+ ...sentIn(name, track)
532
578
  }))
533
579
  });
534
580
  if (answered.answer) await pc.setRemoteDescription(answered.answer);
@@ -1,2 +1,2 @@
1
- import { a as CallToken, c as Layer, d as TrackName, f as WireParticipant, i as CallOp, l as Sdp, m as WireSignal, n as CALL_STATUS, o as CallWire, p as WireRoom, r as CallErrorCode, s as IceServer, t as CALL_OPS, u as TRACK_KINDS } from "../protocol-_2SNN1Nz.mjs";
1
+ import { a as CallToken, c as Layer, d as TrackName, f as WireParticipant, i as CallOp, l as Sdp, m as WireSignal, n as CALL_STATUS, o as CallWire, p as WireRoom, r as CallErrorCode, s as IceServer, t as CALL_OPS, u as TRACK_KINDS } from "../protocol-Cda1THdm.mjs";
2
2
  export { CALL_OPS, CALL_STATUS, CallErrorCode, CallOp, CallToken, CallWire, IceServer, Layer, Sdp, TRACK_KINDS, TrackName, WireParticipant, WireRoom, WireSignal };
package/calls/react.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { d as TrackName } from "../protocol-_2SNN1Nz.mjs";
1
+ import { d as TrackName } from "../protocol-Cda1THdm.mjs";
2
2
  import { Call, CallError, CallState, LocalTrack, Participant, Rtc, TokenSource } from "./index.mjs";
3
3
  import { AudioHTMLAttributes, ReactNode, VideoHTMLAttributes } from "react";
4
4
  //#region src/calls/react.d.ts
@@ -1,4 +1,4 @@
1
- import { a as CallToken } from "../protocol-_2SNN1Nz.mjs";
1
+ import { a as CallToken } from "../protocol-Cda1THdm.mjs";
2
2
  import { CallTokenInput } from "./index.mjs";
3
3
  //#region src/calls/stand-in.d.ts
4
4
  interface CallsStandIn {
package/here-C2jhTheQ.mjs CHANGED
@@ -12,7 +12,7 @@ function processEnv() {
12
12
  * This package's version: `0.0.0-dev` here, and in a published package the version it was published at, which the
13
13
  * release writes in its place as it stages the package (`stampSdk` in `scripts/release/packages.ts`).
14
14
  */
15
- const SDK_VERSION = "0.1.0-staging.4546";
15
+ const SDK_VERSION = "0.1.0-staging.4552";
16
16
  /**
17
17
  * The header that tells Midsummer which client made each of this package's calls: `Midsummer-Client: sdk/<version>
18
18
  * <part>`, `part` the product whose client it is (`database`, `storage`, `queues`, ...), so the platform counts which
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midsummer-ai/sdk",
3
- "version": "0.1.0-staging.4546",
3
+ "version": "0.1.0-staging.4552",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "description": "Midsummer's handles for an app's code: its Database, Storage, Queues, Vector DB, AI, Email and Agents, with stand-ins for tests.",
@@ -66,6 +66,7 @@ interface CallWire {
66
66
  expiresAt: number;
67
67
  };
68
68
  };
69
+ /** `layers` is how many layers a camera is sent in when that isn't three: 2 for one under 960×540, 1 for one under 480×270. */
69
70
  publish: {
70
71
  body: {
71
72
  participant: string;
@@ -73,6 +74,7 @@ interface CallWire {
73
74
  tracks: ReadonlyArray<{
74
75
  mid?: string;
75
76
  name: TrackName;
77
+ layers?: number;
76
78
  }>;
77
79
  };
78
80
  answer: {
@@ -107,12 +109,25 @@ interface CallWire {
107
109
  }>;
108
110
  };
109
111
  };
112
+ /** With `pull`, the tracks are received as `pull` does once the answer is applied: the next offer and their mids, in one trip. A platform from before it returns neither, and the tracks are asked for with `pull`. */
110
113
  answer: {
111
114
  body: {
112
115
  participant: string;
113
116
  answer: Sdp;
117
+ pull?: ReadonlyArray<{
118
+ of: string;
119
+ name: TrackName;
120
+ layer?: Layer;
121
+ }>;
122
+ };
123
+ answer: {
124
+ offer?: Sdp;
125
+ tracks?: ReadonlyArray<{
126
+ of: string;
127
+ name: TrackName;
128
+ mid: string;
129
+ }>;
114
130
  };
115
- answer: Record<string, never>;
116
131
  };
117
132
  layer: {
118
133
  body: {