@midsummer-ai/sdk 0.1.0-staging.4603 → 0.1.0-staging.4609
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/calls/index.mjs +19 -9
- package/here-C2jhTheQ.mjs +1 -1
- package/package.json +1 -1
package/calls/index.mjs
CHANGED
|
@@ -275,6 +275,7 @@ async function answerOf(response, op) {
|
|
|
275
275
|
const body = await response.json().catch(() => void 0);
|
|
276
276
|
if (response.ok && body && typeof body === "object" && !body.error) return body;
|
|
277
277
|
const code = body?.error?.code, message = body?.error?.message;
|
|
278
|
+
if (code === "unavailable" && typeof message === "string") throw new Unreachable(message);
|
|
278
279
|
if (typeof code === "string" && Object.hasOwn(CALL_STATUS, code) && typeof message === "string") throw new CallError(code, message);
|
|
279
280
|
if (response.status >= 500) throw new Unreachable(`The call returned ${response.status}.`);
|
|
280
281
|
throw new CallError("invalid", `The call returned ${response.status} to ${op}.`);
|
|
@@ -378,12 +379,20 @@ function sfuMedia(ctx, auto, declined, offer) {
|
|
|
378
379
|
let connectBy;
|
|
379
380
|
/** Whether the room changed while a track of it was on its way, so the tracks to receive are worked out again once it has come. */
|
|
380
381
|
let missed = false;
|
|
382
|
+
/**
|
|
383
|
+
* The session's one queue: every change to it on the media server (a publish, a receive, a layer, a stop, the data
|
|
384
|
+
* channels, a restart) waits for the one before it, offer and answer and all. The media server takes a session's
|
|
385
|
+
* changes one at a time and may refuse one that comes while another is on its way: staging, 16 Nov, a publish and the
|
|
386
|
+
* data channels' ask sent together were both refused, about one start in five. Work in the queue calls `ctx.post`
|
|
387
|
+
* itself; anywhere else a change goes through `change`.
|
|
388
|
+
*/
|
|
381
389
|
let chain = Promise.resolve();
|
|
382
390
|
const serial = (work) => {
|
|
383
391
|
const next = chain.then(work, work);
|
|
384
392
|
chain = next.catch(() => void 0);
|
|
385
393
|
return next;
|
|
386
394
|
};
|
|
395
|
+
const change = (op, body) => serial(() => ctx.post(op, body));
|
|
387
396
|
const find = (of, name) => [...pulled].find(([, pull]) => pull.of === of && pull.name === name);
|
|
388
397
|
const videos = () => [...pulled.values()].filter((pull) => TRACK_KINDS[pull.name] === "video");
|
|
389
398
|
const publishes = (of, name) => others.some((other) => other.id === of && other.tracks.some((track) => track.name === name));
|
|
@@ -512,7 +521,7 @@ function sfuMedia(ctx, auto, declined, offer) {
|
|
|
512
521
|
const { next, ask } = layerWatch(pull.layer ?? "h", frames, Date.now(), pull.watch);
|
|
513
522
|
pull.watch = next;
|
|
514
523
|
if (!ask) continue;
|
|
515
|
-
|
|
524
|
+
change("layer", {
|
|
516
525
|
participant: ctx.me,
|
|
517
526
|
mid,
|
|
518
527
|
layer: ask
|
|
@@ -566,16 +575,17 @@ function sfuMedia(ctx, auto, declined, offer) {
|
|
|
566
575
|
}
|
|
567
576
|
/**
|
|
568
577
|
* Asks for the channels, one ask at a time, once the join's offer is answered: a channel needs the connection that
|
|
569
|
-
* set up and no offer of its own, so
|
|
570
|
-
* it. Someone who came while an ask was out is asked for after it;
|
|
571
|
-
* again when the room next changes, which their opening it does; a
|
|
578
|
+
* set up and no offer of its own, so the ask takes its turn in the session's queue behind whatever is being
|
|
579
|
+
* published or received then, never ahead of it. Someone who came while an ask was out is asked for after it;
|
|
580
|
+
* someone whose own isn't open yet is asked for again when the room next changes, which their opening it does; a
|
|
581
|
+
* refusal likewise.
|
|
572
582
|
*/
|
|
573
583
|
function askData() {
|
|
574
584
|
if (dataAsking) dataAgain = true;
|
|
575
585
|
if (dataAsking || closed || own && !unheard().length) return;
|
|
576
586
|
dataAsking = true;
|
|
577
587
|
dataAgain = false;
|
|
578
|
-
set.then((up) => up ? openData
|
|
588
|
+
set.then((up) => up ? serial(openData) : unheard()).then((asked) => {
|
|
579
589
|
dataAsking = false;
|
|
580
590
|
if (dataAgain || unheard().some((of) => !asked.includes(of))) askData();
|
|
581
591
|
}, (error) => {
|
|
@@ -697,7 +707,7 @@ function sfuMedia(ctx, auto, declined, offer) {
|
|
|
697
707
|
await sent.get(name)?.sender.replaceTrack(track);
|
|
698
708
|
},
|
|
699
709
|
async unpublish(names) {
|
|
700
|
-
const answered = await
|
|
710
|
+
const answered = await change("unpublish", {
|
|
701
711
|
participant: ctx.me,
|
|
702
712
|
names
|
|
703
713
|
});
|
|
@@ -717,7 +727,7 @@ function sfuMedia(ctx, auto, declined, offer) {
|
|
|
717
727
|
pulled.delete(mid);
|
|
718
728
|
if (pull.track) ctx.ended(pull.of, pull.name);
|
|
719
729
|
}
|
|
720
|
-
if (gone.length)
|
|
730
|
+
if (gone.length) change("unpull", {
|
|
721
731
|
participant: ctx.me,
|
|
722
732
|
mids: gone.map(([mid]) => mid)
|
|
723
733
|
}).catch(ctx.failed);
|
|
@@ -752,7 +762,7 @@ function sfuMedia(ctx, auto, declined, offer) {
|
|
|
752
762
|
const [mid, pulledTrack] = found;
|
|
753
763
|
if (layer === pulledTrack.layer) return;
|
|
754
764
|
if (layer === "f" && videos().filter((each) => each.layer === "f").length + 1 > 2) throw new CallError("invalid", fullCapProblem);
|
|
755
|
-
await
|
|
765
|
+
await change("layer", {
|
|
756
766
|
participant: ctx.me,
|
|
757
767
|
mid,
|
|
758
768
|
layer
|
|
@@ -768,7 +778,7 @@ function sfuMedia(ctx, auto, declined, offer) {
|
|
|
768
778
|
const [mid, pulledTrack] = found;
|
|
769
779
|
pulled.delete(mid);
|
|
770
780
|
if (pulledTrack.track) ctx.ended(of, name);
|
|
771
|
-
await
|
|
781
|
+
await change("unpull", {
|
|
772
782
|
participant: ctx.me,
|
|
773
783
|
mids: [mid]
|
|
774
784
|
});
|
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.
|
|
15
|
+
const SDK_VERSION = "0.1.0-staging.4609";
|
|
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.
|
|
3
|
+
"version": "0.1.0-staging.4609",
|
|
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.",
|