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

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-CFLp4co-.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-CFLp4co-.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));
@@ -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-CFLp4co-.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-CFLp4co-.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-CFLp4co-.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.4549";
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.4549",
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.",
@@ -107,12 +107,25 @@ interface CallWire {
107
107
  }>;
108
108
  };
109
109
  };
110
+ /** 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
111
  answer: {
111
112
  body: {
112
113
  participant: string;
113
114
  answer: Sdp;
115
+ pull?: ReadonlyArray<{
116
+ of: string;
117
+ name: TrackName;
118
+ layer?: Layer;
119
+ }>;
120
+ };
121
+ answer: {
122
+ offer?: Sdp;
123
+ tracks?: ReadonlyArray<{
124
+ of: string;
125
+ name: TrackName;
126
+ mid: string;
127
+ }>;
114
128
  };
115
- answer: Record<string, never>;
116
129
  };
117
130
  layer: {
118
131
  body: {