@midsummer-ai/sdk 0.1.0-staging.4492 → 0.1.0-staging.4498
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.d.mts +10 -2
- package/calls/index.mjs +14 -3
- package/calls/ui.d.mts +9 -5
- package/calls/ui.mjs +376 -116
- package/here-C2jhTheQ.mjs +1 -1
- package/package.json +1 -1
package/calls/index.d.mts
CHANGED
|
@@ -7,9 +7,15 @@ declare const MAX_MESSAGE_BYTES: number;
|
|
|
7
7
|
declare const MAX_VIDEOS = 9;
|
|
8
8
|
declare const MAX_FULL_VIDEOS = 2;
|
|
9
9
|
/** Why a call or a call's request failed, in words a person reads; `code` is the one the wire carries. */
|
|
10
|
+
/**
|
|
11
|
+
* Why a call failed, in the person's terms, where the code alone can't say: `blocked`, the network let no connection
|
|
12
|
+
* through; `dropped`, a call that was connected lost it and couldn't rejoin; `removed`, someone took you out of the room.
|
|
13
|
+
*/
|
|
14
|
+
type CallFailure = "blocked" | "dropped" | "removed";
|
|
10
15
|
declare class CallError extends Error {
|
|
11
16
|
readonly code: CallErrorCode;
|
|
12
|
-
|
|
17
|
+
readonly reason?: CallFailure | undefined;
|
|
18
|
+
constructor(code: CallErrorCode, why: string, reason?: CallFailure | undefined);
|
|
13
19
|
}
|
|
14
20
|
/** Why a name can't be a room's, or undefined: 1 to 64 letters, digits, `-`, `_` and `.`, starting with a letter or digit. */
|
|
15
21
|
declare function roomProblem(name: unknown): string | undefined;
|
|
@@ -101,6 +107,8 @@ interface Call {
|
|
|
101
107
|
readonly room: string;
|
|
102
108
|
readonly state: CallState;
|
|
103
109
|
readonly error: CallError | undefined;
|
|
110
|
+
/** Whether the room takes voice only: no camera or screen. */
|
|
111
|
+
readonly audioOnly: boolean;
|
|
104
112
|
/** You, as the others see you. */
|
|
105
113
|
readonly me: Participant;
|
|
106
114
|
/** Everyone else in the room, each with the tracks received from them. */
|
|
@@ -144,4 +152,4 @@ interface Call {
|
|
|
144
152
|
*/
|
|
145
153
|
declare function join(room: string, options: JoinOptions): Promise<Call>;
|
|
146
154
|
//#endregion
|
|
147
|
-
export { Call, CallError, type CallErrorCode, CallEvents, CallState, type CallToken, CallTokenInput, JoinOptions, type Json, type Layer, LocalTrack, MAX_FULL_VIDEOS, MAX_MESSAGE_BYTES, MAX_VIDEOS, Participant, Rtc, TokenSource, type TrackName, callToken, identityProblem, join, roomProblem };
|
|
155
|
+
export { Call, CallError, type CallErrorCode, CallEvents, CallFailure, CallState, type CallToken, CallTokenInput, JoinOptions, type Json, type Layer, LocalTrack, MAX_FULL_VIDEOS, MAX_MESSAGE_BYTES, MAX_VIDEOS, Participant, Rtc, TokenSource, type TrackName, callToken, identityProblem, join, roomProblem };
|
package/calls/index.mjs
CHANGED
|
@@ -89,12 +89,13 @@ const SIMULCAST = [
|
|
|
89
89
|
maxBitrate: 15e5
|
|
90
90
|
}
|
|
91
91
|
];
|
|
92
|
-
/** Why a call or a call's request failed, in words a person reads; `code` is the one the wire carries. */
|
|
93
92
|
var CallError = class extends Error {
|
|
94
93
|
code;
|
|
95
|
-
|
|
94
|
+
reason;
|
|
95
|
+
constructor(code, why, reason) {
|
|
96
96
|
super(why);
|
|
97
97
|
this.code = code;
|
|
98
|
+
this.reason = reason;
|
|
98
99
|
this.name = "CallError";
|
|
99
100
|
}
|
|
100
101
|
};
|
|
@@ -276,6 +277,7 @@ function sfuMedia(ctx, auto, declined) {
|
|
|
276
277
|
ctx.arrived(pull.of, pull.name, event.track);
|
|
277
278
|
});
|
|
278
279
|
pc.addEventListener("connectionstatechange", () => {
|
|
280
|
+
if (pc.connectionState === "connected") ctx.reached();
|
|
279
281
|
if (!closed && (pc.connectionState === "failed" || pc.connectionState === "disconnected")) ctx.broken();
|
|
280
282
|
});
|
|
281
283
|
async function openData(from) {
|
|
@@ -497,6 +499,7 @@ function relayMedia(ctx, rejoined) {
|
|
|
497
499
|
for (const text of peer.outbox.splice(0)) channel.send(text);
|
|
498
500
|
});
|
|
499
501
|
pc.addEventListener("connectionstatechange", () => {
|
|
502
|
+
if (pc.connectionState === "connected") ctx.reached();
|
|
500
503
|
if (peers.get(of) !== peer || pc.connectionState !== "failed") return;
|
|
501
504
|
drop(peer);
|
|
502
505
|
if (ctx.me < of) offer(of).catch(ctx.failed);
|
|
@@ -630,6 +633,7 @@ var LiveCall = class {
|
|
|
630
633
|
rtc;
|
|
631
634
|
state = "connecting";
|
|
632
635
|
error;
|
|
636
|
+
audioOnly = false;
|
|
633
637
|
me;
|
|
634
638
|
participants = [];
|
|
635
639
|
local = [];
|
|
@@ -650,6 +654,8 @@ var LiveCall = class {
|
|
|
650
654
|
renewal;
|
|
651
655
|
shown = "";
|
|
652
656
|
left = false;
|
|
657
|
+
/** Whether media ever connected, which tells a dropped call from a network that let nothing through. */
|
|
658
|
+
connectedOnce = false;
|
|
653
659
|
constructor(room, options, rtc) {
|
|
654
660
|
this.room = room;
|
|
655
661
|
this.options = options;
|
|
@@ -785,6 +791,9 @@ var LiveCall = class {
|
|
|
785
791
|
broken: () => {
|
|
786
792
|
if (live()) this.reconnect();
|
|
787
793
|
},
|
|
794
|
+
reached: () => {
|
|
795
|
+
this.connectedOnce = true;
|
|
796
|
+
},
|
|
788
797
|
failed: (error) => {
|
|
789
798
|
if (live()) this.background(error);
|
|
790
799
|
}
|
|
@@ -816,6 +825,7 @@ var LiveCall = class {
|
|
|
816
825
|
}
|
|
817
826
|
/** Takes the room as the wire gives it: who is in it, what they publish, and the state that proves. */
|
|
818
827
|
apply(session, room) {
|
|
828
|
+
this.audioOnly = room.audioOnly;
|
|
819
829
|
if (!session.alive || room.changed < session.changed) return;
|
|
820
830
|
session.changed = room.changed;
|
|
821
831
|
if (room.state === "ended") return this.finish();
|
|
@@ -896,7 +906,7 @@ var LiveCall = class {
|
|
|
896
906
|
} catch (error) {
|
|
897
907
|
if (this.left) return;
|
|
898
908
|
if (!(error instanceof Unreachable)) return this.fail(error);
|
|
899
|
-
if (Date.now() + wait > until) return this.fail(new CallError("unavailable", "The call's connection dropped and couldn't be made again within 30 seconds. Check your network, then join again."));
|
|
909
|
+
if (Date.now() + wait > until) return this.fail(this.connectedOnce ? new CallError("unavailable", "The call's connection dropped and couldn't be made again within 30 seconds. Check your network, then join again.", "dropped") : new CallError("unavailable", "Your network let no connection through to the call. Try another network, or one that allows UDP or TCP port 80.", "blocked"));
|
|
900
910
|
await new Promise((resolve) => setTimeout(resolve, wait));
|
|
901
911
|
wait = Math.min(wait * 2, 4e3);
|
|
902
912
|
}
|
|
@@ -1124,6 +1134,7 @@ var LiveCall = class {
|
|
|
1124
1134
|
const deviceRefused = (error) => error?.name === "NotAllowedError";
|
|
1125
1135
|
const messageOf = (error) => error instanceof Error ? error.message : String(error);
|
|
1126
1136
|
function callErrorOf(error) {
|
|
1137
|
+
if (error instanceof CallError && error.code === "forbidden" && !error.reason && /removed from this call/u.test(error.message)) return new CallError(error.code, error.message, "removed");
|
|
1127
1138
|
if (error instanceof CallError) return error;
|
|
1128
1139
|
return new CallError("unavailable", `The call's connection couldn't be made: ${messageOf(error)}`);
|
|
1129
1140
|
}
|
package/calls/ui.d.mts
CHANGED
|
@@ -31,10 +31,11 @@ type CallProps = JoinCallProps | ShowCallProps;
|
|
|
31
31
|
*/
|
|
32
32
|
declare function Call(props: CallProps): ReactNode;
|
|
33
33
|
/**
|
|
34
|
-
* Everyone in the call as tiles
|
|
35
|
-
* and everyone's sound.
|
|
36
|
-
* At most
|
|
37
|
-
* their
|
|
34
|
+
* Everyone in the call as tiles: you first (from the moment the call starts joining), then the others, those with a
|
|
35
|
+
* camera first; and everyone's sound. While a screen is shared it takes the stage and the people sit in a strip beside
|
|
36
|
+
* it. At most 16 people have a tile of their own, and a last tile shows how many more are in the call. At most 9
|
|
37
|
+
* others' videos are received, each at the layer its tile's width needs and at most 2 at `f`; the rest show their
|
|
38
|
+
* initials.
|
|
38
39
|
*/
|
|
39
40
|
declare function CallGrid({ className }: {
|
|
40
41
|
readonly className?: string;
|
|
@@ -62,7 +63,10 @@ interface CallControlsProps {
|
|
|
62
63
|
};
|
|
63
64
|
readonly className?: string;
|
|
64
65
|
}
|
|
65
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* The call's controls: the room's name, microphone, camera, screen sharing and Leave, and the participant list's
|
|
68
|
+
* button. Each shows what was asked the moment it is pressed, and goes back with a line under it when the call refuses.
|
|
69
|
+
*/
|
|
66
70
|
declare function CallControls({ publish, onLeave, people, className }: CallControlsProps): ReactNode;
|
|
67
71
|
interface ParticipantListProps {
|
|
68
72
|
readonly id?: string;
|
package/calls/ui.mjs
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
import { CallError } from "./index.mjs";
|
|
3
3
|
import { Audio, CallProvider, Video, useCall, useCallError, useCallState, useLocalTracks, useParticipants } from "./react.mjs";
|
|
4
4
|
import { a as TYPE, i as MATERIAL, n as FOUNDATION, r as LIGHT, t as DARK } from "../tokens-BpV8U5E1.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { createContext, createElement, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
6
6
|
//#region src/calls/style.ts
|
|
7
7
|
/**
|
|
8
8
|
* The ready call components' stylesheet (`./ui.ts`), scoped to `.msc` and built from Midsummer's tokens, the same ones
|
|
9
|
-
* sign-in's screens use (`../auth/tokens.ts`), light and dark.
|
|
10
|
-
*
|
|
9
|
+
* sign-in's screens use (`../auth/tokens.ts`), light and dark. The grid is as wide as its rows of 16:9 tiles let it be
|
|
10
|
+
* without scrolling, and never narrower than 150px a tile (then the stage scrolls); with a screen shared it is the stage,
|
|
11
|
+
* the screen on the left and the people in a strip on the right that becomes a row under it when the stage is narrower
|
|
12
|
+
* than 720px. An app themes a call with a few CSS variables, set on the call or on any parent of it:
|
|
11
13
|
*
|
|
12
14
|
* --msc-accent the speaking ring and focus rings; Midsummer's blue when unset
|
|
13
15
|
* --msc-radius the corner of the call, its tiles and panels (12px); buttons follow it
|
|
@@ -41,10 +43,16 @@ function callCss() {
|
|
|
41
43
|
.msc-main{position:relative;display:flex;gap:8px;min-width:0;min-height:0;padding:8px 8px 0}
|
|
42
44
|
.msc-stage{container:msc-stage/size;position:relative;display:grid;flex:1;min-width:0;min-height:0;overflow-y:auto;scrollbar-width:thin}
|
|
43
45
|
|
|
44
|
-
.msc-grid{--_cols:1;--_rows:1;display:grid;grid-template-columns:repeat(var(--_cols),minmax(0,1fr));align-content:center;gap:8px;width:100%;max-width:min(100%,calc((100cqh - (var(--_rows) - 1) * 8px) * 16 / 9 * var(--_cols) / var(--_rows) + (var(--_cols) - 1) * 8px));min-width:0;margin:auto}
|
|
46
|
+
.msc-grid{--_cols:1;--_rows:1;display:grid;grid-template-columns:repeat(var(--_cols),minmax(0,1fr));align-content:center;gap:8px;width:100%;max-width:min(100%,max(calc((100cqh - (var(--_rows) - 1) * 8px) * 16 / 9 * var(--_cols) / var(--_rows) + (var(--_cols) - 1) * 8px),calc(var(--_cols) * 150px + (var(--_cols) - 1) * 8px)));min-width:0;margin:auto}
|
|
45
47
|
.msc-grid[data-cols="2"]{--_cols:2}
|
|
46
48
|
.msc-grid[data-cols="3"]{--_cols:3}
|
|
47
49
|
.msc-grid[data-cols="4"]{--_cols:4}
|
|
50
|
+
.msc-grid[data-screens]{display:grid;grid-template-columns:minmax(0,1fr) 200px;grid-template-rows:minmax(0,1fr);align-self:stretch;align-content:stretch;max-width:none;min-height:0;margin:0}
|
|
51
|
+
.msc-screens{display:grid;grid-auto-rows:minmax(0,1fr);gap:8px;min-width:0;min-height:0}
|
|
52
|
+
.msc-grid[data-screens] .msc-tile[data-screen]{aspect-ratio:auto;min-height:0}
|
|
53
|
+
.msc-strip{display:flex;flex-direction:column;gap:8px;min-width:0;min-height:0;overflow-y:auto;scrollbar-width:thin}
|
|
54
|
+
.msc-strip .msc-tile{flex:none;width:100%}
|
|
55
|
+
@container msc-stage (max-width:719px){.msc-grid[data-screens]{grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr) auto}.msc-strip{flex-direction:row;overflow:auto hidden;padding-block-end:2px}.msc-strip .msc-tile{width:168px}}
|
|
48
56
|
|
|
49
57
|
.msc-tile{container:msc-tile/inline-size;position:relative;display:grid;place-items:center;aspect-ratio:16/9;min-width:0;border-radius:var(--_r);background:var(--_tile);overflow:hidden}
|
|
50
58
|
.msc-tile[data-screen]{grid-column:1/-1}
|
|
@@ -56,6 +64,7 @@ function callCss() {
|
|
|
56
64
|
.msc-video[data-mirror]{transform:scaleX(-1)}
|
|
57
65
|
.msc-avatar{position:relative;display:inline-grid;place-items:center;flex-shrink:0;width:clamp(40px,22cqi,112px);aspect-ratio:1;border-radius:999px;overflow:hidden;background:linear-gradient(155deg,var(--ms-surface-primary),var(--ms-surface-secondary));color:var(--ms-text-secondary);font-size:clamp(14px,7cqi,36px);font-weight:var(--font-weight-medium);letter-spacing:-0.01em;line-height:1;user-select:none}
|
|
58
66
|
.msc-avatar::after{content:"";position:absolute;inset:0;border-radius:inherit;pointer-events:none;box-shadow:inset 0 0 0 1px var(--ms-avatar-rim),inset 0 2px 0 var(--ms-avatar-highlight)}
|
|
67
|
+
.msc-avatar .msc-icon{width:50%;height:50%}
|
|
59
68
|
.msc-tile[data-away] .msc-avatar{opacity:.5}
|
|
60
69
|
.msc-label{position:absolute;inset-inline-start:8px;inset-block-end:8px;z-index:1;display:inline-flex;align-items:center;gap:6px;max-width:calc(100% - 16px);height:24px;padding:0 8px;border-radius:var(--_r-inner);background:oklch(0.2 0 0 / 0.62);color:#fff;${role(TYPE.caption)};font-weight:var(--font-weight-medium);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px)}
|
|
61
70
|
.msc-label .msc-icon{width:14px;height:14px}
|
|
@@ -66,14 +75,14 @@ function callCss() {
|
|
|
66
75
|
.msc-away{flex-shrink:0;font-weight:var(--font-weight-normal);opacity:.8}
|
|
67
76
|
|
|
68
77
|
.msc-notice{position:absolute;inset-block-start:12px;inset-inline:0;z-index:2;display:grid;gap:2px;width:max-content;max-width:calc(100% - 24px);margin-inline:auto;padding:10px 16px;border-radius:var(--_r);background:var(--ms-surface-raised);box-shadow:var(--ms-shadow-menu);text-align:center;animation:msc-enter 160ms var(--motion-ease-out) both}
|
|
69
|
-
.msc-notice-title{
|
|
78
|
+
.msc-notice-title{display:inline-flex;align-items:center;justify-content:center;gap:10px;${role(TYPE["body-medium"])};color:var(--ms-text-primary)}
|
|
70
79
|
.msc-notice-detail{${role(TYPE["body-small"])};color:var(--ms-text-secondary);overflow-wrap:anywhere}
|
|
71
80
|
.msc-overlay{position:absolute;inset:0;z-index:3;display:grid;place-items:center;background:color-mix(in oklab,var(--_surface) 72%,transparent);-webkit-backdrop-filter:blur(3px);backdrop-filter:blur(3px);animation:msc-fade 160ms ease-out both}
|
|
72
81
|
.msc-pill{display:inline-flex;align-items:center;gap:10px;padding:10px 16px;border-radius:var(--_r);background:var(--ms-surface-raised);box-shadow:var(--ms-shadow-menu);${role(TYPE["body-medium"])};color:var(--ms-text-primary)}
|
|
73
82
|
.msc-spinner{width:16px;height:16px;border-radius:999px;border:2px solid color-mix(in oklab,var(--ms-text-primary) 18%,transparent);border-top-color:var(--ms-text-primary);animation:msc-spin 800ms linear infinite}
|
|
74
83
|
|
|
75
84
|
.msc-center{display:grid;justify-items:center;align-content:center;gap:16px;min-height:100%;padding:32px 24px;text-align:center}
|
|
76
|
-
.msc-center-copy{display:grid;gap:4px;max-width:
|
|
85
|
+
.msc-center-copy{display:grid;gap:4px;max-width:48ch}
|
|
77
86
|
.msc-title{${role(TYPE.heading)};color:var(--ms-text-primary);text-wrap:balance;overflow-wrap:anywhere}
|
|
78
87
|
.msc-detail{${role(TYPE["body-small"])};color:var(--ms-text-secondary);text-wrap:pretty;overflow-wrap:anywhere}
|
|
79
88
|
.msc-subject{font-weight:var(--font-weight-medium);color:var(--ms-text-primary)}
|
|
@@ -91,6 +100,8 @@ function callCss() {
|
|
|
91
100
|
.msc-control:active:not(:disabled){background-color:var(--ms-button-secondary-pressed);box-shadow:var(--ms-shadow-button-secondary-pressed)}
|
|
92
101
|
.msc-control:focus-visible{outline:2px solid var(--ms-focus-ring);outline-offset:2px}
|
|
93
102
|
.msc-control[data-off]{color:var(--ms-danger-glyph)}
|
|
103
|
+
.msc-control[data-on]{background-color:var(--ms-accent-fill);background-image:none;border-color:var(--ms-accent-border-hover);color:var(--ms-accent-glyph);box-shadow:none}
|
|
104
|
+
.msc-control[data-on]:hover:not(:disabled){background-color:var(--ms-accent-fill);box-shadow:none}
|
|
94
105
|
.msc-control:disabled{cursor:not-allowed;opacity:.45}
|
|
95
106
|
.msc-control[aria-busy="true"]{cursor:progress}
|
|
96
107
|
.msc-leave{border-color:var(--ms-button-danger-edge);background-color:var(--_danger);background-image:var(--ms-button-danger-sheen);color:var(--ms-button-danger-foreground);box-shadow:var(--ms-shadow-button-danger)}
|
|
@@ -146,10 +157,12 @@ function callCss() {
|
|
|
146
157
|
* <Call room="support-42" token={token} />
|
|
147
158
|
*
|
|
148
159
|
* `token` is what `join` takes: a token the app's server made for the room, or a function that asks for one. The call
|
|
149
|
-
* joins as it mounts, turns on the microphone and camera (the browser asks first)
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* with
|
|
160
|
+
* joins as it mounts, turns on the microphone and camera (the browser asks first) and shows your own tile at once,
|
|
161
|
+
* before the join returns; then it draws every state in words: waiting for others, the call itself, reconnecting, left
|
|
162
|
+
* or ended (with Rejoin), and failed (with what to do and Try again). Every control changes the moment it is pressed
|
|
163
|
+
* and goes back, with a line saying why, when the call refuses. It fills the box it is given, at least 360px tall, so
|
|
164
|
+
* give its parent a height. A call joined elsewhere is drawn with `<Call call={call} />`, and `onRejoin` is what Rejoin
|
|
165
|
+
* and Try again do for it.
|
|
153
166
|
*
|
|
154
167
|
* Its parts are exported too, for a call laid out another way. They go inside `<CallProvider>` from
|
|
155
168
|
* `@midsummer-ai/sdk/calls/react`, best with `autoVideo={false}` so the grid chooses the videos it shows:
|
|
@@ -162,6 +175,7 @@ function callCss() {
|
|
|
162
175
|
*
|
|
163
176
|
* `CallTile` draws one person's tile. The grid shows at most 9 videos, asks for each at the layer its tile's width
|
|
164
177
|
* needs (`q` under 320px, `h` under 720px, `f` above, at most 2 at `f`), and shows everyone else by their initials.
|
|
178
|
+
* While a screen is shared it takes the stage, and the people sit in a strip beside it, or under it on a phone.
|
|
165
179
|
*
|
|
166
180
|
* The look comes from Midsummer's tokens and is themed with CSS variables (`--msc-accent`, `--msc-radius`,
|
|
167
181
|
* `--msc-surface`, `--msc-tile`, `--msc-text`, `--msc-danger`, `--msc-font`; `./style.ts` lists them) and `theme`.
|
|
@@ -170,24 +184,87 @@ const CSS = callCss();
|
|
|
170
184
|
const noop = () => {};
|
|
171
185
|
const cx = (...names) => names.filter(Boolean).join(" ");
|
|
172
186
|
const live = (state) => state === "waiting" || state === "in-call";
|
|
173
|
-
/**
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
if (error instanceof Error && (error.name === "NotAllowedError" || error.name === "NotFoundError"
|
|
189
|
-
return
|
|
190
|
-
}
|
|
187
|
+
/** Whether a call takes a control now: in the call, or joining again after a drop (muting works meanwhile). */
|
|
188
|
+
const takes = (state) => live(state) || state === "reconnecting";
|
|
189
|
+
function whyOf(error) {
|
|
190
|
+
if (error instanceof CallError) {
|
|
191
|
+
if (error.reason) return error.reason;
|
|
192
|
+
const words = error.message;
|
|
193
|
+
switch (error.code) {
|
|
194
|
+
case "forbidden": return /removed/i.test(words) ? "removed" : /allow|microphone|camera|screen/i.test(words) ? "devices" : "link";
|
|
195
|
+
case "full": return "full";
|
|
196
|
+
case "ended": return "ended";
|
|
197
|
+
case "quota": return "busy";
|
|
198
|
+
case "invalid": return "refused";
|
|
199
|
+
default: return /\bICE\b|block/i.test(words) ? "blocked" : /dropped/i.test(words) ? "dropped" : /joining again/i.test(words) ? "rejoining" : /microphone|camera|screen|device/i.test(words) ? "devices" : "unreachable";
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (error instanceof Error && (error.name === "NotAllowedError" || error.name === "NotFoundError" || error.name === "NotReadableError")) return "devices";
|
|
203
|
+
return "unreachable";
|
|
204
|
+
}
|
|
205
|
+
/** What a failed call says: what happened (with the room where it is the point), what to do, and whether trying again can help. */
|
|
206
|
+
function failure(error, room, wasLive) {
|
|
207
|
+
switch (whyOf(error)) {
|
|
208
|
+
case "blocked": return {
|
|
209
|
+
title: "Your network is blocking the call",
|
|
210
|
+
detail: "Try another network, such as your phone's hotspot.",
|
|
211
|
+
again: true
|
|
212
|
+
};
|
|
213
|
+
case "dropped": return {
|
|
214
|
+
title: "The call's connection dropped",
|
|
215
|
+
detail: "It couldn't come back. Check your network, then try again.",
|
|
216
|
+
again: true
|
|
217
|
+
};
|
|
218
|
+
case "removed": return {
|
|
219
|
+
title: "You were removed from the call",
|
|
220
|
+
room,
|
|
221
|
+
detail: "You can't join it again.",
|
|
222
|
+
again: false
|
|
223
|
+
};
|
|
224
|
+
case "link": return wasLive ? {
|
|
225
|
+
title: "The call's connection dropped",
|
|
226
|
+
detail: "It couldn't come back. Check your network, then try again.",
|
|
227
|
+
again: true
|
|
228
|
+
} : {
|
|
229
|
+
title: "This link doesn't work",
|
|
230
|
+
detail: "It may have run out, or it's for someone else. Ask whoever invited you for a new one.",
|
|
231
|
+
again: true
|
|
232
|
+
};
|
|
233
|
+
case "full": return {
|
|
234
|
+
title: "This call is full",
|
|
235
|
+
detail: "Try again once someone has left.",
|
|
236
|
+
again: true
|
|
237
|
+
};
|
|
238
|
+
case "ended": return {
|
|
239
|
+
title: "The call has ended",
|
|
240
|
+
room,
|
|
241
|
+
detail: "It ended before you joined.",
|
|
242
|
+
again: true
|
|
243
|
+
};
|
|
244
|
+
case "busy": return {
|
|
245
|
+
title: "This call can't start right now",
|
|
246
|
+
detail: "Try again in a little while.",
|
|
247
|
+
again: true
|
|
248
|
+
};
|
|
249
|
+
default: return {
|
|
250
|
+
title: "The call couldn't connect",
|
|
251
|
+
detail: "Check your connection and try again.",
|
|
252
|
+
again: true
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/** What a refused control says under the controls; nothing when there's nothing to tell, as when the person closed the screen picker. */
|
|
257
|
+
function refusal(what, error) {
|
|
258
|
+
const why = whyOf(error);
|
|
259
|
+
if (why === "ended" || why === "removed") return void 0;
|
|
260
|
+
if (why === "refused" && error instanceof CallError) return error.message;
|
|
261
|
+
if (why === "rejoining") return "The call is reconnecting. Try again once it's back.";
|
|
262
|
+
if (what === "screen") return why === "devices" || why === "link" ? void 0 : "The screen couldn't be shared. Try again.";
|
|
263
|
+
if (why === "devices" || why === "link") return what === "mic" ? "The microphone couldn't start. Check it's connected and allowed for this site." : what === "camera" ? "The camera couldn't start. Check it's connected and allowed for this site." : "Your microphone and camera couldn't start. Check they're connected and allowed for this site.";
|
|
264
|
+
return "That didn't go through. Try again.";
|
|
265
|
+
}
|
|
266
|
+
/** The room `<Call>` draws, for the parts that show it before the call is in. */
|
|
267
|
+
const RoomName = createContext(void 0);
|
|
191
268
|
/**
|
|
192
269
|
* A whole call: everyone's tiles, the controls, who is in it, and every state in words. Given `room` and `token` it
|
|
193
270
|
* joins, and Rejoin and Try again join anew; given a `call` it draws that one, and they do what `onRejoin` does.
|
|
@@ -208,16 +285,17 @@ function Call(props) {
|
|
|
208
285
|
};
|
|
209
286
|
const body = createElement(CallBody, {
|
|
210
287
|
room,
|
|
211
|
-
left,
|
|
212
288
|
onLeave: () => setLeft(true),
|
|
213
289
|
...again ? { onAgain: again } : {}
|
|
214
290
|
});
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
...
|
|
219
|
-
|
|
220
|
-
|
|
291
|
+
const content = left ? createElement(Ending, {
|
|
292
|
+
title: "You left the call",
|
|
293
|
+
room,
|
|
294
|
+
...again ? { action: {
|
|
295
|
+
label: "Rejoin",
|
|
296
|
+
onPress: again
|
|
297
|
+
} } : {}
|
|
298
|
+
}) : given ? createElement(CallProvider, {
|
|
221
299
|
key: attempt,
|
|
222
300
|
call: given.call
|
|
223
301
|
}, body) : createElement(CallProvider, {
|
|
@@ -226,37 +304,51 @@ function Call(props) {
|
|
|
226
304
|
token: joining.token,
|
|
227
305
|
...joining.url !== void 0 ? { url: joining.url } : {},
|
|
228
306
|
autoVideo: false
|
|
229
|
-
}, body)
|
|
307
|
+
}, body);
|
|
308
|
+
return createElement(Root, {
|
|
309
|
+
tag: "section",
|
|
310
|
+
className: cx("msc-call", className),
|
|
311
|
+
...theme ? { theme } : {},
|
|
312
|
+
attributes: { "aria-label": `Call ${room}` }
|
|
313
|
+
}, createElement(RoomName.Provider, { value: room }, content));
|
|
230
314
|
}
|
|
231
|
-
function CallBody({ room,
|
|
315
|
+
function CallBody({ room, onLeave, onAgain }) {
|
|
232
316
|
const state = useCallState();
|
|
233
317
|
const error = useCallError();
|
|
318
|
+
const local = useLocalTracks();
|
|
234
319
|
const [people, setPeople] = useState(false);
|
|
235
320
|
const peopleId = useId();
|
|
236
|
-
|
|
237
|
-
|
|
321
|
+
const wasLive = useRef(false);
|
|
322
|
+
if (live(state)) wasLive.current = true;
|
|
323
|
+
const preview = usePreview(state, local);
|
|
324
|
+
if (state === "failed") {
|
|
325
|
+
const said = failure(error, room, wasLive.current);
|
|
326
|
+
return createElement(Ending, {
|
|
327
|
+
tone: "alert",
|
|
328
|
+
title: said.title,
|
|
329
|
+
...said.room ? { room: said.room } : {},
|
|
330
|
+
...said.detail ? { detail: said.detail } : {},
|
|
331
|
+
...said.again && onAgain ? { action: {
|
|
332
|
+
label: "Try again",
|
|
333
|
+
onPress: onAgain
|
|
334
|
+
} } : {}
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
if (state === "ended") return createElement(Ending, {
|
|
338
|
+
title: "The call has ended",
|
|
339
|
+
room,
|
|
340
|
+
...onAgain ? { action: {
|
|
341
|
+
label: "Rejoin",
|
|
342
|
+
onPress: onAgain
|
|
343
|
+
} } : {}
|
|
344
|
+
});
|
|
345
|
+
return createElement(Preview.Provider, { value: preview }, createElement("div", { className: "msc-main" }, createElement("div", { className: "msc-stage" }, createElement(CallGrid), state === "connecting" && createElement("div", {
|
|
346
|
+
className: "msc-notice",
|
|
238
347
|
role: "status"
|
|
239
|
-
}, createElement("
|
|
348
|
+
}, createElement("p", { className: "msc-notice-title" }, createElement("span", {
|
|
240
349
|
className: "msc-spinner",
|
|
241
350
|
"aria-hidden": true
|
|
242
|
-
}), "Joining…"))
|
|
243
|
-
if (state === "failed") return createElement("div", {
|
|
244
|
-
className: "msc-center",
|
|
245
|
-
role: "alert"
|
|
246
|
-
}, createElement("div", { className: "msc-center-copy" }, createElement("h2", { className: "msc-title" }, "The call couldn't connect"), error && createElement("p", { className: "msc-detail" }, messageOf(error))), onAgain && createElement("button", {
|
|
247
|
-
type: "button",
|
|
248
|
-
className: "msc-button msc-primary",
|
|
249
|
-
onClick: onAgain
|
|
250
|
-
}, createElement(Icon, { name: "again" }), "Try again"));
|
|
251
|
-
if (state === "ended") return createElement("div", {
|
|
252
|
-
className: "msc-center",
|
|
253
|
-
role: "status"
|
|
254
|
-
}, createElement("div", { className: "msc-center-copy" }, createElement("h2", { className: "msc-title" }, left ? "You left the call" : "The call has ended"), createElement("p", { className: "msc-detail" }, createElement("span", { className: "msc-subject" }, room))), onAgain && createElement("button", {
|
|
255
|
-
type: "button",
|
|
256
|
-
className: "msc-button msc-primary",
|
|
257
|
-
onClick: onAgain
|
|
258
|
-
}, createElement(Icon, { name: "again" }), "Rejoin"));
|
|
259
|
-
return createElement(Fragment, null, createElement("div", { className: "msc-main" }, createElement("div", { className: "msc-stage" }, createElement(CallGrid), state === "waiting" && createElement("div", {
|
|
351
|
+
}), "Joining…"), createElement("p", { className: "msc-notice-detail" }, room)), state === "waiting" && createElement("div", {
|
|
260
352
|
className: "msc-notice",
|
|
261
353
|
role: "status"
|
|
262
354
|
}, createElement("p", { className: "msc-notice-title" }, "Waiting for others to join"), createElement("p", { className: "msc-notice-detail" }, room)), state === "reconnecting" && createElement("div", {
|
|
@@ -278,15 +370,120 @@ function CallBody({ room, left, onLeave, onAgain }) {
|
|
|
278
370
|
}
|
|
279
371
|
}));
|
|
280
372
|
}
|
|
373
|
+
/** The end of a call, or its failure, said in the middle: what happened, the room on its own line where it is the point, one line more, and the one thing to do next. */
|
|
374
|
+
function Ending({ tone = "status", title, room, detail, action }) {
|
|
375
|
+
return createElement("div", {
|
|
376
|
+
className: "msc-center",
|
|
377
|
+
role: tone
|
|
378
|
+
}, createElement("div", { className: "msc-center-copy" }, createElement("h2", { className: "msc-title" }, title), room && createElement("p", { className: "msc-detail msc-subject" }, room), detail && createElement("p", { className: "msc-detail" }, detail)), action && createElement("button", {
|
|
379
|
+
type: "button",
|
|
380
|
+
className: "msc-button msc-primary",
|
|
381
|
+
onClick: action.onPress
|
|
382
|
+
}, createElement(Icon, { name: "again" }), action.label));
|
|
383
|
+
}
|
|
384
|
+
const Preview = createContext(void 0);
|
|
385
|
+
/**
|
|
386
|
+
* Captures the microphone and camera the moment a joining call mounts, so your tile shows at once, and keeps them
|
|
387
|
+
* until the call has them. They are the page's, not the call's, so the page stops them: when the call drops one (the
|
|
388
|
+
* camera turned off), when the call ends or fails, and when the call goes.
|
|
389
|
+
*/
|
|
390
|
+
function usePreview(state, local) {
|
|
391
|
+
const [joining] = useState(state === "connecting");
|
|
392
|
+
const [now, setNow] = useState();
|
|
393
|
+
const held = useRef(void 0);
|
|
394
|
+
useEffect(() => {
|
|
395
|
+
if (!joining) return;
|
|
396
|
+
let gone = false;
|
|
397
|
+
let got;
|
|
398
|
+
const devices = globalThis.navigator?.mediaDevices;
|
|
399
|
+
const stopAll = (captured) => {
|
|
400
|
+
captured?.mic?.stop();
|
|
401
|
+
captured?.camera?.stop();
|
|
402
|
+
};
|
|
403
|
+
const capture = async () => {
|
|
404
|
+
if (!devices) return { error: new CallError("unavailable", "There's no camera or microphone to capture here.") };
|
|
405
|
+
const tracksOf = (stream) => {
|
|
406
|
+
const mic = stream.getAudioTracks()[0], camera = stream.getVideoTracks()[0];
|
|
407
|
+
return {
|
|
408
|
+
...mic ? { mic } : {},
|
|
409
|
+
...camera ? { camera } : {}
|
|
410
|
+
};
|
|
411
|
+
};
|
|
412
|
+
try {
|
|
413
|
+
return tracksOf(await devices.getUserMedia({
|
|
414
|
+
audio: true,
|
|
415
|
+
video: true
|
|
416
|
+
}));
|
|
417
|
+
} catch (both) {
|
|
418
|
+
try {
|
|
419
|
+
return tracksOf(await devices.getUserMedia({ audio: true }));
|
|
420
|
+
} catch {
|
|
421
|
+
return { error: both };
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
const ready = capture().then((captured) => {
|
|
426
|
+
if (gone) {
|
|
427
|
+
stopAll(captured);
|
|
428
|
+
return captured;
|
|
429
|
+
}
|
|
430
|
+
got = captured;
|
|
431
|
+
setNow(captured);
|
|
432
|
+
return captured;
|
|
433
|
+
});
|
|
434
|
+
held.current = {
|
|
435
|
+
ready,
|
|
436
|
+
stop: () => {
|
|
437
|
+
gone = true;
|
|
438
|
+
stopAll(got);
|
|
439
|
+
got = void 0;
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
return () => {
|
|
443
|
+
held.current?.stop();
|
|
444
|
+
setNow(void 0);
|
|
445
|
+
};
|
|
446
|
+
}, [joining]);
|
|
447
|
+
const published = useRef(/* @__PURE__ */ new Set());
|
|
448
|
+
useEffect(() => {
|
|
449
|
+
for (const one of local) published.current.add(one.track);
|
|
450
|
+
for (const track of [now?.mic, now?.camera]) if (track && published.current.has(track) && !local.some((one) => one.track === track)) track.stop();
|
|
451
|
+
}, [local, now]);
|
|
452
|
+
useEffect(() => {
|
|
453
|
+
if (state === "ended" || state === "failed") held.current?.stop();
|
|
454
|
+
}, [state]);
|
|
455
|
+
return useMemo(() => joining ? {
|
|
456
|
+
now,
|
|
457
|
+
ready: () => held.current?.ready ?? Promise.resolve({}),
|
|
458
|
+
drop: (name) => setNow((captured) => {
|
|
459
|
+
if (!captured?.[name]) return captured;
|
|
460
|
+
captured[name].stop();
|
|
461
|
+
const { [name]: _dropped, ...rest } = captured;
|
|
462
|
+
return rest;
|
|
463
|
+
})
|
|
464
|
+
} : void 0, [joining, now]);
|
|
465
|
+
}
|
|
281
466
|
/** Tiles report their rendered width, so the grid asks for each video at the layer it needs. */
|
|
282
467
|
const Widths = createContext(void 0);
|
|
283
468
|
/** The layer a tile this wide needs. */
|
|
284
469
|
const layerFor = (width) => width < 320 ? "q" : width < 720 ? "h" : "f";
|
|
470
|
+
/** You, before the join has said who you are in the room. */
|
|
471
|
+
const NOBODY = {
|
|
472
|
+
id: "self",
|
|
473
|
+
as: "",
|
|
474
|
+
name: "",
|
|
475
|
+
kind: "person",
|
|
476
|
+
state: "joined",
|
|
477
|
+
joinedAt: 0,
|
|
478
|
+
tracks: [],
|
|
479
|
+
received: {}
|
|
480
|
+
};
|
|
285
481
|
/**
|
|
286
|
-
* Everyone in the call as tiles
|
|
287
|
-
* and everyone's sound.
|
|
288
|
-
* At most
|
|
289
|
-
* their
|
|
482
|
+
* Everyone in the call as tiles: you first (from the moment the call starts joining), then the others, those with a
|
|
483
|
+
* camera first; and everyone's sound. While a screen is shared it takes the stage and the people sit in a strip beside
|
|
484
|
+
* it. At most 16 people have a tile of their own, and a last tile shows how many more are in the call. At most 9
|
|
485
|
+
* others' videos are received, each at the layer its tile's width needs and at most 2 at `f`; the rest show their
|
|
486
|
+
* initials.
|
|
290
487
|
*/
|
|
291
488
|
function CallGrid({ className }) {
|
|
292
489
|
const call = useCall();
|
|
@@ -295,10 +492,11 @@ function CallGrid({ className }) {
|
|
|
295
492
|
const local = useLocalTracks();
|
|
296
493
|
const present = participants.filter((participant) => participant.state !== "left");
|
|
297
494
|
const sharing = local.some((track) => track.name === "screen");
|
|
298
|
-
const
|
|
495
|
+
const me = call?.me ?? NOBODY;
|
|
496
|
+
const tiles = [
|
|
299
497
|
...sharing ? [{
|
|
300
498
|
key: "self/screen",
|
|
301
|
-
participant:
|
|
499
|
+
participant: me,
|
|
302
500
|
video: "screen",
|
|
303
501
|
self: true
|
|
304
502
|
}] : [],
|
|
@@ -310,7 +508,7 @@ function CallGrid({ className }) {
|
|
|
310
508
|
})),
|
|
311
509
|
{
|
|
312
510
|
key: "self/camera",
|
|
313
|
-
participant:
|
|
511
|
+
participant: me,
|
|
314
512
|
video: "camera",
|
|
315
513
|
self: true
|
|
316
514
|
},
|
|
@@ -320,7 +518,7 @@ function CallGrid({ className }) {
|
|
|
320
518
|
video: "camera",
|
|
321
519
|
self: false
|
|
322
520
|
}))
|
|
323
|
-
]
|
|
521
|
+
];
|
|
324
522
|
const people = tiles.filter((tile) => tile.video === "camera").length;
|
|
325
523
|
const more = people > MAX_TILES ? people - (MAX_TILES - 1) : 0;
|
|
326
524
|
const shown = more ? tiles.filter((tile) => tile.video === "screen" || tiles.filter((one) => one.video === "camera").indexOf(tile) < MAX_TILES - 1) : tiles;
|
|
@@ -386,11 +584,12 @@ function CallGrid({ className }) {
|
|
|
386
584
|
state,
|
|
387
585
|
planned
|
|
388
586
|
]);
|
|
389
|
-
const
|
|
390
|
-
const
|
|
391
|
-
const
|
|
392
|
-
const
|
|
393
|
-
const
|
|
587
|
+
const screens = shown.filter((tile) => tile.video === "screen");
|
|
588
|
+
const cameras = shown.filter((tile) => tile.video === "camera");
|
|
589
|
+
const count = cameras.length + (more ? 1 : 0);
|
|
590
|
+
const most = count <= 1 ? 1 : count <= 4 ? 2 : count <= 9 ? 3 : 4;
|
|
591
|
+
const columns = stage === void 0 ? most : stage < 300 ? 1 : stage <= 560 ? Math.min(most, 2) : stage <= 720 ? Math.min(most, 3) : most;
|
|
592
|
+
const rows = Math.ceil(count / columns);
|
|
394
593
|
const sounds = present.flatMap((participant) => ["mic", "screen-audio"].flatMap((name) => {
|
|
395
594
|
const track = participant.received[name];
|
|
396
595
|
return track ? [createElement(Audio, {
|
|
@@ -398,22 +597,32 @@ function CallGrid({ className }) {
|
|
|
398
597
|
track
|
|
399
598
|
})] : [];
|
|
400
599
|
}));
|
|
600
|
+
const tile = (one) => createElement(CallTile, {
|
|
601
|
+
key: one.key,
|
|
602
|
+
participant: one.participant,
|
|
603
|
+
video: one.video,
|
|
604
|
+
self: one.self
|
|
605
|
+
});
|
|
606
|
+
const rest = more > 0 && createElement("div", {
|
|
607
|
+
key: "more",
|
|
608
|
+
className: "msc-tile msc-more"
|
|
609
|
+
}, `+${more} more`);
|
|
401
610
|
return createElement(Widths.Provider, { value: report }, createElement(Root, {
|
|
402
611
|
className: cx("msc-grid", className),
|
|
403
612
|
elementRef: grid,
|
|
404
613
|
attributes: {
|
|
405
614
|
"data-cols": String(columns),
|
|
615
|
+
...screens.length ? { "data-screens": "" } : {},
|
|
406
616
|
style: { "--_rows": String(rows) }
|
|
407
617
|
}
|
|
408
|
-
}, ...
|
|
409
|
-
key:
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
}, `+${more} more`), ...sounds));
|
|
618
|
+
}, ...screens.length ? [createElement("div", {
|
|
619
|
+
key: "screens",
|
|
620
|
+
className: "msc-screens"
|
|
621
|
+
}, ...screens.map(tile)), createElement("div", {
|
|
622
|
+
key: "strip",
|
|
623
|
+
className: "msc-strip",
|
|
624
|
+
"data-scroll": ""
|
|
625
|
+
}, ...cameras.map(tile), rest)] : [...cameras.map(tile), rest], ...sounds));
|
|
417
626
|
}
|
|
418
627
|
const VIDEOS = ["camera", "screen"];
|
|
419
628
|
/** The most people the grid gives a tile of their own, the last place being the count of the rest past it. */
|
|
@@ -422,9 +631,10 @@ const publishes = (participant, name) => participant.tracks.some((track) => trac
|
|
|
422
631
|
/** One person's tile: their video once it is received, else their initials; their name, a muted microphone, and a ring while they speak. */
|
|
423
632
|
function CallTile({ participant, video = "camera", self = false, className }) {
|
|
424
633
|
const local = useLocalTracks();
|
|
634
|
+
const preview = useContext(Preview)?.now;
|
|
425
635
|
const mine = (name) => local.find((track) => track.name === name && !track.muted)?.track;
|
|
426
|
-
const track = self ? mine(video) : participant.received[video];
|
|
427
|
-
const mic = self ? mine("mic") : participant.received.mic;
|
|
636
|
+
const track = self ? mine(video) ?? (video === "camera" && !local.length ? preview?.camera : void 0) : participant.received[video];
|
|
637
|
+
const mic = self ? mine("mic") ?? (!local.length ? preview?.mic : void 0) : participant.received.mic;
|
|
428
638
|
const silent = useMicOff(participant, self);
|
|
429
639
|
const speaking = useSpeaking(video === "camera" && !silent ? mic : void 0);
|
|
430
640
|
const away = participant.state === "away";
|
|
@@ -469,46 +679,85 @@ function CallTile({ participant, video = "camera", self = false, className }) {
|
|
|
469
679
|
"data-truncated-text": ""
|
|
470
680
|
}, name)), away && createElement("span", { className: "msc-away" }, "Away")));
|
|
471
681
|
}
|
|
472
|
-
/**
|
|
682
|
+
/**
|
|
683
|
+
* The call's controls: the room's name, microphone, camera, screen sharing and Leave, and the participant list's
|
|
684
|
+
* button. Each shows what was asked the moment it is pressed, and goes back with a line under it when the call refuses.
|
|
685
|
+
*/
|
|
473
686
|
function CallControls({ publish = false, onLeave, people, className }) {
|
|
474
687
|
const call = useCall();
|
|
475
688
|
const state = useCallState();
|
|
476
689
|
const local = useLocalTracks();
|
|
477
690
|
const participants = useParticipants();
|
|
478
|
-
const
|
|
691
|
+
const preview = useContext(Preview);
|
|
692
|
+
const room = useContext(RoomName) ?? call?.room ?? "";
|
|
693
|
+
const [starting, setStarting] = useState(false);
|
|
479
694
|
const [problem, setProblem] = useState();
|
|
480
|
-
const
|
|
481
|
-
const
|
|
695
|
+
const [meant, setMeant] = useState(() => /* @__PURE__ */ new Map());
|
|
696
|
+
const chains = useRef(/* @__PURE__ */ new Map());
|
|
697
|
+
const intend = useCallback((what, on, act) => {
|
|
482
698
|
setProblem(void 0);
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
699
|
+
setMeant((before) => new Map(before).set(what, on));
|
|
700
|
+
const settle = (kept) => setMeant((before) => {
|
|
701
|
+
if (kept && before.get(what) !== on) return before;
|
|
702
|
+
const next = new Map(before);
|
|
486
703
|
next.delete(what);
|
|
487
704
|
return next;
|
|
488
|
-
})
|
|
705
|
+
});
|
|
706
|
+
const done = (chains.current.get(what) ?? Promise.resolve()).then(act).then(() => settle(true), (error) => {
|
|
707
|
+
settle(false);
|
|
708
|
+
const words = refusal(what, error);
|
|
709
|
+
if (words) setProblem(words);
|
|
710
|
+
});
|
|
711
|
+
chains.current.set(what, done);
|
|
489
712
|
}, []);
|
|
490
713
|
const started = useRef(false);
|
|
491
714
|
useEffect(() => {
|
|
492
715
|
if (!publish || started.current || !call || !live(state)) return;
|
|
493
716
|
started.current = true;
|
|
494
|
-
|
|
717
|
+
setStarting(true);
|
|
718
|
+
const both = () => call.publish({
|
|
495
719
|
mic: true,
|
|
496
720
|
camera: true
|
|
497
|
-
}).catch((
|
|
498
|
-
throw
|
|
499
|
-
}))
|
|
721
|
+
}).catch((error) => call.publish({ mic: true }).catch(() => {
|
|
722
|
+
throw error;
|
|
723
|
+
}));
|
|
724
|
+
const start = async () => {
|
|
725
|
+
const captured = preview ? await preview.ready() : {};
|
|
726
|
+
if (captured.error) throw captured.error;
|
|
727
|
+
if (!captured.mic && !captured.camera) return both();
|
|
728
|
+
try {
|
|
729
|
+
await call.publish({
|
|
730
|
+
...captured.mic ? { mic: captured.mic } : {},
|
|
731
|
+
...captured.camera ? { camera: captured.camera } : {}
|
|
732
|
+
});
|
|
733
|
+
} catch (error) {
|
|
734
|
+
if (!captured.mic || !captured.camera) throw error;
|
|
735
|
+
preview?.drop("camera");
|
|
736
|
+
await call.publish({ mic: captured.mic }).catch(() => {
|
|
737
|
+
throw error;
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
start().catch((error) => {
|
|
742
|
+
const words = refusal("start", error);
|
|
743
|
+
if (words) setProblem(words);
|
|
744
|
+
}).finally(() => setStarting(false));
|
|
500
745
|
}, [
|
|
501
746
|
publish,
|
|
502
747
|
call,
|
|
503
748
|
state,
|
|
504
|
-
|
|
749
|
+
preview
|
|
505
750
|
]);
|
|
506
751
|
const track = (name) => local.find((one) => one.name === name);
|
|
507
752
|
const mic = track("mic"), camera = track("camera"), screen = track("screen");
|
|
508
|
-
const
|
|
509
|
-
const
|
|
510
|
-
const
|
|
511
|
-
const
|
|
753
|
+
const captured = !local.length ? preview?.now : void 0;
|
|
754
|
+
const micOn = meant.get("mic") ?? Boolean(captured ? captured.mic : mic && !mic.muted);
|
|
755
|
+
const cameraOn = meant.get("camera") ?? Boolean(captured ? captured.camera : camera && !camera.muted);
|
|
756
|
+
const sharing = meant.get("screen") ?? Boolean(screen);
|
|
757
|
+
const voiceOnly = Boolean(call?.audioOnly);
|
|
758
|
+
const canShare = !voiceOnly && typeof navigator !== "undefined" && typeof navigator.mediaDevices?.getDisplayMedia === "function";
|
|
759
|
+
const usable = Boolean(call) && takes(state) && !starting;
|
|
760
|
+
const count = participants.filter((participant) => participant.state !== "left").length + 1;
|
|
512
761
|
const toggle = (what, label, on, icons, act) => tipped(label, createElement("button", {
|
|
513
762
|
type: "button",
|
|
514
763
|
className: "msc-control",
|
|
@@ -516,11 +765,9 @@ function CallControls({ publish = false, onLeave, people, className }) {
|
|
|
516
765
|
...on ? {} : { "data-off": "" },
|
|
517
766
|
"aria-label": label,
|
|
518
767
|
"aria-pressed": on,
|
|
519
|
-
"aria-busy":
|
|
520
|
-
disabled: !
|
|
521
|
-
onClick: () =>
|
|
522
|
-
if (call) run(what, act);
|
|
523
|
-
}
|
|
768
|
+
"aria-busy": meant.has(what) || starting,
|
|
769
|
+
disabled: !usable,
|
|
770
|
+
onClick: () => intend(what, !on, () => act(!on))
|
|
524
771
|
}, createElement(Icon, { name: on ? icons[0] : icons[1] })));
|
|
525
772
|
return createElement(Root, { className: cx("msc-bar", className) }, problem && createElement("div", {
|
|
526
773
|
className: "msc-alert",
|
|
@@ -530,28 +777,38 @@ function CallControls({ publish = false, onLeave, people, className }) {
|
|
|
530
777
|
className: "msc-quiet",
|
|
531
778
|
"aria-label": "Dismiss",
|
|
532
779
|
onClick: () => setProblem(void 0)
|
|
533
|
-
}, createElement(Icon, { name: "close" }))), createElement("span", { className: "msc-room" },
|
|
780
|
+
}, createElement(Icon, { name: "close" }))), createElement("span", { className: "msc-room" }, room), createElement("div", {
|
|
534
781
|
className: "msc-controls",
|
|
535
782
|
role: "group",
|
|
536
783
|
"aria-label": "Call controls"
|
|
537
|
-
},
|
|
784
|
+
}, toggle("mic", "Microphone", micOn, ["mic", "micOff"], (on) => {
|
|
785
|
+
const now = call?.local.find((one) => one.name === "mic");
|
|
786
|
+
return !call ? Promise.resolve() : on ? now ? call.unmute("mic") : call.publish({ mic: true }) : now ? call.mute("mic") : Promise.resolve();
|
|
787
|
+
}), !voiceOnly && toggle("camera", "Camera", cameraOn, ["camera", "cameraOff"], (on) => {
|
|
788
|
+
const now = call?.local.find((one) => one.name === "camera");
|
|
789
|
+
return !call ? Promise.resolve() : on ? now ? call.unmute("camera") : call.publish({ camera: true }) : now ? call.unpublish("camera") : Promise.resolve();
|
|
790
|
+
}), canShare && tipped(sharing ? "Stop sharing" : "Share screen", createElement("button", {
|
|
538
791
|
type: "button",
|
|
539
792
|
className: "msc-control",
|
|
540
793
|
"data-icon-only": "",
|
|
794
|
+
...sharing ? { "data-on": "" } : {},
|
|
541
795
|
"aria-label": "Share screen",
|
|
542
|
-
"aria-pressed":
|
|
543
|
-
"aria-busy":
|
|
544
|
-
disabled: !
|
|
545
|
-
onClick: () =>
|
|
796
|
+
"aria-pressed": sharing,
|
|
797
|
+
"aria-busy": meant.has("screen"),
|
|
798
|
+
disabled: !usable,
|
|
799
|
+
onClick: () => {
|
|
800
|
+
const on = !sharing;
|
|
801
|
+
intend("screen", on, () => !call ? Promise.resolve() : on ? call.screen.share() : call.screen.stop());
|
|
802
|
+
}
|
|
546
803
|
}, createElement(Icon, { name: "screen" }))), tipped("Leave", createElement("button", {
|
|
547
804
|
type: "button",
|
|
548
805
|
className: "msc-control msc-leave",
|
|
549
806
|
"data-icon-only": "",
|
|
550
807
|
"aria-label": "Leave",
|
|
551
|
-
disabled:
|
|
808
|
+
disabled: state === "ended" || state === "failed",
|
|
552
809
|
onClick: () => {
|
|
553
810
|
onLeave?.();
|
|
554
|
-
call?.leave();
|
|
811
|
+
call?.leave().catch(noop);
|
|
555
812
|
}
|
|
556
813
|
}, createElement(Icon, { name: "leave" })))), createElement("div", { className: "msc-bar-end" }, people && createElement("button", {
|
|
557
814
|
type: "button",
|
|
@@ -581,7 +838,7 @@ function ParticipantList({ id, onClose, className }) {
|
|
|
581
838
|
const call = useCall();
|
|
582
839
|
const participants = useParticipants();
|
|
583
840
|
const titleId = useId();
|
|
584
|
-
const everyone = call
|
|
841
|
+
const everyone = [call?.me ?? NOBODY, ...participants.filter((participant) => participant.state !== "left")];
|
|
585
842
|
return createElement(Root, {
|
|
586
843
|
tag: "section",
|
|
587
844
|
className: cx("msc-people", className),
|
|
@@ -609,19 +866,19 @@ function Person({ participant, self }) {
|
|
|
609
866
|
return createElement("li", {
|
|
610
867
|
className: "msc-person",
|
|
611
868
|
...away ? { "data-away": "" } : {}
|
|
612
|
-
}, createElement(Initials, { name: participant.name }), createElement("span", { className: "msc-person-copy" }, createElement("span", { className: "msc-person-name" }, participant.name), (self || away) && createElement("span", { className: "msc-person-detail" }, self ? "You" : "Away")), off && createElement(Icon, {
|
|
869
|
+
}, createElement(Initials, { name: participant.name }), createElement("span", { className: "msc-person-copy" }, createElement("span", { className: "msc-person-name" }, self && !participant.name ? "You" : participant.name), (self && participant.name || away) && createElement("span", { className: "msc-person-detail" }, self ? "You" : "Away")), off && createElement(Icon, {
|
|
613
870
|
name: "micOff",
|
|
614
871
|
label: "Microphone off",
|
|
615
872
|
danger: true
|
|
616
873
|
}));
|
|
617
874
|
}
|
|
618
|
-
/** Someone's first letters in a circle, for a tile without video and the participant list. */
|
|
875
|
+
/** Someone's first letters in a circle, for a tile without video and the participant list; a figure while the name isn't known. */
|
|
619
876
|
function Initials({ name }) {
|
|
620
877
|
const letters = name.trim().split(/\s+/u).slice(0, 2).map((word) => [...word][0] ?? "").join("").toUpperCase();
|
|
621
878
|
return createElement("span", {
|
|
622
879
|
className: "msc-avatar",
|
|
623
880
|
"aria-hidden": true
|
|
624
|
-
}, letters || "
|
|
881
|
+
}, letters || createElement(Icon, { name: "person" }));
|
|
625
882
|
}
|
|
626
883
|
/**
|
|
627
884
|
* Whether someone's microphone sends nothing: yours when it is muted or off; another's when they publish none, or
|
|
@@ -629,8 +886,10 @@ function Initials({ name }) {
|
|
|
629
886
|
*/
|
|
630
887
|
function useMicOff(participant, self) {
|
|
631
888
|
const local = useLocalTracks();
|
|
889
|
+
const preview = useContext(Preview)?.now;
|
|
632
890
|
const quiet = useTrackMuted(self ? void 0 : participant.received.mic);
|
|
633
891
|
if (self) {
|
|
892
|
+
if (!local.length && preview) return !preview.mic;
|
|
634
893
|
const mic = local.find((track) => track.name === "mic");
|
|
635
894
|
return !mic || mic.muted;
|
|
636
895
|
}
|
|
@@ -750,6 +1009,7 @@ const ICONS = {
|
|
|
750
1009
|
"M15.5 4.4a3.5 3.5 0 0 1 0 6.7",
|
|
751
1010
|
"M17.75 14.5c2 .6 3.2 2.3 3.5 4.75"
|
|
752
1011
|
],
|
|
1012
|
+
person: ["M12 11.25a3.5 3.5 0 1 0 0-7a3.5 3.5 0 0 0 0 7Z", "M5.25 19.25c.7-3.3 3.3-5 6.75-5s6.05 1.7 6.75 5"],
|
|
753
1013
|
close: ["M6.75 6.75l10.5 10.5", "M17.25 6.75l-10.5 10.5"],
|
|
754
1014
|
again: ["M19.25 12a7.25 7.25 0 1 1-2.12-5.13", "M19.25 4.75v4h-4"],
|
|
755
1015
|
warning: [
|
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.4498";
|
|
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.4498",
|
|
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.",
|