@ai-matrx/meet 0.11.36 → 0.11.38

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.
@@ -138,6 +138,19 @@ function normalizeDeviceError(error, operation) {
138
138
  }
139
139
  }
140
140
 
141
+ // src/core/leave.ts
142
+ var DEFAULT_LEAVE_POLICY = { hostLeavePrompt: "leave_or_end", endConfirm: false };
143
+ function leaveChoices(args) {
144
+ if (args.role !== "host") return ["leave"];
145
+ switch (args.policy.hostLeavePrompt) {
146
+ case "must_assign_or_end":
147
+ return args.othersPresent ? ["assign_and_leave", "end_for_all"] : ["leave", "end_for_all"];
148
+ case "leave_only":
149
+ case "leave_or_end":
150
+ return ["leave", "end_for_all"];
151
+ }
152
+ }
153
+
141
154
  // src/core/tokens.ts
142
155
  var MEET_ROUTES = {
143
156
  token: "/api/v1/meet/token",
@@ -202,6 +215,12 @@ var MEET_ROUTES = {
202
215
  state: "/api/v1/meet/state",
203
216
  /** S4: `withdraw` (stop waiting) or `leave` (close this tab); the pass may ride in the body. */
204
217
  leave: "/api/v1/meet/leave",
218
+ /**
219
+ * S8: a host's browser just called an admission DOOR (`meet_admit` · `meet_deny` ·
220
+ * `meet_undeny` · `meet_admit_all`). Payload-free: the server republishes the room's
221
+ * replicated state (the People badge's waiting count) from the database truth.
222
+ */
223
+ admissionChanged: "/api/v1/meet/admission/changed",
205
224
  /** S4: a pass holder (guests included) saw the recording notice, for this run. */
206
225
  consent: "/api/v1/meet/consent"
207
226
  };
@@ -1127,16 +1146,16 @@ function useRoom() {
1127
1146
  async () => requireEngine(engine, "toggleCamera").setCameraEnabled(!(local?.cameraEnabled ?? false)),
1128
1147
  [engine, local]
1129
1148
  ),
1130
- toggleScreenShare: useCallback2(
1131
- async () => requireEngine(engine, "toggleScreenShare").setScreenShareEnabled(
1132
- !(local?.screenSharing ?? false)
1133
- ),
1134
- [engine, local]
1135
- ),
1136
- toggleHand: useCallback2(
1137
- async () => requireEngine(engine, "toggleHand").raiseHand(!(local?.handRaised ?? false)),
1138
- [engine, local]
1139
- ),
1149
+ toggleScreenShare: useCallback2(async () => {
1150
+ const on = !(local?.screenSharing ?? false);
1151
+ await requireEngine(engine, "toggleScreenShare").setScreenShareEnabled(on);
1152
+ }, [engine, local]),
1153
+ // S8: a hand is SERVER state (`/moderate raise_hand · lower_hand`, server time), replicated
1154
+ // back as the `matrx.hand` attribute — no client sets its own hand on the wire.
1155
+ toggleHand: useCallback2(async () => {
1156
+ if (host === null) throw noRuntime("toggleHand");
1157
+ await host.inRoom.moderate({ action: local?.handRaised === true ? "lower_hand" : "raise_hand" });
1158
+ }, [host, local]),
1140
1159
  react: useCallback2(
1141
1160
  async (emoji) => requireEngine(engine, "react").react(emoji),
1142
1161
  [engine]
@@ -1265,6 +1284,31 @@ function useWaiting() {
1265
1284
  askAgain: useCallback2(async () => requireSession(session, "askAgain").askAgain(), [session])
1266
1285
  };
1267
1286
  }
1287
+ function useLeave() {
1288
+ const host = useMeetHost();
1289
+ const snapshot = useMeetSnapshot();
1290
+ const session = host?.meetings ?? null;
1291
+ const engine = host?.engine ?? null;
1292
+ const policy = snapshot?.leavePolicy ?? DEFAULT_LEAVE_POLICY;
1293
+ const participants = snapshot?.participants ?? [];
1294
+ const me = participants.find((p) => p.isLocal);
1295
+ const candidates = participants.filter((p) => !p.isLocal && !p.isAgent && p.role !== "viewer");
1296
+ const choices = leaveChoices({ policy, role: me?.role ?? null, othersPresent: candidates.length > 0 });
1297
+ return {
1298
+ choices,
1299
+ policy,
1300
+ candidates,
1301
+ leave: useCallback2(async () => requireEngine(engine, "leave").leave(), [engine]),
1302
+ endForAll: useCallback2(async () => requireSession(session, "endForAll").hostLeave("end_for_all"), [session]),
1303
+ assignAndLeave: useCallback2(
1304
+ async (person) => {
1305
+ await requireSession(session, "assignAndLeave").hostLeave({ assignTo: String(person.identity) });
1306
+ await requireEngine(engine, "leave").leave();
1307
+ },
1308
+ [session, engine]
1309
+ )
1310
+ };
1311
+ }
1268
1312
  function useRecording() {
1269
1313
  const host = useMeetHost();
1270
1314
  const snapshot = useMeetSnapshot();
@@ -3429,19 +3473,75 @@ function ControlBar({ onLeave }) {
3429
3473
  ] }) : null
3430
3474
  ] }) }) : null
3431
3475
  ] }),
3432
- /* @__PURE__ */ jsx6(
3433
- ControlButton,
3476
+ /* @__PURE__ */ jsx6(LeaveControl, { onLeave })
3477
+ ] })
3478
+ ] });
3479
+ }
3480
+ var LEAVE_WORDS = {
3481
+ leave_or_end: { leave: "Leave call", assign_and_leave: "Assign a new host", end_for_all: "End call for everyone" },
3482
+ must_assign_or_end: { leave: "Leave meeting", assign_and_leave: "Assign a new host", end_for_all: "End meeting for all" },
3483
+ leave_only: { leave: "Leave", assign_and_leave: "Assign a new host", end_for_all: "End meeting" }
3484
+ };
3485
+ function LeaveControl({ onLeave }) {
3486
+ const leave = useLeave();
3487
+ const [open, setOpen] = useState4("none");
3488
+ const [failure, setFailure] = useState4(null);
3489
+ const words = LEAVE_WORDS[leave.policy.hostLeavePrompt];
3490
+ const run = (work, leaving) => {
3491
+ setFailure(null);
3492
+ void work().then(() => {
3493
+ setOpen("none");
3494
+ if (leaving) onLeave?.();
3495
+ }).catch((error) => setFailure(error instanceof Error ? error.message : String(error)));
3496
+ };
3497
+ const leaveNow = () => run(leave.leave, true);
3498
+ const endNow = () => run(leave.endForAll, false);
3499
+ return /* @__PURE__ */ jsxs3("span", { className: "mx-meet__anchor", children: [
3500
+ /* @__PURE__ */ jsx6(
3501
+ ControlButton,
3502
+ {
3503
+ label: "Leave",
3504
+ danger: true,
3505
+ active: open !== "none",
3506
+ onClick: () => {
3507
+ if (leave.choices.length === 1 && leave.choices[0] === "leave") leaveNow();
3508
+ else setOpen(open === "none" ? "menu" : "none");
3509
+ },
3510
+ children: /* @__PURE__ */ jsx6(PhoneOffIcon, {})
3511
+ }
3512
+ ),
3513
+ open !== "none" ? /* @__PURE__ */ jsx6(Popover, { label: open === "assign" ? words.assign_and_leave : "Leave", onClose: () => setOpen("none"), children: /* @__PURE__ */ jsxs3("div", { className: "mx-meet__menu", "data-meet-leave-menu": leave.policy.hostLeavePrompt, children: [
3514
+ open === "menu" ? leave.choices.map((choice) => /* @__PURE__ */ jsx6(
3515
+ "button",
3434
3516
  {
3435
- label: "Leave",
3436
- danger: true,
3517
+ type: "button",
3518
+ className: choice === "end_for_all" ? "mx-meet__menu-item mx-meet__menu-item--danger" : "mx-meet__menu-item",
3437
3519
  onClick: () => {
3438
- void room.leave();
3439
- onLeave?.();
3520
+ if (choice === "leave") leaveNow();
3521
+ else if (choice === "assign_and_leave") setOpen("assign");
3522
+ else if (leave.policy.endConfirm) setOpen("confirm");
3523
+ else endNow();
3440
3524
  },
3441
- children: /* @__PURE__ */ jsx6(PhoneOffIcon, {})
3442
- }
3443
- )
3444
- ] })
3525
+ children: words[choice]
3526
+ },
3527
+ choice
3528
+ )) : null,
3529
+ open === "assign" ? leave.candidates.map((person) => /* @__PURE__ */ jsx6(
3530
+ "button",
3531
+ {
3532
+ type: "button",
3533
+ className: "mx-meet__menu-item",
3534
+ onClick: () => run(() => leave.assignAndLeave(person), true),
3535
+ children: person.displayName
3536
+ },
3537
+ String(person.identity)
3538
+ )) : null,
3539
+ open === "confirm" ? /* @__PURE__ */ jsxs3(Fragment, { children: [
3540
+ /* @__PURE__ */ jsx6("button", { type: "button", className: "mx-meet__menu-item mx-meet__menu-item--danger", onClick: endNow, children: words.end_for_all }),
3541
+ /* @__PURE__ */ jsx6("button", { type: "button", className: "mx-meet__menu-item", onClick: () => setOpen("menu"), children: "Cancel" })
3542
+ ] }) : null,
3543
+ failure !== null ? /* @__PURE__ */ jsx6("p", { className: "mx-meet__menu-note", role: "alert", children: failure }) : null
3544
+ ] }) }) : null
3445
3545
  ] });
3446
3546
  }
3447
3547
  function useUnreadChat(open) {