farvex 1.0.0 → 1.0.1

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/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { d as HostClientConfig, H as HostClient, j as SessionClientConfig, i as SessionClient } from './types-DhJEeeui.cjs';
2
- export { C as CallpadError, a as ClientEvents, b as ClientStatus, c as CustomerStartInput, e as HostControls, f as HostParticipantInput, g as HostSessions, I as Invites, L as ListQuery, h as ListSessionsResponse, N as Nullable, P as ParticipantRef, R as RealtimeToken, S as SessionAction, k as SessionDuration, l as SessionInvite, m as SessionRecording, n as SessionRecordingControl, o as Sessions, p as StartedSession, q as StoreTopic, U as Unsubscribe, V as VoiceJoinGrant, r as VoiceParticipant, s as VoiceSession } from './types-DhJEeeui.cjs';
1
+ import { d as HostClientConfig, H as HostClient, k as SessionClientConfig, j as SessionClient } from './types-Dgwrb3rf.cjs';
2
+ export { C as CallpadError, a as ClientEvents, b as ClientStatus, c as CustomerStartInput, e as HostControls, f as HostParticipantInput, g as HostSessions, h as HostStartInput, I as Invites, L as ListQuery, i as ListSessionsResponse, N as Nullable, P as ParticipantRef, R as RealtimeToken, S as SessionAction, l as SessionDuration, m as SessionInvite, n as SessionRecording, o as SessionRecordingControl, p as Sessions, q as StartedSession, r as StoreTopic, U as Unsubscribe, V as VoiceJoinGrant, s as VoiceParticipant, t as VoiceSession } from './types-Dgwrb3rf.cjs';
3
3
 
4
4
  declare const createSessionClient: (config: SessionClientConfig) => SessionClient;
5
5
  declare const createHostClient: (config: HostClientConfig) => HostClient;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { d as HostClientConfig, H as HostClient, j as SessionClientConfig, i as SessionClient } from './types-DhJEeeui.js';
2
- export { C as CallpadError, a as ClientEvents, b as ClientStatus, c as CustomerStartInput, e as HostControls, f as HostParticipantInput, g as HostSessions, I as Invites, L as ListQuery, h as ListSessionsResponse, N as Nullable, P as ParticipantRef, R as RealtimeToken, S as SessionAction, k as SessionDuration, l as SessionInvite, m as SessionRecording, n as SessionRecordingControl, o as Sessions, p as StartedSession, q as StoreTopic, U as Unsubscribe, V as VoiceJoinGrant, r as VoiceParticipant, s as VoiceSession } from './types-DhJEeeui.js';
1
+ import { d as HostClientConfig, H as HostClient, k as SessionClientConfig, j as SessionClient } from './types-Dgwrb3rf.js';
2
+ export { C as CallpadError, a as ClientEvents, b as ClientStatus, c as CustomerStartInput, e as HostControls, f as HostParticipantInput, g as HostSessions, h as HostStartInput, I as Invites, L as ListQuery, i as ListSessionsResponse, N as Nullable, P as ParticipantRef, R as RealtimeToken, S as SessionAction, l as SessionDuration, m as SessionInvite, n as SessionRecording, o as SessionRecordingControl, p as Sessions, q as StartedSession, r as StoreTopic, U as Unsubscribe, V as VoiceJoinGrant, s as VoiceParticipant, t as VoiceSession } from './types-Dgwrb3rf.js';
3
3
 
4
4
  declare const createSessionClient: (config: SessionClientConfig) => SessionClient;
5
5
  declare const createHostClient: (config: HostClientConfig) => HostClient;
package/dist/index.js CHANGED
@@ -1063,6 +1063,7 @@ var createSessionStore = (userId) => {
1063
1063
  let listCache = [];
1064
1064
  let invitesCache = [];
1065
1065
  let inviteKey = "";
1066
+ let inviteExpiryTimer = null;
1066
1067
  const emit = (topic) => {
1067
1068
  const fns = subscribers.get(topic);
1068
1069
  if (!fns) {
@@ -1101,7 +1102,9 @@ var createSessionStore = (userId) => {
1101
1102
  }
1102
1103
  };
1103
1104
  const refreshInvites = () => {
1104
- const invites = listCache.map((session) => inviteFrom(session, userId)).filter((invite) => invite !== null);
1105
+ const now = Date.now();
1106
+ const invites = listCache.map((session) => inviteFrom(session, userId, now)).filter((invite) => invite !== null);
1107
+ scheduleInviteExpiry(invites, now);
1105
1108
  const nextKey = invites.map(
1106
1109
  (invite) => `${invite.session.id}:${invite.participant.id}:${invite.participant.state}:${invite.participant.inviteExpiresAt ?? ""}`
1107
1110
  ).join("|");
@@ -1113,6 +1116,34 @@ var createSessionStore = (userId) => {
1113
1116
  invitesCache = invites;
1114
1117
  return true;
1115
1118
  };
1119
+ const clearInviteExpiryTimer = () => {
1120
+ if (inviteExpiryTimer) {
1121
+ globalThis.clearTimeout(inviteExpiryTimer);
1122
+ inviteExpiryTimer = null;
1123
+ }
1124
+ };
1125
+ const scheduleInviteExpiry = (invites, now) => {
1126
+ clearInviteExpiryTimer();
1127
+ const nextExpiry = invites.reduce((min, invite) => {
1128
+ const expiresAt = inviteExpiryMs(invite.participant);
1129
+ if (expiresAt === null) {
1130
+ return min;
1131
+ }
1132
+ return min === null ? expiresAt : Math.min(min, expiresAt);
1133
+ }, null);
1134
+ if (nextExpiry === null) {
1135
+ return;
1136
+ }
1137
+ inviteExpiryTimer = globalThis.setTimeout(
1138
+ () => {
1139
+ inviteExpiryTimer = null;
1140
+ if (refreshInvites()) {
1141
+ emit("invites");
1142
+ }
1143
+ },
1144
+ Math.max(0, nextExpiry - now)
1145
+ );
1146
+ };
1116
1147
  const notifySessionChange = (sessionId) => {
1117
1148
  refresh();
1118
1149
  const invitesChanged = refreshInvites();
@@ -1199,13 +1230,17 @@ var createSessionStore = (userId) => {
1199
1230
  return next;
1200
1231
  },
1201
1232
  can: (session, action) => can(session, userId, action),
1233
+ dispose: () => {
1234
+ clearInviteExpiryTimer();
1235
+ subscribers.clear();
1236
+ },
1202
1237
  subscribe
1203
1238
  };
1204
1239
  };
1205
1240
  var selfParticipant = (session, userId) => session.participants.find((participant) => participant.userId === userId) ?? null;
1206
- var inviteFrom = (session, userId) => {
1241
+ var inviteFrom = (session, userId, now) => {
1207
1242
  const participant = selfParticipant(session, userId);
1208
- if (!participant || participant.state !== "invited") {
1243
+ if (!participant || session.state === "ended" || !isActiveInvite(participant, now)) {
1209
1244
  return null;
1210
1245
  }
1211
1246
  return { session, participant };
@@ -1218,7 +1253,7 @@ var can = (session, userId, action) => {
1218
1253
  switch (action) {
1219
1254
  case "accept":
1220
1255
  case "reject":
1221
- return self.state === "invited";
1256
+ return isActiveInvite(self);
1222
1257
  case "join":
1223
1258
  return self.transport === "webrtc" && (self.state === "accepted" || self.state === "joined");
1224
1259
  case "leave":
@@ -1233,6 +1268,17 @@ var can = (session, userId, action) => {
1233
1268
  return isHost(self) && session.recording.status === "recording";
1234
1269
  }
1235
1270
  };
1271
+ var isActiveInvite = (participant, now = Date.now()) => {
1272
+ const expiresAt = inviteExpiryMs(participant);
1273
+ return participant.state === "invited" && expiresAt !== null && expiresAt > now;
1274
+ };
1275
+ var inviteExpiryMs = (participant) => {
1276
+ if (!participant.inviteExpiresAt) {
1277
+ return null;
1278
+ }
1279
+ const expiresAt = Date.parse(participant.inviteExpiresAt);
1280
+ return Number.isFinite(expiresAt) ? expiresAt : null;
1281
+ };
1236
1282
  var isHost = (participant) => participant.role === "host" && (participant.kind === "agent" || participant.kind === "vendor_user");
1237
1283
 
1238
1284
  // src/core/client.ts
@@ -1253,7 +1299,7 @@ var createSessionClient = (config) => {
1253
1299
  },
1254
1300
  connect: core.connect,
1255
1301
  disconnect: core.realtime.disconnect,
1256
- dispose: core.realtime.dispose,
1302
+ dispose: core.dispose,
1257
1303
  on: core.emitter.on,
1258
1304
  subscribe: core.store.subscribe
1259
1305
  };
@@ -1277,7 +1323,7 @@ var createHostClient = (config) => {
1277
1323
  host: createHostControls(core),
1278
1324
  connect: core.connect,
1279
1325
  disconnect: core.realtime.disconnect,
1280
- dispose: core.realtime.dispose,
1326
+ dispose: core.dispose,
1281
1327
  on: core.emitter.on,
1282
1328
  subscribe: core.store.subscribe
1283
1329
  };
@@ -1316,6 +1362,10 @@ var createCore = (config) => {
1316
1362
  throw err;
1317
1363
  }
1318
1364
  };
1365
+ const dispose = async () => {
1366
+ await realtime.dispose();
1367
+ store.dispose();
1368
+ };
1319
1369
  return {
1320
1370
  api,
1321
1371
  auth: config.auth,
@@ -1323,6 +1373,7 @@ var createCore = (config) => {
1323
1373
  emitter,
1324
1374
  realtime,
1325
1375
  connect,
1376
+ dispose,
1326
1377
  applySession,
1327
1378
  applyStarted,
1328
1379
  patchRecording