@amityco/ts-sdk 7.11.1-1440698f.0 → 7.11.1-19ae17f9.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.
Files changed (76) hide show
  1. package/dist/@types/core/events.d.ts +0 -3
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +0 -2
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +0 -16
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/domains/room.d.ts +0 -11
  8. package/dist/@types/domains/room.d.ts.map +1 -1
  9. package/dist/client/api/resumeSession.d.ts.map +1 -1
  10. package/dist/client/utils/ObjectResolver/objectResolverEngine.d.ts.map +1 -0
  11. package/dist/client/utils/ObjectResolver/objectResolverEngineOnLoginHandler.d.ts.map +1 -0
  12. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts.map +1 -0
  13. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts.map +1 -0
  14. package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +1 -0
  15. package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngineOnLoginHandler.d.ts.map +1 -0
  16. package/dist/core/events.d.ts +3 -3
  17. package/dist/core/events.d.ts.map +1 -1
  18. package/dist/core/model/index.d.ts.map +1 -1
  19. package/dist/index.cjs.js +46 -501
  20. package/dist/index.esm.js +46 -501
  21. package/dist/index.umd.js +3 -3
  22. package/dist/invitationRepository/api/index.d.ts +0 -1
  23. package/dist/invitationRepository/api/index.d.ts.map +1 -1
  24. package/dist/roomRepository/api/removeParticipant.d.ts.map +1 -1
  25. package/dist/roomRepository/events/onRoomCoHostInviteAccepted.d.ts +1 -1
  26. package/dist/roomRepository/events/onRoomCoHostInviteAccepted.d.ts.map +1 -1
  27. package/dist/roomRepository/index.d.ts +0 -1
  28. package/dist/roomRepository/index.d.ts.map +1 -1
  29. package/dist/roomRepository/internalApi/index.d.ts +0 -2
  30. package/dist/roomRepository/internalApi/index.d.ts.map +1 -1
  31. package/dist/roomRepository/observers/getRoom.d.ts.map +1 -1
  32. package/dist/roomRepository/observers/index.d.ts +0 -2
  33. package/dist/roomRepository/observers/index.d.ts.map +1 -1
  34. package/package.json +1 -1
  35. package/dist/client/api/getPresenceSetting.d.ts +0 -2
  36. package/dist/client/api/getPresenceSetting.d.ts.map +0 -1
  37. package/dist/client/services/ObjectResolver/objectResolverEngine.d.ts.map +0 -1
  38. package/dist/client/services/ObjectResolver/objectResolverEngineOnLoginHandler.d.ts.map +0 -1
  39. package/dist/client/services/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts.map +0 -1
  40. package/dist/client/services/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts.map +0 -1
  41. package/dist/client/services/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +0 -1
  42. package/dist/client/services/ReadReceiptSync/readReceiptSyncEngineOnLoginHandler.d.ts.map +0 -1
  43. package/dist/invitationRepository/api/acceptInvitation.d.ts +0 -16
  44. package/dist/invitationRepository/api/acceptInvitation.d.ts.map +0 -1
  45. package/dist/invitationRepository/api/getMyInvitation.d.ts +0 -16
  46. package/dist/invitationRepository/api/getMyInvitation.d.ts.map +0 -1
  47. package/dist/roomRepository/events/onRoomParticipantRemovedLocal.d.ts +0 -17
  48. package/dist/roomRepository/events/onRoomParticipantRemovedLocal.d.ts.map +0 -1
  49. package/dist/roomRepository/events/onRoomWatchingCountUpdated.d.ts +0 -17
  50. package/dist/roomRepository/events/onRoomWatchingCountUpdated.d.ts.map +0 -1
  51. package/dist/roomRepository/events/onRoomWatchingUsersFetched.d.ts +0 -17
  52. package/dist/roomRepository/events/onRoomWatchingUsersFetched.d.ts.map +0 -1
  53. package/dist/roomRepository/internalApi/getWatchingCount.d.ts +0 -2
  54. package/dist/roomRepository/internalApi/getWatchingCount.d.ts.map +0 -1
  55. package/dist/roomRepository/internalApi/getWatchingUsers.d.ts +0 -2
  56. package/dist/roomRepository/internalApi/getWatchingUsers.d.ts.map +0 -1
  57. package/dist/roomRepository/observers/getWatchingCount.d.ts +0 -18
  58. package/dist/roomRepository/observers/getWatchingCount.d.ts.map +0 -1
  59. package/dist/roomRepository/observers/getWatchingUsers.d.ts +0 -18
  60. package/dist/roomRepository/observers/getWatchingUsers.d.ts.map +0 -1
  61. package/dist/roomRepository/services/WatchingSync/WatchingSyncEngine.d.ts +0 -24
  62. package/dist/roomRepository/services/WatchingSync/WatchingSyncEngine.d.ts.map +0 -1
  63. package/dist/roomRepository/services/WatchingSync/index.d.ts +0 -2
  64. package/dist/roomRepository/services/WatchingSync/index.d.ts.map +0 -1
  65. package/dist/roomRepository/services/WatchingSync/watchingSyncEngineFactory.d.ts +0 -32
  66. package/dist/roomRepository/services/WatchingSync/watchingSyncEngineFactory.d.ts.map +0 -1
  67. package/dist/roomRepository/services/index.d.ts +0 -2
  68. package/dist/roomRepository/services/index.d.ts.map +0 -1
  69. package/dist/utils/linkedObject/roomWatchingUserLinkedObject.d.ts +0 -2
  70. package/dist/utils/linkedObject/roomWatchingUserLinkedObject.d.ts.map +0 -1
  71. /package/dist/client/{services → utils}/ObjectResolver/objectResolverEngine.d.ts +0 -0
  72. /package/dist/client/{services → utils}/ObjectResolver/objectResolverEngineOnLoginHandler.d.ts +0 -0
  73. /package/dist/client/{services → utils}/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts +0 -0
  74. /package/dist/client/{services → utils}/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts +0 -0
  75. /package/dist/client/{services → utils}/ReadReceiptSync/readReceiptSyncEngine.d.ts +0 -0
  76. /package/dist/client/{services → utils}/ReadReceiptSync/readReceiptSyncEngineOnLoginHandler.d.ts +0 -0
package/dist/index.esm.js CHANGED
@@ -717,7 +717,6 @@ const PAYLOAD2MODEL = {
717
717
  rooms: 'room',
718
718
  events: 'event',
719
719
  discussionCommunities: 'discussionCommunity',
720
- viewers: 'viewer',
721
720
  };
722
721
  /** hidden */
723
722
  const isOutdated = (prevData, nextData) => {
@@ -1448,14 +1447,12 @@ const createEventEmitter = () => {
1448
1447
  const proxyMqttEvents = (mqttClient, emitter) => {
1449
1448
  MQTT_EVENTS.forEach(event => {
1450
1449
  mqttClient === null || mqttClient === void 0 ? void 0 : mqttClient.on(event, (...params) => {
1451
- console.log('global event received => ', event);
1452
1450
  emitter.emit(event, params.length === 1 ? params[0] : params);
1453
1451
  });
1454
1452
  });
1455
1453
  // @ts-ignore
1456
1454
  mqttClient.on('message', (topic, payload) => {
1457
1455
  const message = JSON.parse(payload.toString());
1458
- console.log('message event received => ', message.eventType, message.data);
1459
1456
  emitter.emit(message.eventType, message.data);
1460
1457
  });
1461
1458
  };
@@ -28464,7 +28461,7 @@ const createInvitations = async (bundle) => {
28464
28461
  * @category Invitation API
28465
28462
  * @async
28466
28463
  */
28467
- const acceptInvitation$1 = async (invitationId) => {
28464
+ const acceptInvitation = async (invitationId) => {
28468
28465
  var _a;
28469
28466
  const client = getActiveClient();
28470
28467
  client.log('invitation/acceptInvitation', invitationId);
@@ -28550,7 +28547,7 @@ const invitationLinkedObject = (invitation) => {
28550
28547
  }
28551
28548
  return undefined;
28552
28549
  }, accept: async () => {
28553
- await acceptInvitation$1(invitation._id);
28550
+ await acceptInvitation(invitation._id);
28554
28551
  }, reject: async () => {
28555
28552
  await rejectInvitation(invitation._id);
28556
28553
  } });
@@ -44160,7 +44157,9 @@ const getRecordedUrl = async (roomId) => {
44160
44157
  const removeParticipant = async (roomId, participantUserId) => {
44161
44158
  const client = getActiveClient();
44162
44159
  client.log('room/removeParticipant', { roomId, participantUserId });
44163
- await client.http.delete(`/api/v1/rooms/${roomId}/participants/${participantUserId}`);
44160
+ await client.http.delete(`/api/v1/rooms/${roomId}/participants`, {
44161
+ data: { participantUserId },
44162
+ });
44164
44163
  fireEvent('local.room.participantRemoved', {
44165
44164
  rooms: [{ _id: roomId }],
44166
44165
  users: [{ _id: participantUserId }],
@@ -44316,64 +44315,6 @@ const onRoomCoHostInvited = (callback) => {
44316
44315
  return createEventSubscriber(client, 'room/onRoomCoHostInvited', 'room.didCohostInvite', filter);
44317
44316
  };
44318
44317
 
44319
- const getRoomById = async (roomId) => {
44320
- const client = getActiveClient();
44321
- client.log('room/getRoomById', roomId);
44322
- // Check if room is in tombstone
44323
- isInTombstone('room', roomId);
44324
- let data;
44325
- try {
44326
- const response = await client.http.get(`/api/v1/rooms/${roomId}`);
44327
- data = response.data;
44328
- }
44329
- catch (error) {
44330
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
44331
- pushToTombstone('room', roomId);
44332
- }
44333
- throw error;
44334
- }
44335
- const cachedAt = client.cache && Date.now();
44336
- if (client.cache) {
44337
- ingestInCache(data, { cachedAt });
44338
- }
44339
- return {
44340
- data: data.rooms[0],
44341
- cachedAt,
44342
- };
44343
- };
44344
- getRoomById.locally = (roomId) => {
44345
- const client = getActiveClient();
44346
- client.log('room/getRoomById.locally', roomId);
44347
- // Check if room is in tombstone
44348
- isInTombstone('room', roomId);
44349
- const cachedAt = client.cache && Date.now();
44350
- const roomCache = pullFromCache(['room', 'get', roomId]);
44351
- if (!roomCache)
44352
- return;
44353
- return {
44354
- data: roomCache.data,
44355
- cachedAt,
44356
- };
44357
- };
44358
-
44359
- const getWatchingCount$1 = async (roomId) => {
44360
- const client = getActiveClient();
44361
- client.log('room/getWatchingCount', { roomId });
44362
- const { data } = await client.http.get(`/api/v1/presence/rooms/${roomId}/users/count`);
44363
- pushToCache(['get', 'watchingCount', roomId], data);
44364
- fireEvent('local.room.watchingCountUpdated', data);
44365
- return data;
44366
- };
44367
-
44368
- const getWatchingUsers$1 = async (roomId) => {
44369
- const client = getActiveClient();
44370
- client.log('room/getWatchingUsers', { roomId });
44371
- const { data } = await client.http.get(`/api/v1/presence/rooms/${roomId}/users`);
44372
- pushToCache(['watchingUsers', 'collection', roomId], data.viewers.map(viewer => viewer.userId));
44373
- fireEvent('local.room.watchingUsersFetched', data.viewers);
44374
- return data.viewers;
44375
- };
44376
-
44377
44318
  /**
44378
44319
  * ```js
44379
44320
  * import { onRoomCoHostInviteAccepted } from '@amityco/ts-sdk'
@@ -44391,12 +44332,10 @@ const getWatchingUsers$1 = async (roomId) => {
44391
44332
  */
44392
44333
  const onRoomCoHostInviteAccepted = (callback) => {
44393
44334
  const client = getActiveClient();
44394
- const filter = async (payload) => {
44395
- var _a;
44335
+ const filter = (payload) => {
44396
44336
  const data = prepareMyInvitationsPayload(payload);
44397
- await getRoomById((_a = data.invitations) === null || _a === void 0 ? void 0 : _a[0].targetId);
44398
44337
  ingestInCache(data);
44399
- callback(data.invitations[0]);
44338
+ callback(data.invitations);
44400
44339
  };
44401
44340
  return createEventSubscriber(client, 'room/onRoomCoHostInviteAccepted', 'room.didCohostInviteAccept', filter);
44402
44341
  };
@@ -44616,7 +44555,7 @@ const onRoomParticipantRemoved = (callback) => {
44616
44555
  ingestInCache(payload);
44617
44556
  callback(payload.rooms[0]);
44618
44557
  };
44619
- return createEventSubscriber(client, 'room/onRoomParticipantRemoved', 'room.participantRemoved', filter);
44558
+ return createEventSubscriber(client, 'room/onRoomParticipantRemoved', 'local.room.participantRemoved', filter);
44620
44559
  };
44621
44560
 
44622
44561
  /**
@@ -44643,28 +44582,44 @@ const onRoomLeft = (callback) => {
44643
44582
  return createEventSubscriber(client, 'room/onRoomLeft', 'local.room.left', filter);
44644
44583
  };
44645
44584
 
44646
- /**
44647
- * ```js
44648
- * import { onRoomParticipantRemoved } from '@amityco/ts-sdk'
44649
- * const dispose = onRoomParticipantRemoved(room => {
44650
- * // ...
44651
- * })
44652
- * ```
44653
- *
44654
- * Fired when a participant has been removed from a {@link Amity.Room} locally
44655
- *
44656
- * @param callback The function to call when the event was fired
44657
- * @returns an {@link Amity.Unsubscriber} function to stop listening
44658
- *
44659
- * @category Room Events
44660
- */
44661
- const onRoomParticipantRemovedLocal = (callback) => {
44585
+ const getRoomById = async (roomId) => {
44662
44586
  const client = getActiveClient();
44663
- const filter = (payload) => {
44664
- ingestInCache(payload);
44665
- callback(payload.rooms[0]);
44587
+ client.log('room/getRoomById', roomId);
44588
+ // Check if room is in tombstone
44589
+ isInTombstone('room', roomId);
44590
+ let data;
44591
+ try {
44592
+ const response = await client.http.get(`/api/v1/rooms/${roomId}`);
44593
+ data = response.data;
44594
+ }
44595
+ catch (error) {
44596
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
44597
+ pushToTombstone('room', roomId);
44598
+ }
44599
+ throw error;
44600
+ }
44601
+ const cachedAt = client.cache && Date.now();
44602
+ if (client.cache) {
44603
+ ingestInCache(data, { cachedAt });
44604
+ }
44605
+ return {
44606
+ data: data.rooms[0],
44607
+ cachedAt,
44608
+ };
44609
+ };
44610
+ getRoomById.locally = (roomId) => {
44611
+ const client = getActiveClient();
44612
+ client.log('room/getRoomById.locally', roomId);
44613
+ // Check if room is in tombstone
44614
+ isInTombstone('room', roomId);
44615
+ const cachedAt = client.cache && Date.now();
44616
+ const roomCache = pullFromCache(['room', 'get', roomId]);
44617
+ if (!roomCache)
44618
+ return;
44619
+ return {
44620
+ data: roomCache.data,
44621
+ cachedAt,
44666
44622
  };
44667
- return createEventSubscriber(client, 'room/onRoomParticipantRemoved', 'local.room.participantRemoved', filter);
44668
44623
  };
44669
44624
 
44670
44625
  const getRoom = (roomId, callback) => {
@@ -44676,9 +44631,6 @@ const getRoom = (roomId, callback) => {
44676
44631
  onRoomRecordedAvailable,
44677
44632
  onRoomParticipantJoined,
44678
44633
  onRoomParticipantLeft,
44679
- onRoomParticipantRemoved,
44680
- onRoomParticipantRemovedLocal,
44681
- convertEventPayload(onRoomCoHostInviteAccepted, 'targetId', 'room'),
44682
44634
  ], {
44683
44635
  callbackDataSelector: (data) => {
44684
44636
  if (!data)
@@ -44898,381 +44850,6 @@ const getRooms = (params, callback, config) => {
44898
44850
  };
44899
44851
  /* end_public_function */
44900
44852
 
44901
- /**
44902
- * ```js
44903
- * import { onRoomWaitingReconnect } from '@amityco/ts-sdk'
44904
- * const dispose = onRoomWaitingReconnect(room => {
44905
- * // ...
44906
- * })
44907
- * ```
44908
- *
44909
- * Fired when a {@link Amity.RoomWatchingCount} is waiting for reconnection
44910
- *
44911
- * @param callback The function to call when the event was fired
44912
- * @returns an {@link Amity.Unsubscriber} function to stop listening
44913
- *
44914
- * @category Room Events
44915
- */
44916
- const onRoomWatchingCountUpdated = (callback) => {
44917
- const client = getActiveClient();
44918
- const filter = (payload) => {
44919
- callback(payload);
44920
- };
44921
- return createEventSubscriber(client, 'room/onRoomWatchingCountUpdated', 'local.room.watchingCountUpdated', filter);
44922
- };
44923
-
44924
- /**
44925
- * ```js
44926
- * import RoomRepository from '@amityco/ts-sdk'
44927
- * const unsubscribe = RoomRepository.getWatchingCount('roomId', ({count}) => {
44928
- * console.log('Current watching count:', count);
44929
- * });
44930
- * ```
44931
- *
44932
- * Observe the watching count for a room with real-time updates
44933
- *
44934
- * @param roomId The ID of the room to observe watching count for
44935
- * @param callback The function to call when watching count changes
44936
- * @returns An {@link Amity.Unsubscriber} function to stop observing
44937
- *
44938
- * @category Room Observable
44939
- */
44940
- const getWatchingCount = (roomId, callback) => {
44941
- const { _id: userId } = getCurrentUser();
44942
- if (!userId)
44943
- throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
44944
- const { log, cache } = getActiveClient();
44945
- if (!cache) {
44946
- console.log('For using Live Object feature you need to enable Cache!');
44947
- }
44948
- const timestamp = Date.now();
44949
- log(`liveWatchingCount(tmpid: ${timestamp}) > listen`);
44950
- const disposers = [];
44951
- let model;
44952
- const dispatcher = (data) => {
44953
- callback(data !== null && data !== void 0 ? data : { count: 0, referenceTimestamp: undefined });
44954
- };
44955
- const realtimeRouter = (_) => {
44956
- var _a;
44957
- const data = (_a = pullFromCache(['get', 'watchingCount', roomId])) === null || _a === void 0 ? void 0 : _a.data;
44958
- if (isEqual(model, data))
44959
- return;
44960
- dispatcher(data);
44961
- };
44962
- const onFetch = () => {
44963
- var _a;
44964
- const data = (_a = pullFromCache(['get', 'watchingCount', roomId])) === null || _a === void 0 ? void 0 : _a.data;
44965
- dispatcher(data);
44966
- };
44967
- disposers.push(onRoomWatchingCountUpdated(realtimeRouter));
44968
- onFetch();
44969
- return () => {
44970
- disposers.forEach(fn => fn());
44971
- };
44972
- };
44973
-
44974
- /**
44975
- * ```js
44976
- * import { onRoomWatchingUsersFetched } from '@amityco/ts-sdk'
44977
- * const dispose = onRoomWatchingUsersFetched(users => {
44978
- * console.log('Watching users fetched:', users);
44979
- * })
44980
- * ```
44981
- *
44982
- * Fired when {@link Amity.User[]} watching users data is fetched
44983
- *
44984
- * @param callback The function to call when the event was fired
44985
- * @returns an {@link Amity.Unsubscriber} function to stop listening
44986
- *
44987
- * @category Room Events
44988
- */
44989
- const onRoomWatchingUsersFetched = (callback) => {
44990
- const client = getActiveClient();
44991
- const filter = (payload) => {
44992
- callback(payload);
44993
- };
44994
- return createEventSubscriber(client, 'room/onRoomWatchingUsersFetched', 'local.room.watchingUsersFetched', filter);
44995
- };
44996
-
44997
- /**
44998
- * ```js
44999
- * import RoomRepository from '@amityco/ts-sdk'
45000
- * const unsubscribe = RoomRepository.getWatchingUsers('roomId', ({count}) => {
45001
- * console.log('Current watching count:', count);
45002
- * });
45003
- * ```
45004
- *
45005
- * Observe the watching count for a room with real-time updates
45006
- *
45007
- * @param roomId The ID of the room to observe watching count for
45008
- * @param callback The function to call when watching count changes
45009
- * @returns An {@link Amity.Unsubscriber} function to stop observing
45010
- *
45011
- * @category Room Observable
45012
- */
45013
- const getWatchingUsers = (roomId, callback) => {
45014
- const { _id: userId } = getCurrentUser();
45015
- if (!userId)
45016
- throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
45017
- const { log, cache } = getActiveClient();
45018
- if (!cache) {
45019
- console.log('For using Live Object feature you need to enable Cache!');
45020
- }
45021
- const timestamp = Date.now();
45022
- log(`liveWatchingCount(tmpid: ${timestamp}) > listen`);
45023
- const disposers = [];
45024
- let model;
45025
- const dispatcher = (data) => {
45026
- var _a;
45027
- const callbackData = (_a = data === null || data === void 0 ? void 0 : data.map((userId) => { var _a; return (_a = pullFromCache(['user', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data; }).filter(isNonNullable).map(LinkedObject.user)) !== null && _a !== void 0 ? _a : [];
45028
- callback(callbackData);
45029
- };
45030
- const realtimeRouter = (_) => {
45031
- var _a;
45032
- const data = (_a = pullFromCache([
45033
- 'watchingUsers',
45034
- 'collection',
45035
- roomId,
45036
- ])) === null || _a === void 0 ? void 0 : _a.data;
45037
- if (isEqual(model, data))
45038
- return;
45039
- dispatcher(data);
45040
- };
45041
- const onFetch = () => {
45042
- var _a;
45043
- const data = (_a = pullFromCache([
45044
- 'watchingUsers',
45045
- 'collection',
45046
- roomId,
45047
- ])) === null || _a === void 0 ? void 0 : _a.data;
45048
- dispatcher(data);
45049
- };
45050
- disposers.push(onRoomWatchingUsersFetched(realtimeRouter));
45051
- onFetch();
45052
- return () => {
45053
- disposers.forEach(fn => fn());
45054
- };
45055
- };
45056
-
45057
- const getPresenceSetting = async () => {
45058
- const client = getActiveClient();
45059
- client.log('presence/getPresenceSetting');
45060
- const { data } = await client.http.get('/api/v1/presence/settings');
45061
- pushToCache(['get', 'presenceSetting'], data);
45062
- return data;
45063
- };
45064
-
45065
- class WatchingSyncEngine {
45066
- constructor(roomId) {
45067
- this.roomId = roomId;
45068
- this.config = {
45069
- heartbeatInterval: 1 * MINUTE,
45070
- presenceSyncInterval: 30 * SECOND$1,
45071
- };
45072
- // Initialize config asynchronously - don't await in constructor
45073
- this.initializeConfig().catch(error => {
45074
- console.error('Failed to initialize WatchingSyncEngine config in constructor:', error);
45075
- });
45076
- }
45077
- async initializeConfig() {
45078
- try {
45079
- // Get presence settings from API with retry logic
45080
- const presenceSettings = await WatchingSyncEngine.getPresenceSettingWithRetry();
45081
- if (presenceSettings) {
45082
- // Set intervals from network settings (convert from minutes to milliseconds)
45083
- this.config = {
45084
- heartbeatInterval: (presenceSettings.network.heartbeatInterval || 5) * 60 * 1000,
45085
- presenceSyncInterval: (presenceSettings.network.presenceSyncInterval || 1) * 60 * 1000,
45086
- };
45087
- }
45088
- else {
45089
- // Use default intervals if all retries failed
45090
- this.config.heartbeatInterval = 5 * 60 * 1000; // 5 minutes
45091
- this.config.presenceSyncInterval = 1 * 60 * 1000; // 1 minute
45092
- }
45093
- }
45094
- catch (error) {
45095
- console.error('Failed to initialize WatchingSyncEngine config:', error);
45096
- // Use default intervals if settings fetch fails
45097
- this.config.heartbeatInterval = 5 * 60 * 1000; // 5 minutes
45098
- this.config.presenceSyncInterval = 1 * 60 * 1000; // 1 minute
45099
- }
45100
- }
45101
- static async getPresenceSettingWithRetry(maxRetries = 5) {
45102
- for (let attempt = 0; attempt < maxRetries; attempt += 1) {
45103
- try {
45104
- // eslint-disable-next-line no-await-in-loop
45105
- const presenceSettings = await getPresenceSetting();
45106
- return presenceSettings;
45107
- }
45108
- catch (error) {
45109
- if (attempt >= maxRetries - 1) {
45110
- console.error(`Failed to get presence setting after ${maxRetries} attempts:`, error);
45111
- return null;
45112
- }
45113
- // Calculate delay: 20 seconds + random jitter (0-5 seconds)
45114
- const jitter = Math.random() * 5000; // 0-5 seconds in milliseconds
45115
- const delay = 20000 + jitter; // 20 seconds + jitter
45116
- console.warn(`Failed to get presence setting (attempt ${attempt + 1}/${maxRetries}), retrying in ${Math.round(delay / 1000)}s:`, error);
45117
- // Wait before retry
45118
- // eslint-disable-next-line no-await-in-loop
45119
- await new Promise(resolve => {
45120
- setTimeout(resolve, delay);
45121
- });
45122
- }
45123
- }
45124
- return null;
45125
- }
45126
- startWatching() {
45127
- if (!this.roomId) {
45128
- console.error('WatchingSyncEngine: roomId is required');
45129
- return;
45130
- }
45131
- // Stop existing timer if any
45132
- this.stopWatching();
45133
- // Send immediate heartbeat when starting
45134
- this.sendHeartbeat();
45135
- // Start heartbeat timer
45136
- this.heartbeatTimer = setInterval(() => {
45137
- this.sendHeartbeat();
45138
- }, this.config.heartbeatInterval);
45139
- }
45140
- async sendHeartbeat() {
45141
- if (!this.roomId)
45142
- return;
45143
- try {
45144
- const client = getActiveClient();
45145
- await client.http.post(`/api/v1/presence/rooms/${this.roomId}/heartbeat`);
45146
- }
45147
- catch (error) {
45148
- console.error('Heartbeat failed:', error);
45149
- }
45150
- }
45151
- stopWatching() {
45152
- if (this.heartbeatTimer) {
45153
- clearInterval(this.heartbeatTimer);
45154
- this.heartbeatTimer = undefined;
45155
- }
45156
- }
45157
- syncWatchingUsers() {
45158
- if (!this.roomId) {
45159
- console.error('WatchingSyncEngine: roomId is required');
45160
- return;
45161
- }
45162
- // Stop existing timer if any
45163
- this.stopSyncWatchingUsers();
45164
- // Fetch watching data immediately when starting
45165
- this.fetchWatchingData();
45166
- // Start watching users sync timer
45167
- this.watchingUsersTimer = setInterval(() => {
45168
- this.fetchWatchingData();
45169
- }, this.config.presenceSyncInterval);
45170
- }
45171
- async fetchWatchingData() {
45172
- if (!this.roomId)
45173
- return;
45174
- try {
45175
- // Call both APIs to sync watching data
45176
- const [count, users] = await Promise.all([
45177
- getWatchingCount$1(this.roomId),
45178
- getWatchingUsers$1(this.roomId),
45179
- ]);
45180
- // Data is automatically cached by the individual API calls
45181
- const client = getActiveClient();
45182
- client.log('room/watchingSync', { roomId: this.roomId, count, usersCount: users.length });
45183
- }
45184
- catch (error) {
45185
- console.error('Watching users sync failed:', error);
45186
- }
45187
- }
45188
- stopSyncWatchingUsers() {
45189
- if (this.watchingUsersTimer) {
45190
- clearInterval(this.watchingUsersTimer);
45191
- this.watchingUsersTimer = undefined;
45192
- }
45193
- }
45194
- /**
45195
- * Cleanup method to stop all timers and release resources
45196
- * Call this when the engine instance is no longer needed
45197
- */
45198
- destroy() {
45199
- // Stop all active timers
45200
- this.stopWatching();
45201
- this.stopSyncWatchingUsers();
45202
- }
45203
- // Session Management
45204
- onSessionDestroyed() {
45205
- // Stop all timers when session is destroyed and cleanup
45206
- this.destroy();
45207
- }
45208
- onTokenExpired() {
45209
- // Stop timers when token expires
45210
- this.stopWatching();
45211
- this.stopSyncWatchingUsers();
45212
- }
45213
- }
45214
-
45215
- // Global map to store instances
45216
- const engineInstances = new Map();
45217
- /**
45218
- * Get or create a WatchingSyncEngine instance for a room
45219
- *
45220
- * @param roomId The room ID to get/create engine for
45221
- * @returns WatchingSyncEngine instance for the room
45222
- */
45223
- const getWatchingSyncEngine = (roomId) => {
45224
- let engine = engineInstances.get(roomId);
45225
- if (!engine) {
45226
- engine = new WatchingSyncEngine(roomId);
45227
- engineInstances.set(roomId, engine);
45228
- }
45229
- return engine;
45230
- };
45231
- /**
45232
- * Destroy and remove engine instance for a room
45233
- *
45234
- * @param roomId The room ID to destroy engine for
45235
- */
45236
- const destroyWatchingSyncEngine = (roomId) => {
45237
- const engine = engineInstances.get(roomId);
45238
- if (engine) {
45239
- engine.destroy();
45240
- engineInstances.delete(roomId);
45241
- }
45242
- };
45243
- /**
45244
- * Get all active room IDs with engines
45245
- */
45246
- const getActiveWatchingRooms = () => {
45247
- return Array.from(engineInstances.keys());
45248
- };
45249
- /**
45250
- * Check if a room has an active engine
45251
- */
45252
- const hasWatchingSyncEngine = (roomId) => {
45253
- return engineInstances.has(roomId);
45254
- };
45255
- /**
45256
- * Destroy all engines
45257
- */
45258
- const destroyAllWatchingSyncEngines = () => {
45259
- engineInstances.forEach(engine => {
45260
- engine.destroy();
45261
- });
45262
- engineInstances.clear();
45263
- };
45264
- /**
45265
- * Session management functions
45266
- */
45267
- const onWatchingSyncSessionDestroyed = () => {
45268
- destroyAllWatchingSyncEngines();
45269
- };
45270
- const onWatchingSyncTokenExpired = () => {
45271
- engineInstances.forEach(engine => {
45272
- engine.onTokenExpired();
45273
- });
45274
- };
45275
-
45276
44853
  var index$8 = /*#__PURE__*/Object.freeze({
45277
44854
  __proto__: null,
45278
44855
  createRoom: createRoom,
@@ -45300,16 +44877,7 @@ var index$8 = /*#__PURE__*/Object.freeze({
45300
44877
  onRoomParticipantRemoved: onRoomParticipantRemoved,
45301
44878
  onRoomLeft: onRoomLeft,
45302
44879
  getRoom: getRoom,
45303
- getRooms: getRooms,
45304
- getWatchingCount: getWatchingCount,
45305
- getWatchingUsers: getWatchingUsers,
45306
- getWatchingSyncEngine: getWatchingSyncEngine,
45307
- destroyWatchingSyncEngine: destroyWatchingSyncEngine,
45308
- getActiveWatchingRooms: getActiveWatchingRooms,
45309
- hasWatchingSyncEngine: hasWatchingSyncEngine,
45310
- destroyAllWatchingSyncEngines: destroyAllWatchingSyncEngines,
45311
- onWatchingSyncSessionDestroyed: onWatchingSyncSessionDestroyed,
45312
- onWatchingSyncTokenExpired: onWatchingSyncTokenExpired
44880
+ getRooms: getRooms
45313
44881
  });
45314
44882
 
45315
44883
  /* begin_public_function
@@ -47639,28 +47207,6 @@ const cancelInvitation = async (invitationId) => {
47639
47207
  };
47640
47208
  /* end_public_function */
47641
47209
 
47642
- /* begin_public_function
47643
- id: invitation.accept
47644
- */
47645
- /**
47646
- * ```js
47647
- * import { acceptInvitation } from '@amityco/ts-sdk'
47648
- * const isAccepted = await acceptInvitation(invitationId)
47649
- * ```
47650
- *
47651
- * Accepts a {@link Amity.Invitation} object
47652
- *
47653
- * @param invitationId the {@link Amity.Invitation} to accept
47654
- * @returns A success boolean if the {@link Amity.Invitation} was accepted
47655
- *
47656
- * @category Invitation API
47657
- * @async
47658
- */
47659
- const acceptInvitation = async (invitationId) => {
47660
- return acceptInvitation$1(invitationId);
47661
- };
47662
- /* end_public_function */
47663
-
47664
47210
  class MyInvitationsPaginationController extends PaginationController {
47665
47211
  async getRequest(queryParams, token) {
47666
47212
  const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
@@ -47899,7 +47445,7 @@ const getInvitations = (params, callback) => {
47899
47445
  callback(data.map(LinkedObject.invitation));
47900
47446
  };
47901
47447
  const realtimeRouter = (data) => {
47902
- const invitations = (Array.isArray(data) ? data : [data]).filter(({ targetId, targetType }) => targetId === params.targetId && targetType === params.targetType);
47448
+ const invitations = data.filter(({ targetId, targetType }) => targetId === params.targetId && targetType === params.targetType);
47903
47449
  dispatcher(invitations);
47904
47450
  };
47905
47451
  // Only subscribe to room co-host events for now (since that's what we have implemented)
@@ -47919,7 +47465,6 @@ const getInvitations = (params, callback) => {
47919
47465
  var index$2 = /*#__PURE__*/Object.freeze({
47920
47466
  __proto__: null,
47921
47467
  cancelInvitation: cancelInvitation,
47922
- acceptInvitation: acceptInvitation,
47923
47468
  onLocalInvitationCreated: onLocalInvitationCreated,
47924
47469
  onLocalInvitationUpdated: onLocalInvitationUpdated,
47925
47470
  onLocalInvitationCanceled: onLocalInvitationCanceled,