@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.
@@ -243,6 +243,19 @@ function normalizeDeviceError(error, operation) {
243
243
  }
244
244
  }
245
245
 
246
+ // src/core/leave.ts
247
+ var DEFAULT_LEAVE_POLICY = { hostLeavePrompt: "leave_or_end", endConfirm: false };
248
+ function leaveChoices(args) {
249
+ if (args.role !== "host") return ["leave"];
250
+ switch (args.policy.hostLeavePrompt) {
251
+ case "must_assign_or_end":
252
+ return args.othersPresent ? ["assign_and_leave", "end_for_all"] : ["leave", "end_for_all"];
253
+ case "leave_only":
254
+ case "leave_or_end":
255
+ return ["leave", "end_for_all"];
256
+ }
257
+ }
258
+
246
259
  // src/core/tokens.ts
247
260
  var MEET_ROUTES = {
248
261
  token: "/api/v1/meet/token",
@@ -307,6 +320,12 @@ var MEET_ROUTES = {
307
320
  state: "/api/v1/meet/state",
308
321
  /** S4: `withdraw` (stop waiting) or `leave` (close this tab); the pass may ride in the body. */
309
322
  leave: "/api/v1/meet/leave",
323
+ /**
324
+ * S8: a host's browser just called an admission DOOR (`meet_admit` · `meet_deny` ·
325
+ * `meet_undeny` · `meet_admit_all`). Payload-free: the server republishes the room's
326
+ * replicated state (the People badge's waiting count) from the database truth.
327
+ */
328
+ admissionChanged: "/api/v1/meet/admission/changed",
310
329
  /** S4: a pass holder (guests included) saw the recording notice, for this run. */
311
330
  consent: "/api/v1/meet/consent"
312
331
  };
@@ -1219,16 +1238,16 @@ function useRoom() {
1219
1238
  async () => requireEngine(engine, "toggleCamera").setCameraEnabled(!(local?.cameraEnabled ?? false)),
1220
1239
  [engine, local]
1221
1240
  ),
1222
- toggleScreenShare: (0, import_react5.useCallback)(
1223
- async () => requireEngine(engine, "toggleScreenShare").setScreenShareEnabled(
1224
- !(local?.screenSharing ?? false)
1225
- ),
1226
- [engine, local]
1227
- ),
1228
- toggleHand: (0, import_react5.useCallback)(
1229
- async () => requireEngine(engine, "toggleHand").raiseHand(!(local?.handRaised ?? false)),
1230
- [engine, local]
1231
- ),
1241
+ toggleScreenShare: (0, import_react5.useCallback)(async () => {
1242
+ const on = !(local?.screenSharing ?? false);
1243
+ await requireEngine(engine, "toggleScreenShare").setScreenShareEnabled(on);
1244
+ }, [engine, local]),
1245
+ // S8: a hand is SERVER state (`/moderate raise_hand · lower_hand`, server time), replicated
1246
+ // back as the `matrx.hand` attribute — no client sets its own hand on the wire.
1247
+ toggleHand: (0, import_react5.useCallback)(async () => {
1248
+ if (host === null) throw noRuntime("toggleHand");
1249
+ await host.inRoom.moderate({ action: local?.handRaised === true ? "lower_hand" : "raise_hand" });
1250
+ }, [host, local]),
1232
1251
  react: (0, import_react5.useCallback)(
1233
1252
  async (emoji) => requireEngine(engine, "react").react(emoji),
1234
1253
  [engine]
@@ -1357,6 +1376,31 @@ function useWaiting() {
1357
1376
  askAgain: (0, import_react5.useCallback)(async () => requireSession(session, "askAgain").askAgain(), [session])
1358
1377
  };
1359
1378
  }
1379
+ function useLeave() {
1380
+ const host = useMeetHost();
1381
+ const snapshot = useMeetSnapshot();
1382
+ const session = host?.meetings ?? null;
1383
+ const engine = host?.engine ?? null;
1384
+ const policy = snapshot?.leavePolicy ?? DEFAULT_LEAVE_POLICY;
1385
+ const participants = snapshot?.participants ?? [];
1386
+ const me = participants.find((p) => p.isLocal);
1387
+ const candidates = participants.filter((p) => !p.isLocal && !p.isAgent && p.role !== "viewer");
1388
+ const choices = leaveChoices({ policy, role: me?.role ?? null, othersPresent: candidates.length > 0 });
1389
+ return {
1390
+ choices,
1391
+ policy,
1392
+ candidates,
1393
+ leave: (0, import_react5.useCallback)(async () => requireEngine(engine, "leave").leave(), [engine]),
1394
+ endForAll: (0, import_react5.useCallback)(async () => requireSession(session, "endForAll").hostLeave("end_for_all"), [session]),
1395
+ assignAndLeave: (0, import_react5.useCallback)(
1396
+ async (person) => {
1397
+ await requireSession(session, "assignAndLeave").hostLeave({ assignTo: String(person.identity) });
1398
+ await requireEngine(engine, "leave").leave();
1399
+ },
1400
+ [session, engine]
1401
+ )
1402
+ };
1403
+ }
1360
1404
  function useRecording() {
1361
1405
  const host = useMeetHost();
1362
1406
  const snapshot = useMeetSnapshot();
@@ -3521,19 +3565,75 @@ function ControlBar({ onLeave }) {
3521
3565
  ] }) : null
3522
3566
  ] }) }) : null
3523
3567
  ] }),
3524
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3525
- ControlButton,
3568
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(LeaveControl, { onLeave })
3569
+ ] })
3570
+ ] });
3571
+ }
3572
+ var LEAVE_WORDS = {
3573
+ leave_or_end: { leave: "Leave call", assign_and_leave: "Assign a new host", end_for_all: "End call for everyone" },
3574
+ must_assign_or_end: { leave: "Leave meeting", assign_and_leave: "Assign a new host", end_for_all: "End meeting for all" },
3575
+ leave_only: { leave: "Leave", assign_and_leave: "Assign a new host", end_for_all: "End meeting" }
3576
+ };
3577
+ function LeaveControl({ onLeave }) {
3578
+ const leave = useLeave();
3579
+ const [open, setOpen] = (0, import_react10.useState)("none");
3580
+ const [failure, setFailure] = (0, import_react10.useState)(null);
3581
+ const words = LEAVE_WORDS[leave.policy.hostLeavePrompt];
3582
+ const run = (work, leaving) => {
3583
+ setFailure(null);
3584
+ void work().then(() => {
3585
+ setOpen("none");
3586
+ if (leaving) onLeave?.();
3587
+ }).catch((error) => setFailure(error instanceof Error ? error.message : String(error)));
3588
+ };
3589
+ const leaveNow = () => run(leave.leave, true);
3590
+ const endNow = () => run(leave.endForAll, false);
3591
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "mx-meet__anchor", children: [
3592
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3593
+ ControlButton,
3594
+ {
3595
+ label: "Leave",
3596
+ danger: true,
3597
+ active: open !== "none",
3598
+ onClick: () => {
3599
+ if (leave.choices.length === 1 && leave.choices[0] === "leave") leaveNow();
3600
+ else setOpen(open === "none" ? "menu" : "none");
3601
+ },
3602
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PhoneOffIcon, {})
3603
+ }
3604
+ ),
3605
+ open !== "none" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Popover, { label: open === "assign" ? words.assign_and_leave : "Leave", onClose: () => setOpen("none"), children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "mx-meet__menu", "data-meet-leave-menu": leave.policy.hostLeavePrompt, children: [
3606
+ open === "menu" ? leave.choices.map((choice) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3607
+ "button",
3526
3608
  {
3527
- label: "Leave",
3528
- danger: true,
3609
+ type: "button",
3610
+ className: choice === "end_for_all" ? "mx-meet__menu-item mx-meet__menu-item--danger" : "mx-meet__menu-item",
3529
3611
  onClick: () => {
3530
- void room.leave();
3531
- onLeave?.();
3612
+ if (choice === "leave") leaveNow();
3613
+ else if (choice === "assign_and_leave") setOpen("assign");
3614
+ else if (leave.policy.endConfirm) setOpen("confirm");
3615
+ else endNow();
3532
3616
  },
3533
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PhoneOffIcon, {})
3534
- }
3535
- )
3536
- ] })
3617
+ children: words[choice]
3618
+ },
3619
+ choice
3620
+ )) : null,
3621
+ open === "assign" ? leave.candidates.map((person) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3622
+ "button",
3623
+ {
3624
+ type: "button",
3625
+ className: "mx-meet__menu-item",
3626
+ onClick: () => run(() => leave.assignAndLeave(person), true),
3627
+ children: person.displayName
3628
+ },
3629
+ String(person.identity)
3630
+ )) : null,
3631
+ open === "confirm" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
3632
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "mx-meet__menu-item mx-meet__menu-item--danger", onClick: endNow, children: words.end_for_all }),
3633
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "mx-meet__menu-item", onClick: () => setOpen("menu"), children: "Cancel" })
3634
+ ] }) : null,
3635
+ failure !== null ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "mx-meet__menu-note", role: "alert", children: failure }) : null
3636
+ ] }) }) : null
3537
3637
  ] });
3538
3638
  }
3539
3639
  function useUnreadChat(open) {