vg-x07df 1.3.0 → 1.4.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # vg-x07df
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - edaed71: Bug fixes
8
+ - 72bb02b: exit
9
+ - 77d4cf4: Peformance and bug fixes
10
+
3
11
  ## 1.0.2
4
12
 
5
13
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -6,8 +6,8 @@ var zustand = require('zustand');
6
6
  var immer = require('zustand/middleware/immer');
7
7
  var mitt = require('mitt');
8
8
  var zod = require('zod');
9
- var livekitClient = require('livekit-client');
10
9
  var componentsReact = require('@livekit/components-react');
10
+ var livekitClient = require('livekit-client');
11
11
 
12
12
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
13
 
@@ -164,14 +164,14 @@ var useRtcStore = zustand.create()(
164
164
  var rtcStore = useRtcStore;
165
165
 
166
166
  // src/state/errors.ts
167
- function pushError(code, message, context, logger4) {
167
+ function pushError(code, message, context, logger5) {
168
168
  const error = {
169
169
  code,
170
170
  message,
171
171
  timestamp: Date.now(),
172
172
  context
173
173
  };
174
- logger4?.("error", message, { code, context });
174
+ logger5?.("error", message, { code, context });
175
175
  rtcStore.getState().addError(error);
176
176
  }
177
177
  function clearErrors(predicate) {
@@ -183,73 +183,73 @@ function clearErrors(predicate) {
183
183
  }
184
184
  });
185
185
  }
186
- function pushSocketValidationError(eventType, issues, payload, logger4) {
186
+ function pushSocketValidationError(eventType, issues, payload, logger5) {
187
187
  pushError(
188
188
  "SOCKET_PAYLOAD",
189
189
  `Invalid ${eventType} event payload`,
190
190
  { eventType, issues, payload },
191
- logger4
191
+ logger5
192
192
  );
193
193
  }
194
- function pushIdentityGuardError(reason, expected, received, logger4) {
194
+ function pushIdentityGuardError(reason, expected, received, logger5) {
195
195
  pushError(
196
196
  "JOIN_FLOW",
197
197
  // Use new error code
198
198
  `Identity guard failed: ${reason}`,
199
199
  { expected, received },
200
- logger4
200
+ logger5
201
201
  );
202
202
  }
203
- function pushLiveKitConnectError(message, error, logger4) {
203
+ function pushLiveKitConnectError(message, error, logger5) {
204
204
  pushError(
205
205
  "LIVEKIT_CONNECT",
206
206
  `LiveKit connection failed: ${message}`,
207
207
  { originalError: error },
208
- logger4
208
+ logger5
209
209
  );
210
210
  }
211
- function pushStaleEventError(eventType, reason, context, logger4) {
211
+ function pushStaleEventError(eventType, reason, context, logger5) {
212
212
  pushError(
213
213
  "JOIN_FLOW",
214
214
  // Use new error code
215
215
  `Ignored stale ${eventType} event: ${reason}`,
216
216
  context,
217
- logger4
217
+ logger5
218
218
  );
219
219
  }
220
- function pushApiError(operation, error, logger4) {
220
+ function pushApiError(operation, error, logger5) {
221
221
  const errorMessage = error instanceof Error ? error.message : String(error);
222
222
  pushError(
223
223
  "API_ERROR",
224
224
  `API ${operation} failed: ${errorMessage}`,
225
225
  { operation, originalError: error },
226
- logger4
226
+ logger5
227
227
  );
228
228
  }
229
- function pushNetworkError(operation, error, logger4) {
229
+ function pushNetworkError(operation, error, logger5) {
230
230
  const errorMessage = error instanceof Error ? error.message : String(error);
231
231
  pushError(
232
232
  "NETWORK",
233
233
  `Network error during ${operation}: ${errorMessage}`,
234
234
  { operation, originalError: error },
235
- logger4
235
+ logger5
236
236
  );
237
237
  }
238
- function pushMediaPermissionError(device, error, logger4) {
238
+ function pushMediaPermissionError(device, error, logger5) {
239
239
  pushError(
240
240
  "MEDIA_PERMISSION",
241
241
  `${device} permission denied`,
242
242
  { device, originalError: error },
243
- logger4
243
+ logger5
244
244
  );
245
245
  }
246
- function pushDeviceError(operation, device, error, logger4) {
246
+ function pushDeviceError(operation, device, error, logger5) {
247
247
  const errorMessage = error instanceof Error ? error.message : String(error);
248
248
  pushError(
249
249
  "DEVICE_SWITCH",
250
250
  `Failed to ${operation} ${device}: ${errorMessage}`,
251
251
  { operation, device, originalError: error },
252
- logger4
252
+ logger5
253
253
  );
254
254
  }
255
255
 
@@ -351,18 +351,9 @@ var SdkEventType = /* @__PURE__ */ ((SdkEventType2) => {
351
351
  SdkEventType2["CALL_CANCELED"] = "call:canceled";
352
352
  SdkEventType2["CALL_TIMEOUT"] = "call:timeout";
353
353
  SdkEventType2["JOIN_INFO_RECEIVED"] = "join-info:received";
354
+ SdkEventType2["CALL_STARTED"] = "call:started";
354
355
  SdkEventType2["PARTICIPANT_UPDATED"] = "participant:updated";
355
356
  SdkEventType2["PARTICIPANT_INVITED"] = "participant:invited";
356
- SdkEventType2["MEDIA_ENABLED"] = "media:enabled";
357
- SdkEventType2["MEDIA_DISABLED"] = "media:disabled";
358
- SdkEventType2["MEDIA_DEVICE_CHANGED"] = "media:device-changed";
359
- SdkEventType2["MEDIA_PERMISSION_GRANTED"] = "media:permission-granted";
360
- SdkEventType2["MEDIA_PERMISSION_DENIED"] = "media:permission-denied";
361
- SdkEventType2["CONNECTION_ESTABLISHED"] = "connection:established";
362
- SdkEventType2["CONNECTION_LOST"] = "connection:lost";
363
- SdkEventType2["CONNECTION_RECONNECTING"] = "connection:reconnecting";
364
- SdkEventType2["CONNECTION_QUALITY_CHANGED"] = "connection:quality-changed";
365
- SdkEventType2["ERROR_OCCURRED"] = "error:occurred";
366
357
  return SdkEventType2;
367
358
  })(SdkEventType || {});
368
359
  var callCancelledSchema = zod.z.object({
@@ -400,7 +391,7 @@ var callEndedSchema = zod.z.object({
400
391
  }).strict();
401
392
  var callInviteSchema = zod.z.object({
402
393
  callId: zod.z.string(),
403
- status: zod.z.enum(["pending", "active", "ended"]),
394
+ status: zod.z.enum(["pending", "ready", "active", "ended"]),
404
395
  caller: zod.z.object({
405
396
  firstName: zod.z.string().nullable(),
406
397
  lastName: zod.z.string().nullable(),
@@ -409,13 +400,11 @@ var callInviteSchema = zod.z.object({
409
400
  profilePhoto: zod.z.string().nullable(),
410
401
  userId: zod.z.string()
411
402
  }).strict(),
412
- mode: zod.z.enum(["VIDEO", "AUDIO"]),
413
- expiresAt: zod.z.string(),
414
- expiresInMs: zod.z.number()
403
+ mode: zod.z.enum(["VIDEO", "AUDIO"])
415
404
  }).strict();
416
405
  var callInviteAcceptedSchema = zod.z.object({
417
406
  callId: zod.z.string(),
418
- status: zod.z.enum(["pending", "active", "ended"]),
407
+ status: zod.z.enum(["pending", "ready", "active", "ended"]),
419
408
  participant: zod.z.object({
420
409
  firstName: zod.z.string().nullable(),
421
410
  lastName: zod.z.string().nullable(),
@@ -428,14 +417,14 @@ var callInviteAcceptedSchema = zod.z.object({
428
417
  }).strict();
429
418
  var callInviteCancelledSchema = zod.z.object({
430
419
  callId: zod.z.string(),
431
- status: zod.z.enum(["pending", "active", "ended"]),
420
+ status: zod.z.enum(["pending", "ready", "active", "ended"]),
432
421
  cancelledByUserId: zod.z.string(),
433
422
  cancelledAt: zod.z.string(),
434
423
  reason: zod.z.string()
435
424
  }).strict();
436
425
  var callInviteDeclinedSchema = zod.z.object({
437
426
  callId: zod.z.string(),
438
- status: zod.z.enum(["pending", "active", "ended"]),
427
+ status: zod.z.enum(["pending", "ready", "active", "ended"]),
439
428
  participant: zod.z.object({
440
429
  firstName: zod.z.string().nullable(),
441
430
  lastName: zod.z.string().nullable(),
@@ -449,7 +438,7 @@ var callInviteDeclinedSchema = zod.z.object({
449
438
  }).strict();
450
439
  var callInviteMissedSchema = zod.z.object({
451
440
  callId: zod.z.string(),
452
- status: zod.z.enum(["pending", "active", "ended"]),
441
+ status: zod.z.enum(["pending", "ready", "active", "ended"]),
453
442
  participant: zod.z.object({
454
443
  firstName: zod.z.string().nullable(),
455
444
  lastName: zod.z.string().nullable(),
@@ -486,7 +475,7 @@ var callMissedSchema = zod.z.object({
486
475
  }).strict();
487
476
  var callParticipantAddedSchema = zod.z.object({
488
477
  callId: zod.z.string(),
489
- status: zod.z.enum(["pending", "active", "ended"]),
478
+ status: zod.z.enum(["pending", "ready", "active", "ended"]),
490
479
  participant: zod.z.object({
491
480
  participantId: zod.z.string(),
492
481
  userId: zod.z.string(),
@@ -499,6 +488,12 @@ var callParticipantAddedSchema = zod.z.object({
499
488
  joinState: zod.z.enum(["not_joined", "joined"])
500
489
  }).strict()
501
490
  }).strict();
491
+ var callRoomStartedSchema = zod.z.object({
492
+ callId: zod.z.string(),
493
+ roomName: zod.z.string(),
494
+ startedAt: zod.z.string(),
495
+ status: zod.z.literal("active")
496
+ }).strict();
502
497
 
503
498
  // src/core/socketio/handlers/invite.handler.ts
504
499
  var InviteHandler = class extends BaseSocketHandler {
@@ -524,9 +519,7 @@ var InviteHandler = class extends BaseSocketHandler {
524
519
  email: data.caller.email,
525
520
  profilePhoto: data.caller.profilePhoto
526
521
  },
527
- mode: data.mode,
528
- expiresAt: data.expiresAt,
529
- expiresInMs: data.expiresInMs
522
+ mode: data.mode
530
523
  };
531
524
  state.session = {
532
525
  id: data.callId,
@@ -624,6 +617,9 @@ var InviteAcceptedHandler = class extends BaseSocketHandler {
624
617
  return;
625
618
  }
626
619
  this.updateStore((state) => {
620
+ if (state.session && data.status) {
621
+ state.session.status = data.status;
622
+ }
627
623
  const userId = data.participant.userId;
628
624
  if (state.outgoingInvites[userId]) {
629
625
  state.outgoingInvites[userId].status = "accepted";
@@ -995,6 +991,11 @@ var ParticipantAddedHandler = class extends BaseSocketHandler {
995
991
  this.logger.warn("Ignoring participant added for different call", { callId: data.callId });
996
992
  return;
997
993
  }
994
+ this.updateStore((state) => {
995
+ if (state.session && data.status) {
996
+ state.session.status = data.status;
997
+ }
998
+ });
998
999
  eventBus.emit("participant:updated" /* PARTICIPANT_UPDATED */, {
999
1000
  participantId: data.participant.participantId,
1000
1001
  timestamp: Date.now()
@@ -1005,6 +1006,32 @@ var ParticipantAddedHandler = class extends BaseSocketHandler {
1005
1006
  }
1006
1007
  };
1007
1008
 
1009
+ // src/core/socketio/handlers/room-started.handler.ts
1010
+ var RoomStartedHandler = class extends BaseSocketHandler {
1011
+ constructor() {
1012
+ super(...arguments);
1013
+ this.eventName = "call:roomStarted";
1014
+ this.schema = callRoomStartedSchema;
1015
+ }
1016
+ handle(data) {
1017
+ this.logger.info("LiveKit room started", {
1018
+ callId: data.callId,
1019
+ roomName: data.roomName
1020
+ });
1021
+ this.updateStore((state) => {
1022
+ if (state.session) {
1023
+ state.session.status = data.status;
1024
+ }
1025
+ });
1026
+ eventBus.emit("call:started" /* CALL_STARTED */, {
1027
+ callId: data.callId,
1028
+ roomName: data.roomName,
1029
+ timestamp: Date.now()
1030
+ });
1031
+ this.logger.debug("Session status updated to active");
1032
+ }
1033
+ };
1034
+
1008
1035
  // src/core/socketio/handlers/handler.registry.ts
1009
1036
  var logger = createLogger("socketio:registry");
1010
1037
  var SocketHandlerRegistry = class {
@@ -1029,7 +1056,9 @@ var SocketHandlerRegistry = class {
1029
1056
  new InviteMissedHandler(this.options),
1030
1057
  new SessionCancelledHandler(this.options),
1031
1058
  new SessionMissedHandler(this.options),
1032
- new ParticipantAddedHandler(this.options)
1059
+ new ParticipantAddedHandler(this.options),
1060
+ // Phase 4: LiveKit room events
1061
+ new RoomStartedHandler(this.options)
1033
1062
  ];
1034
1063
  for (const handler of handlers) {
1035
1064
  this.handlers.set(handler.eventName, handler);
@@ -1964,6 +1993,9 @@ function createCallsService(config) {
1964
1993
  }
1965
1994
  async function accept(callId) {
1966
1995
  ensureApiConfigured();
1996
+ rtcStore.setState((state) => {
1997
+ state.incomingInvite = null;
1998
+ });
1967
1999
  return CallsService.postSignalCallsByCallIdAccept({
1968
2000
  callId,
1969
2001
  appId
@@ -2275,50 +2307,10 @@ function useCallInitiated() {
2275
2307
  function useSessionDuration() {
2276
2308
  return 0;
2277
2309
  }
2278
- var defaultRoomOptions = {
2279
- adaptiveStream: true,
2280
- dynacast: true
2281
- };
2282
- function useRoom(options) {
2283
- const [room] = React.useState(() => new livekitClient.Room(options || defaultRoomOptions));
2284
- const livekitInfo = useRtcStore((state) => state.session?.livekitInfo);
2285
- React.useEffect(() => {
2286
- if (!livekitInfo) {
2287
- return;
2288
- }
2289
- room.connect(livekitInfo.url, livekitInfo.token);
2290
- return () => {
2291
- room.disconnect();
2292
- };
2293
- }, [livekitInfo, room]);
2294
- if (!livekitInfo) {
2295
- return null;
2296
- }
2297
- return room;
2298
- }
2299
- function useParticipantMetadata(participantOrIdentity) {
2300
- const room = useRoom();
2301
- const participants = componentsReact.useParticipants(room ? { room } : {});
2302
- let resolvedParticipant;
2303
- if (typeof participantOrIdentity === "string") {
2304
- resolvedParticipant = participants.find(
2305
- (p) => p.identity === participantOrIdentity
2306
- );
2307
- } else if (participantOrIdentity) {
2308
- resolvedParticipant = participantOrIdentity;
2309
- }
2310
- const livekitInfo = componentsReact.useParticipantInfo(
2311
- resolvedParticipant ? { participant: resolvedParticipant } : {}
2312
- );
2313
- if (!livekitInfo.metadata) {
2314
- return null;
2315
- }
2310
+ function useParticipantMetadata(participant) {
2311
+ const info = componentsReact.useParticipantInfo({ participant });
2316
2312
  try {
2317
- const metadata = JSON.parse(livekitInfo.metadata);
2318
- if (!metadata.userId || !metadata.role) {
2319
- console.warn("Invalid participant metadata: missing required fields", metadata);
2320
- return null;
2321
- }
2313
+ const metadata = JSON.parse(info.metadata);
2322
2314
  return {
2323
2315
  userId: metadata.userId,
2324
2316
  role: metadata.role,
@@ -2334,6 +2326,47 @@ function useParticipantMetadata(participantOrIdentity) {
2334
2326
  }
2335
2327
  }
2336
2328
 
2329
+ // src/hooks/useLivekitInfo.ts
2330
+ function useLivekitInfo() {
2331
+ return useRtcStore((state) => state.session?.livekitInfo ?? null);
2332
+ }
2333
+
2334
+ // src/hooks/useHasActiveSession.ts
2335
+ function useHasActiveSession() {
2336
+ return useRtcStore((state) => {
2337
+ if (!state.session) {
2338
+ return false;
2339
+ }
2340
+ return state.session.status === "pending" || state.session.status === "active";
2341
+ });
2342
+ }
2343
+
2344
+ // src/hooks/useRoomReady.ts
2345
+ function useRoomReady() {
2346
+ const livekitInfo = useLivekitInfo();
2347
+ const { status } = useCallState();
2348
+ return livekitInfo !== null && (status === "ready" || status === "active");
2349
+ }
2350
+ var logger4 = createLogger("useAutoConnectRoom");
2351
+ function useAutoConnectRoom(options) {
2352
+ const [room] = React.useState(() => new livekitClient.Room(options));
2353
+ const isReady = useRoomReady();
2354
+ const livekitInfo = useLivekitInfo();
2355
+ React.useEffect(() => {
2356
+ if (isReady && livekitInfo) {
2357
+ room.connect(livekitInfo.url, livekitInfo.token).catch((error) => {
2358
+ logger4.error("Failed to connect to LiveKit room", error);
2359
+ });
2360
+ } else if (room.state === livekitClient.ConnectionState.Connected) {
2361
+ room.disconnect();
2362
+ }
2363
+ return () => {
2364
+ room.disconnect();
2365
+ };
2366
+ }, [isReady, livekitInfo, room]);
2367
+ return room;
2368
+ }
2369
+
2337
2370
  exports.RtcProvider = RtcProvider;
2338
2371
  exports.SdkEventType = SdkEventType;
2339
2372
  exports.apiConfig = apiConfig;
@@ -2349,6 +2382,7 @@ exports.callInviteSentSchema = callInviteSentSchema;
2349
2382
  exports.callJoinInfoSchema = callJoinInfoSchema;
2350
2383
  exports.callMissedSchema = callMissedSchema;
2351
2384
  exports.callParticipantAddedSchema = callParticipantAddedSchema;
2385
+ exports.callRoomStartedSchema = callRoomStartedSchema;
2352
2386
  exports.clearErrors = clearErrors;
2353
2387
  exports.eventBus = eventBus;
2354
2388
  exports.pushApiError = pushApiError;
@@ -2360,15 +2394,18 @@ exports.pushMediaPermissionError = pushMediaPermissionError;
2360
2394
  exports.pushNetworkError = pushNetworkError;
2361
2395
  exports.pushSocketValidationError = pushSocketValidationError;
2362
2396
  exports.pushStaleEventError = pushStaleEventError;
2397
+ exports.useAutoConnectRoom = useAutoConnectRoom;
2363
2398
  exports.useCallActions = useCallActions;
2364
2399
  exports.useCallInitiated = useCallInitiated;
2365
2400
  exports.useCallState = useCallState;
2366
2401
  exports.useEvent = useEvent;
2402
+ exports.useHasActiveSession = useHasActiveSession;
2367
2403
  exports.useIncomingInvite = useIncomingInvite;
2368
2404
  exports.useInviteAccepted = useInviteAccepted;
2405
+ exports.useLivekitInfo = useLivekitInfo;
2369
2406
  exports.useOutgoingInvites = useOutgoingInvites;
2370
2407
  exports.useParticipantMetadata = useParticipantMetadata;
2371
- exports.useRoom = useRoom;
2408
+ exports.useRoomReady = useRoomReady;
2372
2409
  exports.useSdk = useSdk;
2373
2410
  exports.useSessionDuration = useSessionDuration;
2374
2411
  exports.useSessionId = useSessionId;