@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.js CHANGED
@@ -43,6 +43,20 @@ var MeetError = class extends Error {
43
43
  return this.code === "permission-denied" || this.code === "device-not-found" || this.code === "device-in-use" || this.code === "insecure-context";
44
44
  }
45
45
  };
46
+ var SERVER_FAILED_SENTENCE = "The server hit an unexpected problem and nothing was changed.";
47
+ function isRawServerText(value) {
48
+ const text3 = value.trim();
49
+ 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);
50
+ }
51
+ function humanDatabaseSentence(message) {
52
+ const text3 = message.trim();
53
+ if (text3.length === 0 || isRawServerText(text3)) return null;
54
+ if (/permission denied for|violates|relation "|does not exist|syntax error|column "|jwt|pgrst|duplicate key|null value in/i.test(
55
+ text3
56
+ ))
57
+ return null;
58
+ return text3;
59
+ }
46
60
  var FORBIDDEN_CODES = /* @__PURE__ */ new Set(["42501", "PGRST301", "PGRST302"]);
47
61
  var NOT_FOUND_CODES = /* @__PURE__ */ new Set(["PGRST116", "PGRST205"]);
48
62
  var CONFLICT_CODES = /* @__PURE__ */ new Set(["23505", "40001", "55000"]);
@@ -70,8 +84,8 @@ function normalizeMeetError(error, operation) {
70
84
  if (code !== void 0 && FORBIDDEN_CODES.has(code)) {
71
85
  return new MeetError(
72
86
  "forbidden",
73
- `${operation}: denied by the database (${code}: ${message})`,
74
- "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.",
87
+ humanDatabaseSentence(message) ?? "You don't have access to do that in this meeting.",
88
+ "Ask the meeting's host to do it, or to give you access.",
75
89
  error
76
90
  );
77
91
  }
@@ -86,15 +100,16 @@ function normalizeMeetError(error, operation) {
86
100
  if (code !== void 0 && CONFLICT_CODES.has(code)) {
87
101
  return new MeetError(
88
102
  "conflict",
89
- `${operation}: unique violation (${code}: ${message})`,
90
- "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.",
103
+ humanDatabaseSentence(message) ?? "This meeting changed a moment ago, so nothing was saved.",
104
+ "Reload to see the latest, then try again.",
91
105
  error
92
106
  );
93
107
  }
108
+ const hint = error?.hint;
94
109
  return new MeetError(
95
110
  "transport",
96
- `${operation}: ${message}`,
97
- "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.",
111
+ /failed to fetch|networkerror|load failed|network request failed/i.test(message) ? "The server could not be reached." : humanDatabaseSentence(message) ?? SERVER_FAILED_SENTENCE,
112
+ typeof hint === "string" && humanDatabaseSentence(hint) !== null ? hint.trim() : "Nothing was changed \u2014 retry in a moment; if it keeps happening, reload the page.",
98
113
  error
99
114
  );
100
115
  }
@@ -502,11 +517,6 @@ function readText(data) {
502
517
  }
503
518
  return "";
504
519
  }
505
- var SERVER_FAILED_SENTENCE = "The server hit an unexpected problem and nothing was changed.";
506
- function isRawServerText(value) {
507
- const text3 = value.trim();
508
- 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);
509
- }
510
520
  async function refusalFromResponse(response, operation, fallbackRemedy) {
511
521
  let body = null;
512
522
  try {
@@ -4312,6 +4322,15 @@ function createLiveKitDriver(handlers, options = {}) {
4312
4322
  handlers.participants([local, ...remotes]);
4313
4323
  };
4314
4324
  projectRoster = roster;
4325
+ created.on(RoomEvent.TrackSubscribed, (track) => {
4326
+ if (track.kind !== Track.Kind.Audio || typeof document === "undefined") return;
4327
+ const element = track.attach();
4328
+ element.setAttribute("data-mx-meet-audio", "");
4329
+ audioSink().appendChild(element);
4330
+ }).on(RoomEvent.TrackUnsubscribed, (track) => {
4331
+ if (track.kind !== Track.Kind.Audio) return;
4332
+ for (const element of track.detach()) element.remove();
4333
+ });
4315
4334
  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) => {
4316
4335
  handlers.roomMetadata?.(metadata ?? "");
4317
4336
  }).on(RoomEvent.ActiveSpeakersChanged, (speakers) => {
@@ -4327,6 +4346,8 @@ function createLiveKitDriver(handlers, options = {}) {
4327
4346
  participant?.identity ?? null
4328
4347
  );
4329
4348
  }).on(RoomEvent.Disconnected, (reason) => {
4349
+ audioContainer?.remove();
4350
+ audioContainer = null;
4330
4351
  handlers.disconnected(reason === void 0 ? null : String(reason));
4331
4352
  });
4332
4353
  try {
@@ -4368,10 +4389,26 @@ function createLiveKitDriver(handlers, options = {}) {
4368
4389
  microphone: Track.Source.Microphone,
4369
4390
  screen: Track.Source.ScreenShare
4370
4391
  };
4392
+ trackEvents = {
4393
+ subscribed: RoomEvent.TrackSubscribed,
4394
+ localPublished: RoomEvent.LocalTrackPublished
4395
+ };
4371
4396
  room = created;
4372
4397
  return created;
4373
4398
  }
4374
4399
  let sources = null;
4400
+ let trackEvents = null;
4401
+ let audioContainer = null;
4402
+ function audioSink() {
4403
+ if (audioContainer !== null && audioContainer.isConnected) return audioContainer;
4404
+ const container = document.createElement("div");
4405
+ container.setAttribute("data-mx-meet-audio-sink", "");
4406
+ container.setAttribute("aria-hidden", "true");
4407
+ container.style.display = "none";
4408
+ document.body.appendChild(container);
4409
+ audioContainer = container;
4410
+ return container;
4411
+ }
4375
4412
  function requireRoom(operation) {
4376
4413
  if (room === null) {
4377
4414
  throw new MeetError(
@@ -4402,6 +4439,8 @@ function createLiveKitDriver(handlers, options = {}) {
4402
4439
  } catch {
4403
4440
  }
4404
4441
  projectRoster = null;
4442
+ audioContainer?.remove();
4443
+ audioContainer = null;
4405
4444
  await target.disconnect();
4406
4445
  },
4407
4446
  async setMicrophoneEnabled(enabled) {
@@ -4467,14 +4506,33 @@ function createLiveKitDriver(handlers, options = {}) {
4467
4506
  attach(identity, kind, element) {
4468
4507
  const target = requireRoom("attach");
4469
4508
  const source = sources?.[kind];
4470
- const participant = target.localParticipant.identity === identity ? target.localParticipant : target.remoteParticipants.get(identity);
4471
- if (participant === void 0 || source === void 0) return () => void 0;
4472
- const publication = participant.getTrackPublication(source);
4473
- const track = publication?.track;
4474
- if (track === void 0) return () => void 0;
4475
- track.attach(element);
4509
+ if (source === void 0) return () => void 0;
4510
+ let current = null;
4511
+ const sync = () => {
4512
+ const participant = target.localParticipant.identity === identity ? target.localParticipant : target.remoteParticipants.get(identity);
4513
+ const track = participant?.getTrackPublication(source)?.track;
4514
+ if (track === void 0 || track === current) return;
4515
+ current?.detach(element);
4516
+ track.attach(element);
4517
+ current = track;
4518
+ };
4519
+ const onTrack = (...args) => {
4520
+ const who = args[args.length - 1];
4521
+ if (who?.identity === identity) sync();
4522
+ };
4523
+ sync();
4524
+ const events = trackEvents;
4525
+ if (events !== null) {
4526
+ target.on(events.subscribed, onTrack);
4527
+ target.on(events.localPublished, onTrack);
4528
+ }
4476
4529
  return () => {
4477
- track.detach(element);
4530
+ if (events !== null) {
4531
+ target.off(events.subscribed, onTrack);
4532
+ target.off(events.localPublished, onTrack);
4533
+ }
4534
+ current?.detach(element);
4535
+ current = null;
4478
4536
  };
4479
4537
  },
4480
4538
  activeDevices() {
@@ -6064,6 +6122,7 @@ function kindOf(person) {
6064
6122
  if (person.role === "host") return "host";
6065
6123
  if (person.role === "cohost") return "cohost";
6066
6124
  if (person.role === "guest") return person.userId !== null ? "signed-in guest" : "guest";
6125
+ if (person.userId === null) return "guest";
6067
6126
  return "member";
6068
6127
  }
6069
6128
  function ms(iso) {