@ai-matrx/meet 0.7.8 → 0.7.10

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/dist/react.cjs CHANGED
@@ -321,6 +321,20 @@ var MeetError = class extends Error {
321
321
  return this.code === "permission-denied" || this.code === "device-not-found" || this.code === "device-in-use" || this.code === "insecure-context";
322
322
  }
323
323
  };
324
+ var SERVER_FAILED_SENTENCE = "The server hit an unexpected problem and nothing was changed.";
325
+ function isRawServerText(value) {
326
+ const text3 = value.trim();
327
+ return /^internal server error\b/i.test(text3) || /^[A-Z][A-Za-z0-9]*(Error|Exception)$/.test(text3) || /^[a-z][a-z0-9]*(_[a-z0-9]+)+$/.test(text3);
328
+ }
329
+ function humanDatabaseSentence(message) {
330
+ const text3 = message.trim();
331
+ if (text3.length === 0 || isRawServerText(text3)) return null;
332
+ if (/permission denied for|violates|relation "|does not exist|syntax error|column "|jwt|pgrst|duplicate key|null value in/i.test(
333
+ text3
334
+ ))
335
+ return null;
336
+ return text3;
337
+ }
324
338
  var FORBIDDEN_CODES = /* @__PURE__ */ new Set(["42501", "PGRST301", "PGRST302"]);
325
339
  var NOT_FOUND_CODES = /* @__PURE__ */ new Set(["PGRST116", "PGRST205"]);
326
340
  var CONFLICT_CODES = /* @__PURE__ */ new Set(["23505", "40001", "55000"]);
@@ -348,8 +362,8 @@ function normalizeMeetError(error, operation) {
348
362
  if (code !== void 0 && FORBIDDEN_CODES.has(code)) {
349
363
  return new MeetError(
350
364
  "forbidden",
351
- `${operation}: denied by the database (${code}: ${message})`,
352
- "Authorization is RLS plus auth-checked RPCs (R5). Fix the policy or the caller's membership \u2014 never route around it with a service-role client in a browser.",
365
+ humanDatabaseSentence(message) ?? "You don't have access to do that in this meeting.",
366
+ "Ask the meeting's host to do it, or to give you access.",
353
367
  error
354
368
  );
355
369
  }
@@ -364,15 +378,16 @@ function normalizeMeetError(error, operation) {
364
378
  if (code !== void 0 && CONFLICT_CODES.has(code)) {
365
379
  return new MeetError(
366
380
  "conflict",
367
- `${operation}: unique violation (${code}: ${message})`,
368
- "A concurrent writer won. Re-read the meeting rather than retrying the insert \u2014 for a call invite this is the idempotency key doing its job.",
381
+ humanDatabaseSentence(message) ?? "This meeting changed a moment ago, so nothing was saved.",
382
+ "Reload to see the latest, then try again.",
369
383
  error
370
384
  );
371
385
  }
386
+ const hint = error?.hint;
372
387
  return new MeetError(
373
388
  "transport",
374
- `${operation}: ${message}`,
375
- "Transient transport failure. Reads retry once; a join failure surfaces to the room phase as `failed` with this message rather than hanging on a spinner.",
389
+ /failed to fetch|networkerror|load failed|network request failed/i.test(message) ? "The server could not be reached." : humanDatabaseSentence(message) ?? SERVER_FAILED_SENTENCE,
390
+ typeof hint === "string" && humanDatabaseSentence(hint) !== null ? hint.trim() : "Nothing was changed \u2014 retry in a moment; if it keeps happening, reload the page.",
376
391
  error
377
392
  );
378
393
  }
@@ -780,11 +795,6 @@ function readText(data) {
780
795
  }
781
796
  return "";
782
797
  }
783
- var SERVER_FAILED_SENTENCE = "The server hit an unexpected problem and nothing was changed.";
784
- function isRawServerText(value) {
785
- const text3 = value.trim();
786
- return /^internal server error\b/i.test(text3) || /^[A-Z][A-Za-z0-9]*(Error|Exception)$/.test(text3) || /^[a-z][a-z0-9]*(_[a-z0-9]+)+$/.test(text3);
787
- }
788
798
  async function refusalFromResponse(response, operation, fallbackRemedy) {
789
799
  let body = null;
790
800
  try {
@@ -4590,6 +4600,15 @@ function createLiveKitDriver(handlers, options = {}) {
4590
4600
  handlers.participants([local, ...remotes]);
4591
4601
  };
4592
4602
  projectRoster = roster;
4603
+ created.on(RoomEvent.TrackSubscribed, (track) => {
4604
+ if (track.kind !== Track.Kind.Audio || typeof document === "undefined") return;
4605
+ const element = track.attach();
4606
+ element.setAttribute("data-mx-meet-audio", "");
4607
+ audioSink().appendChild(element);
4608
+ }).on(RoomEvent.TrackUnsubscribed, (track) => {
4609
+ if (track.kind !== Track.Kind.Audio) return;
4610
+ for (const element of track.detach()) element.remove();
4611
+ });
4593
4612
  created.on(RoomEvent.ParticipantConnected, roster).on(RoomEvent.ParticipantDisconnected, roster).on(RoomEvent.TrackSubscribed, roster).on(RoomEvent.TrackUnsubscribed, roster).on(RoomEvent.TrackMuted, roster).on(RoomEvent.TrackUnmuted, roster).on(RoomEvent.LocalTrackPublished, roster).on(RoomEvent.LocalTrackUnpublished, roster).on(RoomEvent.ParticipantNameChanged, roster).on(RoomEvent.ParticipantAttributesChanged, roster).on(RoomEvent.ParticipantMetadataChanged, roster).on(RoomEvent.RoomMetadataChanged, (metadata) => {
4594
4613
  handlers.roomMetadata?.(metadata ?? "");
4595
4614
  }).on(RoomEvent.ActiveSpeakersChanged, (speakers) => {
@@ -4605,6 +4624,8 @@ function createLiveKitDriver(handlers, options = {}) {
4605
4624
  participant?.identity ?? null
4606
4625
  );
4607
4626
  }).on(RoomEvent.Disconnected, (reason) => {
4627
+ audioContainer?.remove();
4628
+ audioContainer = null;
4608
4629
  handlers.disconnected(reason === void 0 ? null : String(reason));
4609
4630
  });
4610
4631
  try {
@@ -4646,10 +4667,26 @@ function createLiveKitDriver(handlers, options = {}) {
4646
4667
  microphone: Track.Source.Microphone,
4647
4668
  screen: Track.Source.ScreenShare
4648
4669
  };
4670
+ trackEvents = {
4671
+ subscribed: RoomEvent.TrackSubscribed,
4672
+ localPublished: RoomEvent.LocalTrackPublished
4673
+ };
4649
4674
  room = created;
4650
4675
  return created;
4651
4676
  }
4652
4677
  let sources = null;
4678
+ let trackEvents = null;
4679
+ let audioContainer = null;
4680
+ function audioSink() {
4681
+ if (audioContainer !== null && audioContainer.isConnected) return audioContainer;
4682
+ const container = document.createElement("div");
4683
+ container.setAttribute("data-mx-meet-audio-sink", "");
4684
+ container.setAttribute("aria-hidden", "true");
4685
+ container.style.display = "none";
4686
+ document.body.appendChild(container);
4687
+ audioContainer = container;
4688
+ return container;
4689
+ }
4653
4690
  function requireRoom(operation) {
4654
4691
  if (room === null) {
4655
4692
  throw new MeetError(
@@ -4680,6 +4717,8 @@ function createLiveKitDriver(handlers, options = {}) {
4680
4717
  } catch {
4681
4718
  }
4682
4719
  projectRoster = null;
4720
+ audioContainer?.remove();
4721
+ audioContainer = null;
4683
4722
  await target.disconnect();
4684
4723
  },
4685
4724
  async setMicrophoneEnabled(enabled) {
@@ -4745,14 +4784,33 @@ function createLiveKitDriver(handlers, options = {}) {
4745
4784
  attach(identity, kind, element) {
4746
4785
  const target = requireRoom("attach");
4747
4786
  const source = sources?.[kind];
4748
- const participant = target.localParticipant.identity === identity ? target.localParticipant : target.remoteParticipants.get(identity);
4749
- if (participant === void 0 || source === void 0) return () => void 0;
4750
- const publication = participant.getTrackPublication(source);
4751
- const track = publication?.track;
4752
- if (track === void 0) return () => void 0;
4753
- track.attach(element);
4787
+ if (source === void 0) return () => void 0;
4788
+ let current = null;
4789
+ const sync = () => {
4790
+ const participant = target.localParticipant.identity === identity ? target.localParticipant : target.remoteParticipants.get(identity);
4791
+ const track = participant?.getTrackPublication(source)?.track;
4792
+ if (track === void 0 || track === current) return;
4793
+ current?.detach(element);
4794
+ track.attach(element);
4795
+ current = track;
4796
+ };
4797
+ const onTrack = (...args) => {
4798
+ const who = args[args.length - 1];
4799
+ if (who?.identity === identity) sync();
4800
+ };
4801
+ sync();
4802
+ const events = trackEvents;
4803
+ if (events !== null) {
4804
+ target.on(events.subscribed, onTrack);
4805
+ target.on(events.localPublished, onTrack);
4806
+ }
4754
4807
  return () => {
4755
- track.detach(element);
4808
+ if (events !== null) {
4809
+ target.off(events.subscribed, onTrack);
4810
+ target.off(events.localPublished, onTrack);
4811
+ }
4812
+ current?.detach(element);
4813
+ current = null;
4756
4814
  };
4757
4815
  },
4758
4816
  activeDevices() {
@@ -6342,6 +6400,7 @@ function kindOf(person) {
6342
6400
  if (person.role === "host") return "host";
6343
6401
  if (person.role === "cohost") return "cohost";
6344
6402
  if (person.role === "guest") return person.userId !== null ? "signed-in guest" : "guest";
6403
+ if (person.userId === null) return "guest";
6345
6404
  return "member";
6346
6405
  }
6347
6406
  function ms(iso) {