@amityco/ts-sdk 7.11.1-3c94a340.0 → 7.11.1-4c3f6231.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 (176) hide show
  1. package/dist/@types/core/events.d.ts +13 -32
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +3 -2
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +4 -15
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/core/permissions.d.ts +1 -5
  8. package/dist/@types/core/permissions.d.ts.map +1 -1
  9. package/dist/@types/core/transport.d.ts +0 -3
  10. package/dist/@types/core/transport.d.ts.map +1 -1
  11. package/dist/@types/domains/channel.d.ts +1 -0
  12. package/dist/@types/domains/channel.d.ts.map +1 -1
  13. package/dist/@types/domains/community.d.ts +1 -8
  14. package/dist/@types/domains/community.d.ts.map +1 -1
  15. package/dist/@types/domains/content.d.ts +4 -1
  16. package/dist/@types/domains/content.d.ts.map +1 -1
  17. package/dist/@types/domains/feed.d.ts +2 -1
  18. package/dist/@types/domains/feed.d.ts.map +1 -1
  19. package/dist/@types/domains/partials.d.ts +2 -2
  20. package/dist/@types/domains/partials.d.ts.map +1 -1
  21. package/dist/@types/domains/post.d.ts +2 -0
  22. package/dist/@types/domains/post.d.ts.map +1 -1
  23. package/dist/@types/domains/room.d.ts +77 -0
  24. package/dist/@types/domains/room.d.ts.map +1 -0
  25. package/dist/@types/index.d.ts +2 -1
  26. package/dist/@types/index.d.ts.map +1 -1
  27. package/dist/channelRepository/api/createChannel.d.ts +1 -0
  28. package/dist/channelRepository/api/createChannel.d.ts.map +1 -1
  29. package/dist/core/events.d.ts +3 -3
  30. package/dist/core/events.d.ts.map +1 -1
  31. package/dist/core/model/index.d.ts.map +1 -1
  32. package/dist/core/subscription.d.ts +2 -0
  33. package/dist/core/subscription.d.ts.map +1 -1
  34. package/dist/index.cjs.js +2822 -2647
  35. package/dist/index.d.ts +1 -1
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.esm.js +889 -716
  38. package/dist/index.umd.js +3 -3
  39. package/dist/liveReactionRepository/api/createReaction.d.ts +2 -2
  40. package/dist/liveReactionRepository/api/createReaction.d.ts.map +1 -1
  41. package/dist/liveReactionRepository/internalApi/createLiveReaction.d.ts +2 -2
  42. package/dist/liveReactionRepository/internalApi/createLiveReaction.d.ts.map +1 -1
  43. package/dist/liveReactionRepository/service/ReactionSyncEngine.d.ts +1 -1
  44. package/dist/liveReactionRepository/service/ReactionSyncEngine.d.ts.map +1 -1
  45. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +2 -1
  46. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
  47. package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
  48. package/dist/roomRepository/api/createRoom.d.ts +24 -0
  49. package/dist/roomRepository/api/createRoom.d.ts.map +1 -0
  50. package/dist/roomRepository/api/deleteRoom.d.ts +16 -0
  51. package/dist/roomRepository/api/deleteRoom.d.ts.map +1 -0
  52. package/dist/roomRepository/api/getBroadcasterData.d.ts +16 -0
  53. package/dist/roomRepository/api/getBroadcasterData.d.ts.map +1 -0
  54. package/dist/roomRepository/api/getRecordedUrl.d.ts +19 -0
  55. package/dist/roomRepository/api/getRecordedUrl.d.ts.map +1 -0
  56. package/dist/roomRepository/api/index.d.ts +7 -0
  57. package/dist/roomRepository/api/index.d.ts.map +1 -0
  58. package/dist/roomRepository/api/stopRoom.d.ts +16 -0
  59. package/dist/roomRepository/api/stopRoom.d.ts.map +1 -0
  60. package/dist/roomRepository/api/updateRoom.d.ts +24 -0
  61. package/dist/roomRepository/api/updateRoom.d.ts.map +1 -0
  62. package/dist/roomRepository/events/index.d.ts +12 -0
  63. package/dist/roomRepository/events/index.d.ts.map +1 -0
  64. package/dist/roomRepository/events/onRoomCreated.d.ts +17 -0
  65. package/dist/roomRepository/events/onRoomCreated.d.ts.map +1 -0
  66. package/dist/roomRepository/events/onRoomDeleted.d.ts +17 -0
  67. package/dist/roomRepository/events/onRoomDeleted.d.ts.map +1 -0
  68. package/dist/roomRepository/events/onRoomEndBroadcasting.d.ts +17 -0
  69. package/dist/roomRepository/events/onRoomEndBroadcasting.d.ts.map +1 -0
  70. package/dist/roomRepository/events/onRoomParticipantInviting.d.ts +17 -0
  71. package/dist/roomRepository/events/onRoomParticipantInviting.d.ts.map +1 -0
  72. package/dist/roomRepository/events/onRoomParticipantJoined.d.ts +17 -0
  73. package/dist/roomRepository/events/onRoomParticipantJoined.d.ts.map +1 -0
  74. package/dist/roomRepository/events/onRoomParticipantLeft.d.ts +17 -0
  75. package/dist/roomRepository/events/onRoomParticipantLeft.d.ts.map +1 -0
  76. package/dist/roomRepository/events/onRoomRecordedAvailable.d.ts +17 -0
  77. package/dist/roomRepository/events/onRoomRecordedAvailable.d.ts.map +1 -0
  78. package/dist/roomRepository/events/onRoomStartBroadcasting.d.ts +17 -0
  79. package/dist/roomRepository/events/onRoomStartBroadcasting.d.ts.map +1 -0
  80. package/dist/roomRepository/events/onRoomStopped.d.ts +17 -0
  81. package/dist/roomRepository/events/onRoomStopped.d.ts.map +1 -0
  82. package/dist/roomRepository/events/onRoomUpdated.d.ts +17 -0
  83. package/dist/roomRepository/events/onRoomUpdated.d.ts.map +1 -0
  84. package/dist/roomRepository/events/onRoomWaitingReconnect.d.ts +17 -0
  85. package/dist/roomRepository/events/onRoomWaitingReconnect.d.ts.map +1 -0
  86. package/dist/roomRepository/index.d.ts.map +1 -0
  87. package/dist/roomRepository/internalApi/getLiveChat.d.ts +16 -0
  88. package/dist/roomRepository/internalApi/getLiveChat.d.ts.map +1 -0
  89. package/dist/roomRepository/internalApi/getRoomById.d.ts +5 -0
  90. package/dist/roomRepository/internalApi/getRoomById.d.ts.map +1 -0
  91. package/dist/roomRepository/internalApi/index.d.ts +3 -0
  92. package/dist/roomRepository/internalApi/index.d.ts.map +1 -0
  93. package/dist/roomRepository/observers/enums.d.ts +10 -0
  94. package/dist/roomRepository/observers/enums.d.ts.map +1 -0
  95. package/dist/roomRepository/observers/getRoom.d.ts +2 -0
  96. package/dist/roomRepository/observers/getRoom.d.ts.map +1 -0
  97. package/dist/roomRepository/observers/getRooms/RoomLiveCollectionController.d.ts +14 -0
  98. package/dist/roomRepository/observers/getRooms/RoomLiveCollectionController.d.ts.map +1 -0
  99. package/dist/roomRepository/observers/getRooms/RoomPaginationController.d.ts +5 -0
  100. package/dist/roomRepository/observers/getRooms/RoomPaginationController.d.ts.map +1 -0
  101. package/dist/roomRepository/observers/getRooms/RoomQueryStreamController.d.ts +15 -0
  102. package/dist/roomRepository/observers/getRooms/RoomQueryStreamController.d.ts.map +1 -0
  103. package/dist/roomRepository/observers/getRooms.d.ts +29 -0
  104. package/dist/roomRepository/observers/getRooms.d.ts.map +1 -0
  105. package/dist/roomRepository/observers/index.d.ts +3 -0
  106. package/dist/roomRepository/observers/index.d.ts.map +1 -0
  107. package/dist/roomRepository/observers/utils.d.ts +6 -0
  108. package/dist/roomRepository/observers/utils.d.ts.map +1 -0
  109. package/dist/utils/linkedObject/index.d.ts +1 -1
  110. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  111. package/dist/utils/linkedObject/roomLinkedObject.d.ts +2 -0
  112. package/dist/utils/linkedObject/roomLinkedObject.d.ts.map +1 -0
  113. package/dist/utils/postTypePredicate.d.ts +1 -0
  114. package/dist/utils/postTypePredicate.d.ts.map +1 -1
  115. package/dist/utils/tests/dummy/comment.d.ts +1 -1
  116. package/package.json +1 -1
  117. package/dist/@types/domains/event.d.ts +0 -81
  118. package/dist/@types/domains/event.d.ts.map +0 -1
  119. package/dist/eventRepository/api/createEvent.d.ts +0 -16
  120. package/dist/eventRepository/api/createEvent.d.ts.map +0 -1
  121. package/dist/eventRepository/api/deleteEvent.d.ts +0 -15
  122. package/dist/eventRepository/api/deleteEvent.d.ts.map +0 -1
  123. package/dist/eventRepository/api/index.d.ts +0 -4
  124. package/dist/eventRepository/api/index.d.ts.map +0 -1
  125. package/dist/eventRepository/api/updateEvent.d.ts +0 -17
  126. package/dist/eventRepository/api/updateEvent.d.ts.map +0 -1
  127. package/dist/eventRepository/events/enums.d.ts +0 -6
  128. package/dist/eventRepository/events/enums.d.ts.map +0 -1
  129. package/dist/eventRepository/events/index.d.ts +0 -7
  130. package/dist/eventRepository/events/index.d.ts.map +0 -1
  131. package/dist/eventRepository/events/onEventCreated.d.ts +0 -17
  132. package/dist/eventRepository/events/onEventCreated.d.ts.map +0 -1
  133. package/dist/eventRepository/events/onEventDeleted.d.ts +0 -17
  134. package/dist/eventRepository/events/onEventDeleted.d.ts.map +0 -1
  135. package/dist/eventRepository/events/onEventUpdated.d.ts +0 -17
  136. package/dist/eventRepository/events/onEventUpdated.d.ts.map +0 -1
  137. package/dist/eventRepository/events/onLocalEventCreated.d.ts +0 -17
  138. package/dist/eventRepository/events/onLocalEventCreated.d.ts.map +0 -1
  139. package/dist/eventRepository/events/onLocalEventDeleted.d.ts +0 -17
  140. package/dist/eventRepository/events/onLocalEventDeleted.d.ts.map +0 -1
  141. package/dist/eventRepository/events/onLocalEventUpdated.d.ts +0 -17
  142. package/dist/eventRepository/events/onLocalEventUpdated.d.ts.map +0 -1
  143. package/dist/eventRepository/index.d.ts.map +0 -1
  144. package/dist/eventRepository/internalApi/getEvent.d.ts +0 -32
  145. package/dist/eventRepository/internalApi/getEvent.d.ts.map +0 -1
  146. package/dist/eventRepository/internalApi/index.d.ts +0 -2
  147. package/dist/eventRepository/internalApi/index.d.ts.map +0 -1
  148. package/dist/eventRepository/observers/getEvent.d.ts +0 -21
  149. package/dist/eventRepository/observers/getEvent.d.ts.map +0 -1
  150. package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts +0 -13
  151. package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts.map +0 -1
  152. package/dist/eventRepository/observers/getEvents/PaginationController.d.ts +0 -5
  153. package/dist/eventRepository/observers/getEvents/PaginationController.d.ts.map +0 -1
  154. package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts +0 -15
  155. package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts.map +0 -1
  156. package/dist/eventRepository/observers/getEvents.d.ts +0 -12
  157. package/dist/eventRepository/observers/getEvents.d.ts.map +0 -1
  158. package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts +0 -13
  159. package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts.map +0 -1
  160. package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts +0 -5
  161. package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts.map +0 -1
  162. package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts +0 -15
  163. package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts.map +0 -1
  164. package/dist/eventRepository/observers/getMyEvents.d.ts +0 -12
  165. package/dist/eventRepository/observers/getMyEvents.d.ts.map +0 -1
  166. package/dist/eventRepository/observers/index.d.ts +0 -4
  167. package/dist/eventRepository/observers/index.d.ts.map +0 -1
  168. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +0 -2
  169. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +0 -1
  170. package/dist/eventRepository/utils/index.d.ts +0 -3
  171. package/dist/eventRepository/utils/index.d.ts.map +0 -1
  172. package/dist/eventRepository/utils/prepareEventPayload.d.ts +0 -2
  173. package/dist/eventRepository/utils/prepareEventPayload.d.ts.map +0 -1
  174. package/dist/utils/linkedObject/eventLinkObject.d.ts +0 -2
  175. package/dist/utils/linkedObject/eventLinkObject.d.ts.map +0 -1
  176. /package/dist/{eventRepository → roomRepository}/index.d.ts +0 -0
package/dist/index.esm.js CHANGED
@@ -112,6 +112,7 @@ const PostContentType = Object.freeze({
112
112
  POLL: 'poll',
113
113
  CLIP: 'clip',
114
114
  AUDIO: 'audio',
115
+ ROOM: 'room',
115
116
  });
116
117
  const PostStructureType = Object.freeze({
117
118
  TEXT: 'text',
@@ -163,6 +164,7 @@ var FeedDataTypeEnum;
163
164
  FeedDataTypeEnum["LiveStream"] = "liveStream";
164
165
  FeedDataTypeEnum["Clip"] = "clip";
165
166
  FeedDataTypeEnum["Poll"] = "poll";
167
+ FeedDataTypeEnum["Room"] = "room";
166
168
  })(FeedDataTypeEnum || (FeedDataTypeEnum = {}));
167
169
  var FeedSortByEnum;
168
170
  (function (FeedSortByEnum) {
@@ -177,30 +179,6 @@ var FeedSourceEnum;
177
179
  FeedSourceEnum["User"] = "user";
178
180
  })(FeedSourceEnum || (FeedSourceEnum = {}));
179
181
 
180
- var AmityEventType;
181
- (function (AmityEventType) {
182
- AmityEventType["Virtual"] = "virtual";
183
- AmityEventType["InPerson"] = "in_person";
184
- })(AmityEventType || (AmityEventType = {}));
185
- var AmityEventOriginType;
186
- (function (AmityEventOriginType) {
187
- AmityEventOriginType["Community"] = "community";
188
- AmityEventOriginType["User"] = "user";
189
- })(AmityEventOriginType || (AmityEventOriginType = {}));
190
- var AmityEventStatus;
191
- (function (AmityEventStatus) {
192
- AmityEventStatus["Scheduled"] = "scheduled";
193
- AmityEventStatus["Live"] = "live";
194
- AmityEventStatus["Ended"] = "ended";
195
- AmityEventStatus["Cancelled"] = "cancelled";
196
- })(AmityEventStatus || (AmityEventStatus = {}));
197
- var AmityEventResponseStatus;
198
- (function (AmityEventResponseStatus) {
199
- AmityEventResponseStatus["Going"] = "going";
200
- AmityEventResponseStatus["Interested"] = "interested";
201
- AmityEventResponseStatus["NotGoing"] = "not_going";
202
- })(AmityEventResponseStatus || (AmityEventResponseStatus = {}));
203
-
204
182
  function getVersion() {
205
183
  try {
206
184
  // the string ''v7.11.0-esm'' should be replaced by actual value by @rollup/plugin-replace
@@ -649,7 +627,7 @@ const idResolvers = {
649
627
  notificationTraySeen: ({ userId }) => userId,
650
628
  invitation: ({ _id }) => _id,
651
629
  joinRequest: ({ joinRequestId }) => joinRequestId,
652
- event: ({ eventId }) => eventId,
630
+ room: ({ roomId }) => roomId,
653
631
  };
654
632
  /**
655
633
  * Retrieve the id resolver matching a domain name
@@ -705,8 +683,7 @@ const PAYLOAD2MODEL = {
705
683
  notificationTrayItems: 'notificationTrayItem',
706
684
  invitations: 'invitation',
707
685
  joinRequests: 'joinRequest',
708
- events: 'event',
709
- discussionCommunities: 'community',
686
+ rooms: 'room',
710
687
  };
711
688
  /** hidden */
712
689
  const isOutdated = (prevData, nextData) => {
@@ -1506,6 +1483,37 @@ async function modifyMqttConnection() {
1506
1483
  }
1507
1484
  }
1508
1485
 
1486
+ const userLinkedObject = (user) => {
1487
+ return Object.assign(Object.assign({}, user), { get avatar() {
1488
+ var _a;
1489
+ if (!user.avatarFileId)
1490
+ return undefined;
1491
+ const avatar = (_a = pullFromCache([
1492
+ 'file',
1493
+ 'get',
1494
+ `${user.avatarFileId}`,
1495
+ ])) === null || _a === void 0 ? void 0 : _a.data;
1496
+ return avatar;
1497
+ } });
1498
+ };
1499
+
1500
+ /* begin_public_function
1501
+ id: client.get_current_user
1502
+ */
1503
+ const getCurrentUser = () => {
1504
+ var _a;
1505
+ const client = getActiveClient();
1506
+ if (!client) {
1507
+ throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
1508
+ }
1509
+ const cache = (_a = pullFromCache(['user', 'get', client.userId])) === null || _a === void 0 ? void 0 : _a.data;
1510
+ if (!cache) {
1511
+ throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
1512
+ }
1513
+ return userLinkedObject(cache);
1514
+ };
1515
+ /* end_public_function */
1516
+
1509
1517
  var SubscriptionLevels;
1510
1518
  (function (SubscriptionLevels) {
1511
1519
  SubscriptionLevels["COMMUNITY"] = "community";
@@ -1611,6 +1619,14 @@ const getLiveStreamTopic = () => {
1611
1619
  const getLiveReactionTopic = (post) => {
1612
1620
  return `${post.path}/liveReaction`;
1613
1621
  };
1622
+ const getRoomWatcherTopic = (room) => {
1623
+ const user = getCurrentUser();
1624
+ return `${getNetworkId(user)}/room/${room._id}`;
1625
+ };
1626
+ const getRoomStreamerTopic = (room) => {
1627
+ const user = getCurrentUser();
1628
+ return `${getNetworkId(user)}/room/${room.roomId}/streamer`;
1629
+ };
1614
1630
  function subscribeTopic(topic, callback) {
1615
1631
  const { mqtt } = getActiveClient();
1616
1632
  if (!mqtt)
@@ -21037,20 +21053,6 @@ const getChannelMessagePreview = (channelId) => {
21037
21053
  return ((_b = (_a = pullFromCache(['messagePreviewChannel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : null);
21038
21054
  };
21039
21055
 
21040
- const userLinkedObject = (user) => {
21041
- return Object.assign(Object.assign({}, user), { get avatar() {
21042
- var _a;
21043
- if (!user.avatarFileId)
21044
- return undefined;
21045
- const avatar = (_a = pullFromCache([
21046
- 'file',
21047
- 'get',
21048
- `${user.avatarFileId}`,
21049
- ])) === null || _a === void 0 ? void 0 : _a.data;
21050
- return avatar;
21051
- } });
21052
- };
21053
-
21054
21056
  const getChannelMessagePreviewWithUser = (channel) => {
21055
21057
  var _a;
21056
21058
  const messagePreview = channel.messagePreviewId
@@ -24566,11 +24568,11 @@ var objectResolverEngineOnLoginHandler = () => {
24566
24568
  * @category Live Reaction API
24567
24569
  * @async
24568
24570
  */
24569
- const createLiveReaction = async ({ reactions, liveStreamId, }) => {
24571
+ const createLiveReaction = async ({ reactions, roomId, }) => {
24570
24572
  const client = getActiveClient();
24571
24573
  client.log('live_reaction/addReaction', reactions);
24572
24574
  const { data } = await client.http.post(`/api/v1/reactions/live`, {
24573
- liveStreamId,
24575
+ roomId,
24574
24576
  reactions,
24575
24577
  });
24576
24578
  return data;
@@ -24628,19 +24630,19 @@ class LiveReactionSyncEngine {
24628
24630
  // Clear buffer
24629
24631
  this.clearBuffer();
24630
24632
  const payloads = reactions.reduce((prev, curr) => {
24631
- const { streamId } = curr, rest = __rest(curr, ["streamId"]);
24632
- if (!prev[streamId]) {
24633
+ const { roomId } = curr, rest = __rest(curr, ["roomId"]);
24634
+ if (!prev[roomId]) {
24633
24635
  // eslint-disable-next-line no-param-reassign
24634
- prev[streamId] = [rest];
24636
+ prev[roomId] = [rest];
24635
24637
  }
24636
24638
  else
24637
- prev[streamId].push(rest);
24639
+ prev[roomId].push(rest);
24638
24640
  return prev;
24639
24641
  }, {});
24640
24642
  // Call server api `POST /api/v1/reactions/live` to sync live reactions
24641
- Object.entries(payloads).forEach(([streamId, reactions]) => {
24643
+ Object.entries(payloads).forEach(([roomId, reactions]) => {
24642
24644
  createLiveReaction({
24643
- liveStreamId: streamId,
24645
+ roomId,
24644
24646
  reactions,
24645
24647
  });
24646
24648
  });
@@ -25133,23 +25135,6 @@ const loginAsVisitor = async (params) => {
25133
25135
  };
25134
25136
  /* end_public_function */
25135
25137
 
25136
- /* begin_public_function
25137
- id: client.get_current_user
25138
- */
25139
- const getCurrentUser = () => {
25140
- var _a;
25141
- const client = getActiveClient();
25142
- if (!client) {
25143
- throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
25144
- }
25145
- const cache = (_a = pullFromCache(['user', 'get', client.userId])) === null || _a === void 0 ? void 0 : _a.data;
25146
- if (!cache) {
25147
- throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
25148
- }
25149
- return userLinkedObject(cache);
25150
- };
25151
- /* end_public_function */
25152
-
25153
25138
  /* begin_public_function
25154
25139
  id: client.renew_access_token
25155
25140
  */
@@ -28151,7 +28136,7 @@ getChannel$1.locally = (channelId) => {
28151
28136
  * @category Stream API
28152
28137
  * @async
28153
28138
  */
28154
- const getLiveChat = async (stream) => {
28139
+ const getLiveChat$1 = async (stream) => {
28155
28140
  var _a;
28156
28141
  const client = getActiveClient();
28157
28142
  client.log('stream/getLiveChat', stream.streamId);
@@ -28218,7 +28203,7 @@ const streamLinkedObject = (stream) => {
28218
28203
  return streamLinkedObject(streamCache);
28219
28204
  })
28220
28205
  .filter(isNonNullable);
28221
- }, getLiveChat: () => getLiveChat(stream), isBanned: !stream.watcherUrl, watcherUrl: null, get [GET_WATCHER_URLS]() {
28206
+ }, getLiveChat: () => getLiveChat$1(stream), isBanned: !stream.watcherUrl, watcherUrl: null, get [GET_WATCHER_URLS]() {
28222
28207
  return stream.watcherUrl;
28223
28208
  } });
28224
28209
  };
@@ -28326,6 +28311,95 @@ function isAmityAudioPost(post) {
28326
28311
  'fileId' in post.data &&
28327
28312
  post.dataType === 'audio');
28328
28313
  }
28314
+ function isAmityRoomPost(post) {
28315
+ return !!(post.data &&
28316
+ typeof post.data !== 'string' &&
28317
+ 'roomId' in post.data &&
28318
+ post.dataType === 'room');
28319
+ }
28320
+
28321
+ /**
28322
+ * ```js
28323
+ * import { RoomRepository } from '@amityco/ts-sdk'
28324
+ * const stream = await getStream('foobar')
28325
+ * ```
28326
+ *
28327
+ * Fetches a {@link Amity.Channel} object linked with a current stream
28328
+ *
28329
+ * @param stream {@link Amity.Stream} that has linked live channel
28330
+ * @returns the associated {@link Amity.Channel<'live'>} object
28331
+ *
28332
+ * @category Stream API
28333
+ * @async
28334
+ */
28335
+ const getLiveChat = async (room) => {
28336
+ var _a;
28337
+ const client = getActiveClient();
28338
+ client.log('room/getLiveChat', room.roomId);
28339
+ if (room.liveChannelId) {
28340
+ const channel = (_a = pullFromCache([
28341
+ 'channel',
28342
+ 'get',
28343
+ room.liveChannelId,
28344
+ ])) === null || _a === void 0 ? void 0 : _a.data;
28345
+ if (channel)
28346
+ return channelLinkedObject(constructChannelObject(channel));
28347
+ const { data } = await getChannel$1(room.liveChannelId);
28348
+ return channelLinkedObject(constructChannelObject(data));
28349
+ }
28350
+ // No Channel ID
28351
+ // streamer: create a new live channel
28352
+ if (room.createdBy === client.userId) {
28353
+ const { data: channel } = await createChannel({
28354
+ type: 'live',
28355
+ postId: room.referenceId,
28356
+ roomId: room.roomId,
28357
+ });
28358
+ // Update channelId to stream object in cache
28359
+ mergeInCache(['room', 'get', room.roomId], {
28360
+ liveChannelId: channel.channelId,
28361
+ });
28362
+ return channel;
28363
+ }
28364
+ // watcher: return undefined
28365
+ return undefined;
28366
+ };
28367
+
28368
+ const roomLinkedObject = (room) => {
28369
+ return Object.assign(Object.assign({}, room), { get moderation() {
28370
+ var _a;
28371
+ return (_a = pullFromCache(['roomModeration', 'get', room.roomId])) === null || _a === void 0 ? void 0 : _a.data;
28372
+ },
28373
+ get post() {
28374
+ var _a;
28375
+ if (room.referenceType !== 'post')
28376
+ return;
28377
+ return (_a = pullFromCache(['post', 'get', room.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
28378
+ },
28379
+ get community() {
28380
+ var _a;
28381
+ if (room.targetType !== 'community')
28382
+ return;
28383
+ return (_a = pullFromCache(['community', 'get', room.targetId])) === null || _a === void 0 ? void 0 : _a.data;
28384
+ },
28385
+ get user() {
28386
+ var _a;
28387
+ return (_a = pullFromCache(['user', 'get', room.createdBy])) === null || _a === void 0 ? void 0 : _a.data;
28388
+ },
28389
+ get childRooms() {
28390
+ if (!room.childRoomIds || room.childRoomIds.length === 0)
28391
+ return [];
28392
+ return room.childRoomIds
28393
+ .map(id => {
28394
+ var _a;
28395
+ const roomCache = (_a = pullFromCache(['room', 'get', id])) === null || _a === void 0 ? void 0 : _a.data;
28396
+ if (!roomCache)
28397
+ return undefined;
28398
+ return roomLinkedObject(roomCache);
28399
+ })
28400
+ .filter(isNonNullable);
28401
+ }, getLiveChat: () => getLiveChat(room) });
28402
+ };
28329
28403
 
28330
28404
  const postLinkedObject = (post) => {
28331
28405
  return shallowClone(post, {
@@ -28420,6 +28494,13 @@ const postLinkedObject = (post) => {
28420
28494
  ? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
28421
28495
  : undefined;
28422
28496
  },
28497
+ getRoomInfo() {
28498
+ var _a, _b;
28499
+ if (!isAmityRoomPost(post))
28500
+ return;
28501
+ const room = (_b = pullFromCache(['room', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.roomId])) === null || _b === void 0 ? void 0 : _b.data;
28502
+ return room ? roomLinkedObject(room) : undefined;
28503
+ },
28423
28504
  });
28424
28505
  };
28425
28506
 
@@ -29777,35 +29858,6 @@ const communityLinkedObject = (community) => {
29777
29858
  } });
29778
29859
  };
29779
29860
 
29780
- const eventLinkedObject = (event) => {
29781
- return Object.assign(Object.assign({}, event), { get creator() {
29782
- const cacheData = pullFromCache(['user', 'get', event.userId]);
29783
- if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29784
- return;
29785
- return userLinkedObject(cacheData.data);
29786
- },
29787
- get discussionCommunity() {
29788
- if (!event.discussionCommunityId)
29789
- return;
29790
- const cacheData = pullFromCache([
29791
- 'community',
29792
- 'get',
29793
- event.discussionCommunityId,
29794
- ]);
29795
- if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29796
- return;
29797
- return communityLinkedObject(cacheData.data);
29798
- },
29799
- get liveStream() {
29800
- if (!event.livestreamId)
29801
- return;
29802
- const cacheData = pullFromCache(['stream', 'get', event.livestreamId]);
29803
- if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29804
- return;
29805
- return cacheData.data;
29806
- } });
29807
- };
29808
-
29809
29861
  const LinkedObject = {
29810
29862
  ad: adLinkedObject,
29811
29863
  comment: commentLinkedObject,
@@ -29824,7 +29876,7 @@ const LinkedObject = {
29824
29876
  invitation: invitationLinkedObject,
29825
29877
  joinRequest: joinRequestLinkedObject,
29826
29878
  channelMember: channelMemberLinkedObject,
29827
- event: eventLinkedObject,
29879
+ room: roomLinkedObject,
29828
29880
  };
29829
29881
 
29830
29882
  /* begin_public_function
@@ -43809,6 +43861,735 @@ var index$8 = /*#__PURE__*/Object.freeze({
43809
43861
  getStreams: getStreams
43810
43862
  });
43811
43863
 
43864
+ /* begin_public_function
43865
+ id: room.create
43866
+ */
43867
+ /**
43868
+ * ```js
43869
+ * import { createRoom } from '@amityco/ts-sdk'
43870
+ * const created = await createRoom({ title: 'my room', 'thumbnailFileId': fileId })
43871
+ * ```
43872
+ *
43873
+ * Creates an {@link Amity.Room}
43874
+ *
43875
+ * @param bundle The data necessary to create a new {@link Amity.Room}
43876
+ * @returns The newly created {@link Amity.Room}
43877
+ *
43878
+ * @category Room API
43879
+ * @async
43880
+ */
43881
+ const createRoom = async (bundle) => {
43882
+ const client = getActiveClient();
43883
+ client.log('room/createRoom', bundle);
43884
+ const { data } = await client.http.post('/api/v1/rooms', bundle);
43885
+ fireEvent('local.room.created', data);
43886
+ const cachedAt = client.cache && Date.now();
43887
+ // TODO: check if should pick `users` filed which contains participants - if no need to ingest in the cache
43888
+ if (client.cache)
43889
+ ingestInCache(data, { cachedAt });
43890
+ const { rooms } = data;
43891
+ return {
43892
+ data: roomLinkedObject(rooms[0]),
43893
+ cachedAt,
43894
+ };
43895
+ };
43896
+ /* end_public_function */
43897
+
43898
+ /* begin_public_function
43899
+ id: room.update
43900
+ */
43901
+ /**
43902
+ * ```js
43903
+ * import { updateRoom } from '@amityco/ts-sdk'
43904
+ * const updated = await updateRoom('roomId', { title: 'updated title' })
43905
+ * ```
43906
+ *
43907
+ * Updates an {@link Amity.InternalRoom}
43908
+ *
43909
+ * @param roomId The ID of the room to update
43910
+ * @param bundle The data to update the room with
43911
+ * @returns The updated {@link Amity.InternalRoom}
43912
+ *
43913
+ * @category Room API
43914
+ * @async
43915
+ */
43916
+ const updateRoom = async (roomId, bundle) => {
43917
+ const client = getActiveClient();
43918
+ client.log('room/updateRoom', { roomId, bundle });
43919
+ const { data } = await client.http.put(`/api/v1/rooms/${roomId}`, bundle);
43920
+ fireEvent('local.room.updated', data);
43921
+ const cachedAt = client.cache && Date.now();
43922
+ if (client.cache)
43923
+ ingestInCache(data, { cachedAt });
43924
+ const { rooms } = data;
43925
+ return {
43926
+ data: roomLinkedObject(rooms[0]),
43927
+ cachedAt,
43928
+ };
43929
+ };
43930
+ /* end_public_function */
43931
+
43932
+ /* begin_public_function
43933
+ id: room.delete
43934
+ */
43935
+ /**
43936
+ * ```js
43937
+ * import { deleteRoom } from '@amityco/ts-sdk'
43938
+ * const result = await deleteRoom('roomId')
43939
+ * ```
43940
+ *
43941
+ * Deletes an {@link Amity.Room}
43942
+ *
43943
+ * @param roomId The ID of the room to delete
43944
+ * @returns Promise that resolves when the room is deleted
43945
+ *
43946
+ * @category Room API
43947
+ * @async
43948
+ */
43949
+ const deleteRoom = async (roomId) => {
43950
+ const client = getActiveClient();
43951
+ client.log('room/deleteRoom', { roomId });
43952
+ await client.http.delete(`/api/v1/rooms/${roomId}`);
43953
+ fireEvent('local.room.deleted', { rooms: [{ _id: roomId }] });
43954
+ };
43955
+ /* end_public_function */
43956
+
43957
+ /* begin_public_function
43958
+ id: room.stop
43959
+ */
43960
+ /**
43961
+ * ```js
43962
+ * import { stopRoom } from '@amityco/ts-sdk'
43963
+ * const result = await stopRoom('roomId')
43964
+ * ```
43965
+ *
43966
+ * Stops a room's broadcasting
43967
+ *
43968
+ * @param roomId The ID of the room to stop
43969
+ * @returns The updated room data
43970
+ *
43971
+ * @category Room API
43972
+ * @async
43973
+ */
43974
+ const stopRoom = async (roomId) => {
43975
+ const client = getActiveClient();
43976
+ client.log('room/stopRoom', { roomId });
43977
+ const { data } = await client.http.post(`/api/v1/rooms/${roomId}/stop`);
43978
+ fireEvent('local.room.stopped', data);
43979
+ const cachedAt = client.cache && Date.now();
43980
+ if (client.cache)
43981
+ ingestInCache(data, { cachedAt });
43982
+ const { rooms } = data;
43983
+ return {
43984
+ data: rooms[0],
43985
+ cachedAt,
43986
+ };
43987
+ };
43988
+ /* end_public_function */
43989
+
43990
+ /* begin_public_function
43991
+ id: room.getBroadcasterData
43992
+ */
43993
+ /**
43994
+ * ```js
43995
+ * import { getBroadcasterData } from '@amityco/ts-sdk'
43996
+ * const token = await getBroadcasterData('roomId')
43997
+ * ```
43998
+ *
43999
+ * Gets broadcaster data for a room
44000
+ *
44001
+ * @param roomId The ID of the room to get token for
44002
+ * @returns The broadcaster data of the room including coHostToken, coHostUrl and direactStreamUrl
44003
+ *
44004
+ * @category Room API
44005
+ * @async
44006
+ */
44007
+ const getBroadcasterData = async (roomId) => {
44008
+ const client = getActiveClient();
44009
+ client.log('room/getBroadcasterData', { roomId });
44010
+ const { data } = await client.http.get(`/api/v1/rooms/${roomId}/token`);
44011
+ return data;
44012
+ };
44013
+ /* end_public_function */
44014
+
44015
+ /* begin_public_function
44016
+ id: room.getRecordedUrl
44017
+ */
44018
+ /**
44019
+ * ```js
44020
+ * import { getRecordedUrl } from '@amityco/ts-sdk'
44021
+ * const recordedUrl = await getRecordedUrl('roomId')
44022
+ * ```
44023
+ *
44024
+ * Gets the recorded URL for a room
44025
+ *
44026
+ * @param roomId The ID of the room to get recorded URL for
44027
+ * @returns The recorded URL information
44028
+ *
44029
+ * @category Room API
44030
+ * @async
44031
+ */
44032
+ const getRecordedUrl = async (roomId) => {
44033
+ const client = getActiveClient();
44034
+ client.log('room/getRecordedUrl', { roomId });
44035
+ const { data } = await client.http.get(`/api/v1/rooms/${roomId}/recorded`);
44036
+ return data;
44037
+ };
44038
+ /* end_public_function */
44039
+
44040
+ /**
44041
+ * ```js
44042
+ * import { onRoomStartBroadcasting } from '@amityco/ts-sdk'
44043
+ * const dispose = onRoomStartBroadcasting(room => {
44044
+ * // ...
44045
+ * })
44046
+ * ```
44047
+ *
44048
+ * Fired when a {@link Amity.Room} has started broadcasting
44049
+ *
44050
+ * @param callback The function to call when the event was fired
44051
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44052
+ *
44053
+ * @category Room Events
44054
+ */
44055
+ const onRoomStartBroadcasting = (callback) => {
44056
+ const client = getActiveClient();
44057
+ const filter = (payload) => {
44058
+ ingestInCache(payload);
44059
+ callback(payload.rooms[0]);
44060
+ };
44061
+ return createEventSubscriber(client, 'room/onRoomStartBroadcasting', 'room.startBroadcasting', filter);
44062
+ };
44063
+
44064
+ /**
44065
+ * ```js
44066
+ * import { onRoomWaitingReconnect } from '@amityco/ts-sdk'
44067
+ * const dispose = onRoomWaitingReconnect(room => {
44068
+ * // ...
44069
+ * })
44070
+ * ```
44071
+ *
44072
+ * Fired when a {@link Amity.Room} is waiting for reconnection
44073
+ *
44074
+ * @param callback The function to call when the event was fired
44075
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44076
+ *
44077
+ * @category Room Events
44078
+ */
44079
+ const onRoomWaitingReconnect = (callback) => {
44080
+ const client = getActiveClient();
44081
+ const filter = (payload) => {
44082
+ ingestInCache(payload);
44083
+ callback(payload.rooms[0]);
44084
+ };
44085
+ return createEventSubscriber(client, 'room/onRoomWaitingReconnect', 'room.waitingReconnect', filter);
44086
+ };
44087
+
44088
+ /**
44089
+ * ```js
44090
+ * import { onRoomEndBroadcasting } from '@amityco/ts-sdk'
44091
+ * const dispose = onRoomEndBroadcasting(room => {
44092
+ * // ...
44093
+ * })
44094
+ * ```
44095
+ *
44096
+ * Fired when a {@link Amity.Room} has ended broadcasting
44097
+ *
44098
+ * @param callback The function to call when the event was fired
44099
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44100
+ *
44101
+ * @category Room Events
44102
+ */
44103
+ const onRoomEndBroadcasting = (callback) => {
44104
+ const client = getActiveClient();
44105
+ const filter = (payload) => {
44106
+ ingestInCache(payload);
44107
+ callback(payload.rooms[0]);
44108
+ };
44109
+ return createEventSubscriber(client, 'room/onRoomEndBroadcasting', 'room.endBroadcasting', filter);
44110
+ };
44111
+
44112
+ /**
44113
+ * ```js
44114
+ * import { onRoomRecordedAvailable } from '@amityco/ts-sdk'
44115
+ * const dispose = onRoomRecordedAvailable(room => {
44116
+ * // ...
44117
+ * })
44118
+ * ```
44119
+ *
44120
+ * Fired when a {@link Amity.Room} recorded content becomes available
44121
+ *
44122
+ * @param callback The function to call when the event was fired
44123
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44124
+ *
44125
+ * @category Room Events
44126
+ */
44127
+ const onRoomRecordedAvailable = (callback) => {
44128
+ const client = getActiveClient();
44129
+ const filter = (payload) => {
44130
+ ingestInCache(payload);
44131
+ callback(payload.rooms[0]);
44132
+ };
44133
+ return createEventSubscriber(client, 'room/onRoomRecordedAvailable', 'room.recordedAvailable', filter);
44134
+ };
44135
+
44136
+ /**
44137
+ * ```js
44138
+ * import { onRoomParticipantInviting } from '@amityco/ts-sdk'
44139
+ * const dispose = onRoomParticipantInviting(room => {
44140
+ * // ...
44141
+ * })
44142
+ * ```
44143
+ *
44144
+ * Fired when a participant is being invited to a {@link Amity.Room}
44145
+ *
44146
+ * @param callback The function to call when the event was fired
44147
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44148
+ *
44149
+ * @category Room Events
44150
+ */
44151
+ const onRoomParticipantInviting = (callback) => {
44152
+ const client = getActiveClient();
44153
+ const filter = (payload) => {
44154
+ ingestInCache(payload);
44155
+ callback(payload.rooms[0]);
44156
+ };
44157
+ return createEventSubscriber(client, 'room/onRoomParticipantInviting', 'room.participantInviting', filter);
44158
+ };
44159
+
44160
+ /**
44161
+ * ```js
44162
+ * import { onRoomParticipantJoined } from '@amityco/ts-sdk'
44163
+ * const dispose = onRoomParticipantJoined(room => {
44164
+ * // ...
44165
+ * })
44166
+ * ```
44167
+ *
44168
+ * Fired when a participant has joined a {@link Amity.Room}
44169
+ *
44170
+ * @param callback The function to call when the event was fired
44171
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44172
+ *
44173
+ * @category Room Events
44174
+ */
44175
+ const onRoomParticipantJoined = (callback) => {
44176
+ const client = getActiveClient();
44177
+ const filter = (payload) => {
44178
+ ingestInCache(payload);
44179
+ callback(payload.rooms[0]);
44180
+ };
44181
+ return createEventSubscriber(client, 'room/onRoomParticipantJoined', 'room.participantJoined', filter);
44182
+ };
44183
+
44184
+ /**
44185
+ * ```js
44186
+ * import { onRoomParticipantLeft } from '@amityco/ts-sdk'
44187
+ * const dispose = onRoomParticipantLeft(room => {
44188
+ * // ...
44189
+ * })
44190
+ * ```
44191
+ *
44192
+ * Fired when a participant has left a {@link Amity.Room}
44193
+ *
44194
+ * @param callback The function to call when the event was fired
44195
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44196
+ *
44197
+ * @category Room Events
44198
+ */
44199
+ const onRoomParticipantLeft = (callback) => {
44200
+ const client = getActiveClient();
44201
+ const filter = (payload) => {
44202
+ ingestInCache(payload);
44203
+ callback(payload.rooms[0]);
44204
+ };
44205
+ return createEventSubscriber(client, 'room/onRoomParticipantLeft', 'room.participantLeft', filter);
44206
+ };
44207
+
44208
+ /**
44209
+ * ```js
44210
+ * import { onRoomCreated } from '@amityco/ts-sdk'
44211
+ * const dispose = onRoomCreated(room => {
44212
+ * // ...
44213
+ * })
44214
+ * ```
44215
+ *
44216
+ * Fired when a {@link Amity.Room} has been created locally
44217
+ *
44218
+ * @param callback The function to call when the event was fired
44219
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44220
+ *
44221
+ * @category Room Events
44222
+ */
44223
+ const onRoomCreated = (callback) => {
44224
+ const client = getActiveClient();
44225
+ const filter = (payload) => {
44226
+ ingestInCache(payload);
44227
+ callback(payload.rooms[0]);
44228
+ };
44229
+ return createEventSubscriber(client, 'room/onRoomCreated', 'local.room.created', filter);
44230
+ };
44231
+
44232
+ /**
44233
+ * ```js
44234
+ * import { onRoomUpdated } from '@amityco/ts-sdk'
44235
+ * const dispose = onRoomUpdated(room => {
44236
+ * // ...
44237
+ * })
44238
+ * ```
44239
+ *
44240
+ * Fired when a {@link Amity.Room} has been updated locally
44241
+ *
44242
+ * @param callback The function to call when the event was fired
44243
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44244
+ *
44245
+ * @category Room Events
44246
+ */
44247
+ const onRoomUpdated = (callback) => {
44248
+ const client = getActiveClient();
44249
+ const filter = (payload) => {
44250
+ ingestInCache(payload);
44251
+ callback(payload.rooms[0]);
44252
+ };
44253
+ return createEventSubscriber(client, 'room/onRoomUpdated', 'local.room.updated', filter);
44254
+ };
44255
+
44256
+ /**
44257
+ * ```js
44258
+ * import { onRoomDeleted } from '@amityco/ts-sdk'
44259
+ * const dispose = onRoomDeleted(room => {
44260
+ * // ...
44261
+ * })
44262
+ * ```
44263
+ *
44264
+ * Fired when a {@link Amity.Room} has been deleted locally
44265
+ *
44266
+ * @param callback The function to call when the event was fired
44267
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44268
+ *
44269
+ * @category Room Events
44270
+ */
44271
+ const onRoomDeleted = (callback) => {
44272
+ const client = getActiveClient();
44273
+ const filter = (payload) => {
44274
+ ingestInCache(payload);
44275
+ callback(payload.rooms[0]);
44276
+ };
44277
+ return createEventSubscriber(client, 'room/onRoomDeleted', 'local.room.deleted', filter);
44278
+ };
44279
+
44280
+ /**
44281
+ * ```js
44282
+ * import { onRoomStopped } from '@amityco/ts-sdk'
44283
+ * const dispose = onRoomStopped(room => {
44284
+ * // ...
44285
+ * })
44286
+ * ```
44287
+ *
44288
+ * Fired when a {@link Amity.Room} has been stopped locally
44289
+ *
44290
+ * @param callback The function to call when the event was fired
44291
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44292
+ *
44293
+ * @category Room Events
44294
+ */
44295
+ const onRoomStopped = (callback) => {
44296
+ const client = getActiveClient();
44297
+ const filter = (payload) => {
44298
+ ingestInCache(payload);
44299
+ callback(payload.rooms[0]);
44300
+ };
44301
+ return createEventSubscriber(client, 'room/onRoomStopped', 'local.room.stopped', filter);
44302
+ };
44303
+
44304
+ const getRoomById = async (roomId) => {
44305
+ const client = getActiveClient();
44306
+ client.log('room/getRoomById', roomId);
44307
+ // Check if room is in tombstone
44308
+ isInTombstone('room', roomId);
44309
+ let data;
44310
+ try {
44311
+ const response = await client.http.get(`/api/v1/rooms/${roomId}`);
44312
+ data = response.data;
44313
+ }
44314
+ catch (error) {
44315
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
44316
+ pushToTombstone('room', roomId);
44317
+ }
44318
+ throw error;
44319
+ }
44320
+ const cachedAt = client.cache && Date.now();
44321
+ if (client.cache) {
44322
+ ingestInCache(data, { cachedAt });
44323
+ }
44324
+ return {
44325
+ data: data.rooms[0],
44326
+ cachedAt,
44327
+ };
44328
+ };
44329
+ getRoomById.locally = (roomId) => {
44330
+ const client = getActiveClient();
44331
+ client.log('room/getRoomById.locally', roomId);
44332
+ // Check if room is in tombstone
44333
+ isInTombstone('room', roomId);
44334
+ const cachedAt = client.cache && Date.now();
44335
+ const roomCache = pullFromCache(['room', 'get', roomId]);
44336
+ if (!roomCache)
44337
+ return;
44338
+ return {
44339
+ data: roomCache.data,
44340
+ cachedAt,
44341
+ };
44342
+ };
44343
+
44344
+ const getRoom = (roomId, callback) => {
44345
+ // TODO: add callbackDataSelector if there are linked object fields
44346
+ return liveObject(roomId, callback, '_id', getRoomById, [
44347
+ onRoomEndBroadcasting,
44348
+ onRoomStartBroadcasting,
44349
+ onRoomWaitingReconnect,
44350
+ onRoomRecordedAvailable,
44351
+ ], {
44352
+ callbackDataSelector: (data) => {
44353
+ if (!data)
44354
+ return data;
44355
+ return LinkedObject.room(data);
44356
+ },
44357
+ });
44358
+ };
44359
+
44360
+ class RoomPaginationController extends PaginationController {
44361
+ async getRequest(queryParams, token) {
44362
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
44363
+ const baseOptions = {
44364
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
44365
+ };
44366
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
44367
+ const { data: queryResponse } = await this.http.get(`/api/v1/rooms`, {
44368
+ params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
44369
+ });
44370
+ return queryResponse;
44371
+ }
44372
+ }
44373
+
44374
+ var EnumRoomActions;
44375
+ (function (EnumRoomActions) {
44376
+ EnumRoomActions["OnRoomCreated"] = "OnRoomCreated";
44377
+ EnumRoomActions["OnRoomUpdated"] = "OnRoomUpdated";
44378
+ EnumRoomActions["OnRoomDeleted"] = "OnRoomDeleted";
44379
+ EnumRoomActions["OnRoomStartBroadcasting"] = "OnRoomStartBroadcasting";
44380
+ EnumRoomActions["OnRoomEndBroadcasting"] = "OnRoomEndBroadcasting";
44381
+ EnumRoomActions["OnRoomParticipantJoined"] = "OnRoomParticipantJoined";
44382
+ EnumRoomActions["OnRoomParticipantLeft"] = "OnRoomParticipantLeft";
44383
+ })(EnumRoomActions || (EnumRoomActions = {}));
44384
+
44385
+ class RoomQueryStreamController extends QueryStreamController {
44386
+ constructor(query, cacheKey, notifyChange, preparePayload) {
44387
+ super(query, cacheKey);
44388
+ this.notifyChange = notifyChange;
44389
+ this.preparePayload = preparePayload;
44390
+ }
44391
+ async saveToMainDB(response) {
44392
+ const processedPayload = await this.preparePayload(response);
44393
+ const client = getActiveClient();
44394
+ const cachedAt = client.cache && Date.now();
44395
+ if (client.cache) {
44396
+ ingestInCache(processedPayload, { cachedAt });
44397
+ }
44398
+ }
44399
+ appendToQueryStream(response, direction, refresh = false) {
44400
+ var _a, _b;
44401
+ if (refresh) {
44402
+ pushToCache(this.cacheKey, {
44403
+ data: response.rooms.map(getResolver('room')),
44404
+ });
44405
+ }
44406
+ else {
44407
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44408
+ const rooms = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
44409
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...rooms, ...response.rooms.map(getResolver('room'))])] }));
44410
+ }
44411
+ }
44412
+ reactor(action) {
44413
+ return (room) => {
44414
+ var _a;
44415
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44416
+ if (!collection)
44417
+ return;
44418
+ if (action === EnumRoomActions.OnRoomDeleted) {
44419
+ collection.data = collection.data.filter(roomId => roomId !== room._id);
44420
+ }
44421
+ if (action === EnumRoomActions.OnRoomCreated) {
44422
+ collection.data = [...new Set([room._id, ...collection.data])];
44423
+ }
44424
+ pushToCache(this.cacheKey, collection);
44425
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
44426
+ };
44427
+ }
44428
+ subscribeRTE(createSubscriber) {
44429
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
44430
+ }
44431
+ }
44432
+
44433
+ // TODO: confirm related events
44434
+ const getRoomSubscription = () => [
44435
+ {
44436
+ fn: onRoomStartBroadcasting,
44437
+ action: EnumRoomActions.OnRoomStartBroadcasting,
44438
+ },
44439
+ {
44440
+ fn: onRoomEndBroadcasting,
44441
+ action: EnumRoomActions.OnRoomEndBroadcasting,
44442
+ },
44443
+ {
44444
+ fn: onRoomRecordedAvailable,
44445
+ action: EnumRoomActions.OnRoomUpdated,
44446
+ },
44447
+ ];
44448
+
44449
+ class RoomLiveCollectionController extends LiveCollectionController {
44450
+ constructor(query, callback) {
44451
+ const queryStreamId = hash(query);
44452
+ const cacheKey = ['rooms', 'collection', queryStreamId];
44453
+ const paginationController = new RoomPaginationController(query);
44454
+ super(paginationController, queryStreamId, cacheKey, callback);
44455
+ this.query = query;
44456
+ this.queryStreamController = new RoomQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
44457
+ this.callback = callback.bind(this);
44458
+ this.loadPage({ initial: true });
44459
+ }
44460
+ setup() {
44461
+ var _a;
44462
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44463
+ if (!collection) {
44464
+ pushToCache(this.cacheKey, {
44465
+ data: [],
44466
+ params: {},
44467
+ });
44468
+ }
44469
+ }
44470
+ async persistModel(queryPayload) {
44471
+ await this.queryStreamController.saveToMainDB(queryPayload);
44472
+ }
44473
+ persistQueryStream({ response, direction, refresh, }) {
44474
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
44475
+ }
44476
+ startSubscription() {
44477
+ return this.queryStreamController.subscribeRTE(getRoomSubscription());
44478
+ }
44479
+ notifyChange({ origin, loading, error }) {
44480
+ var _a, _b;
44481
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44482
+ if (!collection)
44483
+ return;
44484
+ const data = this.applyFilter((_b = collection.data
44485
+ .map(id => pullFromCache(['room', 'get', id]))
44486
+ .filter(isNonNullable)
44487
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(room => room); // Since Room is same as InternalRoom, no transformation needed
44488
+ if (!this.shouldNotify(data) && origin === 'event')
44489
+ return;
44490
+ this.callback({
44491
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
44492
+ data,
44493
+ hasNextPage: !!this.paginationController.getNextToken(),
44494
+ loading,
44495
+ error,
44496
+ });
44497
+ }
44498
+ applyFilter(data) {
44499
+ let rooms = data;
44500
+ if (!this.query.includeDeleted) {
44501
+ rooms = filterByPropEquality(rooms, 'isDeleted', false);
44502
+ }
44503
+ if (this.query.statuses && this.query.statuses.length > 0) {
44504
+ rooms = rooms.filter(room => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(room.status); });
44505
+ }
44506
+ if (this.query.type) {
44507
+ rooms = filterByPropEquality(rooms, 'type', this.query.type);
44508
+ }
44509
+ switch (this.query.sortBy) {
44510
+ case 'firstCreated':
44511
+ rooms = rooms.sort(sortByFirstCreated);
44512
+ break;
44513
+ case 'lastCreated':
44514
+ default:
44515
+ rooms = rooms.sort(sortByLastCreated);
44516
+ break;
44517
+ }
44518
+ return rooms;
44519
+ }
44520
+ }
44521
+
44522
+ /* begin_public_function
44523
+ id: room.get_rooms
44524
+ */
44525
+ /**
44526
+ * ```js
44527
+ * import { RoomRepository } from '@amityco/ts-sdk'
44528
+ *
44529
+ * let rooms = []
44530
+ * const unsub = RoomRepository.getRooms({
44531
+ * type: 'direct_streaming',
44532
+ * statuses: ['live', 'idle'],
44533
+ * sortBy: 'lastCreated',
44534
+ * limit: 20,
44535
+ * includeDeleted: false
44536
+ * }, response => merge(rooms, response.data))
44537
+ * ```
44538
+ *
44539
+ * Observe all mutations on a list of {@link Amity.Room} for a given query
44540
+ *
44541
+ * @param params.type the type of rooms to filter by ('direct_streaming' | 'co_hosts')
44542
+ * @param params.statuses array of room statuses to filter by (['idle', 'live', 'waiting_reconnect', 'ended', 'recorded'])
44543
+ * @param params.sortBy sort rooms by creation time ('firstCreated' | 'lastCreated')
44544
+ * @param params.limit maximum number of rooms to retrieve per page
44545
+ * @param params.includeDeleted whether to include deleted rooms in the results
44546
+ * @param callback the function to call when new data are available
44547
+ * @param config optional configuration for the live collection
44548
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the rooms
44549
+ *
44550
+ * @category Rooms Live Collection
44551
+ */
44552
+ const getRooms = (params, callback, config) => {
44553
+ const { log, cache } = getActiveClient();
44554
+ if (!cache) {
44555
+ console.log(ENABLE_CACHE_MESSAGE);
44556
+ }
44557
+ const timestamp = Date.now();
44558
+ log(`getRooms(tmpid: ${timestamp}) > listen`);
44559
+ const roomsLiveCollection = new RoomLiveCollectionController(params, callback);
44560
+ const disposers = roomsLiveCollection.startSubscription();
44561
+ const cacheKey = roomsLiveCollection.getCacheKey();
44562
+ disposers.push(() => dropFromCache(cacheKey));
44563
+ return () => {
44564
+ log(`getRooms(tmpid: ${timestamp}) > dispose`);
44565
+ disposers.forEach(fn => fn());
44566
+ };
44567
+ };
44568
+ /* end_public_function */
44569
+
44570
+ var index$7 = /*#__PURE__*/Object.freeze({
44571
+ __proto__: null,
44572
+ createRoom: createRoom,
44573
+ updateRoom: updateRoom,
44574
+ deleteRoom: deleteRoom,
44575
+ stopRoom: stopRoom,
44576
+ getBroadcasterData: getBroadcasterData,
44577
+ getRecordedUrl: getRecordedUrl,
44578
+ onRoomStartBroadcasting: onRoomStartBroadcasting,
44579
+ onRoomWaitingReconnect: onRoomWaitingReconnect,
44580
+ onRoomEndBroadcasting: onRoomEndBroadcasting,
44581
+ onRoomRecordedAvailable: onRoomRecordedAvailable,
44582
+ onRoomParticipantInviting: onRoomParticipantInviting,
44583
+ onRoomParticipantJoined: onRoomParticipantJoined,
44584
+ onRoomParticipantLeft: onRoomParticipantLeft,
44585
+ onRoomCreated: onRoomCreated,
44586
+ onRoomUpdated: onRoomUpdated,
44587
+ onRoomDeleted: onRoomDeleted,
44588
+ onRoomStopped: onRoomStopped,
44589
+ getRoom: getRoom,
44590
+ getRooms: getRooms
44591
+ });
44592
+
43812
44593
  /* begin_public_function
43813
44594
  id: poll.create
43814
44595
  */
@@ -44109,7 +44890,7 @@ const getPoll = (pollId, callback) => {
44109
44890
  };
44110
44891
  /* end_public_function */
44111
44892
 
44112
- var index$7 = /*#__PURE__*/Object.freeze({
44893
+ var index$6 = /*#__PURE__*/Object.freeze({
44113
44894
  __proto__: null,
44114
44895
  createPoll: createPoll,
44115
44896
  closePoll: closePoll,
@@ -44492,7 +45273,7 @@ const getPlayer = async (parameters) => {
44492
45273
  return video;
44493
45274
  };
44494
45275
 
44495
- var index$6 = /*#__PURE__*/Object.freeze({
45276
+ var index$5 = /*#__PURE__*/Object.freeze({
44496
45277
  __proto__: null,
44497
45278
  getPlayer: getPlayer
44498
45279
  });
@@ -45665,7 +46446,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
45665
46446
  };
45666
46447
  };
45667
46448
 
45668
- var index$5 = /*#__PURE__*/Object.freeze({
46449
+ var index$4 = /*#__PURE__*/Object.freeze({
45669
46450
  __proto__: null,
45670
46451
  createImageStory: createImageStory,
45671
46452
  createVideoStory: createVideoStory,
@@ -45702,7 +46483,7 @@ const getNetworkAds = async () => {
45702
46483
  };
45703
46484
  };
45704
46485
 
45705
- var index$4 = /*#__PURE__*/Object.freeze({
46486
+ var index$3 = /*#__PURE__*/Object.freeze({
45706
46487
  __proto__: null,
45707
46488
  getNetworkAds: getNetworkAds
45708
46489
  });
@@ -46093,7 +46874,7 @@ const markTraySeen = async (lastSeenAt) => {
46093
46874
  };
46094
46875
  /* end_public_function */
46095
46876
 
46096
- var index$3 = /*#__PURE__*/Object.freeze({
46877
+ var index$2 = /*#__PURE__*/Object.freeze({
46097
46878
  __proto__: null,
46098
46879
  getNotificationTraySeen: getNotificationTraySeen,
46099
46880
  getNotificationTrayItems: getNotificationTrayItems,
@@ -46294,7 +47075,7 @@ const getMyCommunityInvitations = (params, callback, config) => {
46294
47075
  };
46295
47076
  };
46296
47077
 
46297
- var index$2 = /*#__PURE__*/Object.freeze({
47078
+ var index$1 = /*#__PURE__*/Object.freeze({
46298
47079
  __proto__: null,
46299
47080
  onLocalInvitationCreated: onLocalInvitationCreated,
46300
47081
  onLocalInvitationUpdated: onLocalInvitationUpdated,
@@ -46327,7 +47108,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
46327
47108
  * @category Live Reaction API
46328
47109
  * @async
46329
47110
  */
46330
- const createReaction = async ({ referenceId, referenceType, reactionName, streamId, }) => {
47111
+ const createReaction = async ({ referenceId, referenceType, reactionName, roomId, }) => {
46331
47112
  const client = getActiveClient();
46332
47113
  client.log('live_reaction/createReaction', {
46333
47114
  referenceId,
@@ -46339,7 +47120,7 @@ const createReaction = async ({ referenceId, referenceType, reactionName, stream
46339
47120
  reactionName,
46340
47121
  referencePublicId: referenceId,
46341
47122
  referenceType,
46342
- streamId,
47123
+ roomId,
46343
47124
  occurredAt: new Date().toISOString(),
46344
47125
  };
46345
47126
  reactionSynceEngine.createLiveReaction(reaction);
@@ -46435,619 +47216,11 @@ const getReactions = (postId, callback) => {
46435
47216
  };
46436
47217
  };
46437
47218
 
46438
- var index$1 = /*#__PURE__*/Object.freeze({
47219
+ var index = /*#__PURE__*/Object.freeze({
46439
47220
  __proto__: null,
46440
47221
  createReaction: createReaction,
46441
47222
  onLiveReactionCreated: onLiveReactionCreated,
46442
47223
  getReactions: getReactions
46443
47224
  });
46444
47225
 
46445
- const prepareEventPayload = (rawPayload) => {
46446
- return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
46447
- };
46448
-
46449
- const createEventEventSubscriber = (event, callback) => {
46450
- const client = getActiveClient();
46451
- const filter = (payload) => {
46452
- const unpackedPayload = prepareEventPayload(payload);
46453
- if (!client.cache) {
46454
- callback(unpackedPayload.events[0]);
46455
- }
46456
- else {
46457
- ingestInCache(unpackedPayload);
46458
- const event = pullFromCache([
46459
- 'event',
46460
- 'get',
46461
- unpackedPayload.events[0].eventId,
46462
- ]);
46463
- callback(event.data);
46464
- }
46465
- };
46466
- return createEventSubscriber(client, event, event, filter);
46467
- };
46468
-
46469
- /* begin_public_function
46470
- id: event.create
46471
- */
46472
- /**
46473
- * ```js
46474
- * import { EventRepository } from '@amityco/ts-sdk'
46475
- * const response = await EventRepository.createEvent(bundle)
46476
- * ```
46477
- *
46478
- * Creates an {@link Amity.Event}
46479
- *
46480
- * @param bundle The data necessary to create a new {@link Amity.Event}
46481
- * @returns The newly created {@link Amity.Event}
46482
- *
46483
- * @category Event API
46484
- * @async
46485
- */
46486
- const createEvent = async (bundle) => {
46487
- const client = getActiveClient();
46488
- client.log('event/createEvent', bundle);
46489
- const { data: payload } = await client.http.post('/api/v1/events', bundle);
46490
- fireEvent('local.event.created', payload);
46491
- const preparedPayload = prepareEventPayload(payload);
46492
- const cachedAt = client.cache && Date.now();
46493
- if (client.cache)
46494
- ingestInCache(preparedPayload, { cachedAt });
46495
- return {
46496
- data: eventLinkedObject(preparedPayload.events[0]),
46497
- cachedAt,
46498
- };
46499
- };
46500
- /* end_public_function */
46501
-
46502
- /* begin_public_function
46503
- id: event.update
46504
- */
46505
- /**
46506
- * ```js
46507
- * import { EventRepository } from '@amityco/ts-sdk'
46508
- * const response = await EventRepository.updateEvent(eventId, bundle)
46509
- * ```
46510
- *
46511
- * Updates an {@link Amity.Event}
46512
- *
46513
- * @param eventId The ID of the {@link Amity.Event} to edit
46514
- * @param bundle The data necessary to update an existing {@link Amity.Event}
46515
- * @returns the updated {@link Amity.Event}
46516
- *
46517
- * @category Event API
46518
- * @async
46519
- */
46520
- const updateEvent = async (eventId, bundle) => {
46521
- const client = getActiveClient();
46522
- client.log('event/updateEvent', eventId, bundle);
46523
- const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
46524
- fireEvent('local.event.updated', payload);
46525
- const preparedPayload = prepareEventPayload(payload);
46526
- const cachedAt = client.cache && Date.now();
46527
- if (client.cache)
46528
- ingestInCache(preparedPayload, { cachedAt });
46529
- return {
46530
- data: eventLinkedObject(preparedPayload.events.find(event => event.eventId === eventId)),
46531
- cachedAt,
46532
- };
46533
- };
46534
- /* end_public_function */
46535
-
46536
- /* begin_public_function
46537
- id: event.get
46538
- */
46539
- /**
46540
- * ```js
46541
- * import { EventRepository } from '@amityco/ts-sdk'
46542
- * const event = await EventRepository.getEvent(eventId)
46543
- * ```
46544
- *
46545
- * Fetches a {@link Amity.Event} object
46546
- *
46547
- * @param eventId the ID of the {@link Amity.Event} to fetch
46548
- * @returns the associated {@link Amity.Event} object
46549
- *
46550
- * @category Event API
46551
- * @async
46552
- */
46553
- const getEvent$1 = async (eventId) => {
46554
- const client = getActiveClient();
46555
- client.log('event/getEvent', eventId);
46556
- const { data: payload } = await client.http.get(`/api/v3/events/${eventId}`);
46557
- const data = prepareEventPayload(payload);
46558
- const cachedAt = client.cache && Date.now();
46559
- if (client.cache)
46560
- ingestInCache(data, { cachedAt });
46561
- return {
46562
- data: data.events.find(event => event.eventId === eventId),
46563
- cachedAt,
46564
- };
46565
- };
46566
- /* end_public_function */
46567
- /**
46568
- * ```js
46569
- * import { EventRepository } from '@amityco/ts-sdk'
46570
- * const event = EventRepository.getEvent.locally(eventId)
46571
- * ```
46572
- *
46573
- * Fetches a {@link Amity.Event} object in cache
46574
- *
46575
- * @param eventId the ID of the {@link Amity.Event} to fetch
46576
- * @returns the associated {@link Amity.Event} object
46577
- *
46578
- * @category Event API
46579
- */
46580
- getEvent$1.locally = (eventId) => {
46581
- const client = getActiveClient();
46582
- client.log('event/getEvent.locally', eventId);
46583
- if (!client.cache)
46584
- return;
46585
- const cache = pullFromCache(['event', 'get', eventId]);
46586
- if (!cache)
46587
- return;
46588
- return {
46589
- data: cache.data,
46590
- cachedAt: cache.cachedAt,
46591
- };
46592
- };
46593
-
46594
- /* begin_public_function
46595
- id: event.delete
46596
- */
46597
- /**
46598
- * ```js
46599
- * import { EventRepository } from '@amityco/ts-sdk'
46600
- * const { success } = await EventRepository.deleteEvent(eventId)
46601
- * ```
46602
- *
46603
- * Deletes a {@link Amity.Event}
46604
- *
46605
- * @param eventId The {@link Amity.Event} ID to delete
46606
- *
46607
- * @category Event API
46608
- * @async
46609
- */
46610
- const deleteEvent = async (eventId) => {
46611
- const client = getActiveClient();
46612
- client.log('event/deleteEvent', eventId);
46613
- const event = await getEvent$1(eventId);
46614
- await client.http.delete(`/api/v3/events/${eventId}`);
46615
- const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
46616
- upsertInCache(['event', 'get', eventId], deletedEvent);
46617
- fireEvent('local.event.deleted', {
46618
- users: [],
46619
- files: [],
46620
- communities: [],
46621
- videoStreamings: [],
46622
- events: [deletedEvent],
46623
- discussionCommunities: [],
46624
- });
46625
- };
46626
- /* end_public_function */
46627
-
46628
- /**
46629
- * ```js
46630
- * import { EventRepository } from '@amityco/ts-sdk'
46631
- * const dispose = EventRepository.onEventCreated(event => {
46632
- * // ...
46633
- * })
46634
- * ```
46635
- *
46636
- * Fired when a {@link Amity.Event} has been created
46637
- *
46638
- * @param callback The function to call when the event was fired
46639
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46640
- *
46641
- * @category Event Events
46642
- */
46643
- const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
46644
-
46645
- /**
46646
- * ```js
46647
- * import { EventRepository } from '@amityco/ts-sdk'
46648
- * const dispose = EventRepository.onEventUpdated(event => {
46649
- * // ...
46650
- * })
46651
- * ```
46652
- *
46653
- * Fired when a {@link Amity.Event} has been updated
46654
- *
46655
- * @param callback The function to call when the event was fired
46656
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46657
- *
46658
- * @category Event Events
46659
- */
46660
- const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
46661
-
46662
- /**
46663
- * ```js
46664
- * import { EventRepository } from '@amityco/ts-sdk'
46665
- * const dispose = EventRepository.onEventDeleted(event => {
46666
- * // ...
46667
- * })
46668
- * ```
46669
- *
46670
- * Fired when a {@link Amity.Event} has been deleted
46671
- *
46672
- * @param callback The function to call when the event was fired
46673
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46674
- *
46675
- * @category Event Events
46676
- */
46677
- const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
46678
-
46679
- /**
46680
- * ```js
46681
- * import { EventRepository } from '@amityco/ts-sdk'
46682
- * const dispose = EventRepository.onLocalEventCreated(event => {
46683
- * // ...
46684
- * })
46685
- * ```
46686
- *
46687
- * Fired when a {@link Amity.Event} has been created
46688
- *
46689
- * @param callback The function to call when the event was fired
46690
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46691
- *
46692
- * @category Event Events
46693
- */
46694
- const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
46695
-
46696
- /**
46697
- * ```js
46698
- * import { EventRepository } from '@amityco/ts-sdk'
46699
- * const dispose = EventRepository.onLocalEventUpdated(event => {
46700
- * // ...
46701
- * })
46702
- * ```
46703
- *
46704
- * Fired when a {@link Amity.Event} has been updated
46705
- *
46706
- * @param callback The function to call when the event was fired
46707
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46708
- *
46709
- * @category Event Events
46710
- */
46711
- const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
46712
-
46713
- /**
46714
- * ```js
46715
- * import { EventRepository } from '@amityco/ts-sdk'
46716
- * const dispose = EventRepository.onLocalEventDeleted(event => {
46717
- * // ...
46718
- * })
46719
- * ```
46720
- *
46721
- * Fired when a {@link Amity.Event} has been deleted
46722
- *
46723
- * @param callback The function to call when the event was fired
46724
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46725
- *
46726
- * @category Event Events
46727
- */
46728
- const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
46729
-
46730
- /* begin_public_function
46731
- id: event.get
46732
- */
46733
- /**
46734
- * ```js
46735
- * import { EventRepository } from '@amityco/ts-sdk';
46736
- *
46737
- * let event;
46738
- *
46739
- * const unsubscribe = EventRepository.getEvent(eventId, response => {
46740
- * event = response.data;
46741
- * });
46742
- * ```
46743
- *
46744
- * Observe all mutation on a given {@link Amity.Event}
46745
- *
46746
- * @param eventId the ID of the event to observe
46747
- * @param callback the function to call when new snapshot of event are available
46748
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the event
46749
- *
46750
- * @category Event Live Object
46751
- */
46752
- const getEvent = (eventId, callback) => {
46753
- return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
46754
- callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
46755
- });
46756
- };
46757
- /* end_public_function */
46758
-
46759
- var EventActionsEnum;
46760
- (function (EventActionsEnum) {
46761
- EventActionsEnum["OnEventCreated"] = "onEventCreated";
46762
- EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
46763
- EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
46764
- })(EventActionsEnum || (EventActionsEnum = {}));
46765
-
46766
- class EventPaginationController extends PaginationController {
46767
- async getRequest(queryParams, token) {
46768
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
46769
- const options = token ? { token } : { limit };
46770
- const { data: response } = await this.http.get(`/api/v1/events`, { params: Object.assign(Object.assign({}, params), { options }) });
46771
- return response;
46772
- }
46773
- }
46774
-
46775
- class EventQueryStreamController extends QueryStreamController {
46776
- constructor(query, cacheKey, notifyChange, preparePayload) {
46777
- super(query, cacheKey);
46778
- this.notifyChange = notifyChange;
46779
- this.preparePayload = preparePayload;
46780
- }
46781
- async saveToMainDB(response) {
46782
- const processedPayload = this.preparePayload(response);
46783
- const client = getActiveClient();
46784
- const cachedAt = client.cache && Date.now();
46785
- if (client.cache)
46786
- ingestInCache(processedPayload, { cachedAt });
46787
- }
46788
- appendToQueryStream(response, direction, refresh = false) {
46789
- var _a, _b;
46790
- if (refresh) {
46791
- pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
46792
- }
46793
- else {
46794
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
46795
- const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
46796
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
46797
- }
46798
- }
46799
- reactor(action) {
46800
- return (event) => {
46801
- var _a;
46802
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
46803
- if (!collection)
46804
- return;
46805
- if (action === EventActionsEnum.OnEventCreated) {
46806
- collection.data = [...new Set([event.eventId, ...collection.data])];
46807
- }
46808
- if (action === EventActionsEnum.OnEventDeleted) {
46809
- collection.data = collection.data.filter(eventId => eventId !== event.eventId);
46810
- }
46811
- pushToCache(this.cacheKey, collection);
46812
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
46813
- };
46814
- }
46815
- subscribeRTE(createSubscriber) {
46816
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
46817
- }
46818
- }
46819
-
46820
- class EventLiveCollectionController extends LiveCollectionController {
46821
- constructor(query, callback) {
46822
- const queryStreamId = hash(query);
46823
- const cacheKey = ['event', 'collection', queryStreamId];
46824
- const paginationController = new EventPaginationController(query);
46825
- super(paginationController, queryStreamId, cacheKey, callback);
46826
- this.query = query;
46827
- this.queryStreamController = new EventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
46828
- this.callback = callback.bind(this);
46829
- this.loadPage({ initial: true });
46830
- }
46831
- setup() {
46832
- var _a;
46833
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
46834
- if (!collection)
46835
- pushToCache(this.cacheKey, { data: [], params: {} });
46836
- }
46837
- async persistModel(queryPayload) {
46838
- await this.queryStreamController.saveToMainDB(queryPayload);
46839
- }
46840
- persistQueryStream({ response, direction, refresh, }) {
46841
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
46842
- }
46843
- startSubscription() {
46844
- return this.queryStreamController.subscribeRTE([
46845
- { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
46846
- { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
46847
- { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
46848
- { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
46849
- { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
46850
- { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
46851
- ]);
46852
- }
46853
- notifyChange({ origin, loading, error }) {
46854
- var _a, _b;
46855
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
46856
- if (!collection)
46857
- return;
46858
- const data = ((_b = collection.data
46859
- .map(eventId => pullFromCache(['event', 'get', eventId]))
46860
- .filter(isNonNullable)
46861
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
46862
- if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
46863
- return;
46864
- this.callback({
46865
- data,
46866
- error,
46867
- loading,
46868
- hasNextPage: !!this.paginationController.getNextToken(),
46869
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
46870
- });
46871
- }
46872
- }
46873
-
46874
- /**
46875
- * Get events
46876
- *
46877
- * @param params the query parameters
46878
- * @param callback the callback to be called when the events are updated
46879
- * @returns events
46880
- *
46881
- * @category Event Live Collection
46882
- *
46883
- */
46884
- const getEvents = (params, callback, config) => {
46885
- const { log, cache } = getActiveClient();
46886
- if (!cache)
46887
- console.log(ENABLE_CACHE_MESSAGE);
46888
- const timestamp = Date.now();
46889
- log(`getEvents: (tmpid: ${timestamp}) > listen`);
46890
- const eventLiveCollection = new EventLiveCollectionController(params, callback);
46891
- const disposers = eventLiveCollection.startSubscription();
46892
- const cacheKey = eventLiveCollection.getCacheKey();
46893
- disposers.push(() => dropFromCache(cacheKey));
46894
- return () => {
46895
- log(`getEvents (tmpid: ${timestamp}) > dispose`);
46896
- disposers.forEach(fn => fn());
46897
- };
46898
- };
46899
-
46900
- class MyEventPaginationController extends PaginationController {
46901
- async getRequest(queryParams, token) {
46902
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
46903
- const options = token ? { token } : { limit };
46904
- const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
46905
- return response;
46906
- }
46907
- }
46908
-
46909
- class MyEventQueryStreamController extends QueryStreamController {
46910
- constructor(query, cacheKey, notifyChange, preparePayload) {
46911
- super(query, cacheKey);
46912
- this.notifyChange = notifyChange;
46913
- this.preparePayload = preparePayload;
46914
- }
46915
- async saveToMainDB(response) {
46916
- const processedPayload = this.preparePayload(response);
46917
- const client = getActiveClient();
46918
- const cachedAt = client.cache && Date.now();
46919
- if (client.cache)
46920
- ingestInCache(processedPayload, { cachedAt });
46921
- }
46922
- appendToQueryStream(response, direction, refresh = false) {
46923
- var _a, _b;
46924
- if (refresh) {
46925
- pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
46926
- }
46927
- else {
46928
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
46929
- const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
46930
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
46931
- }
46932
- }
46933
- reactor(action) {
46934
- return (event) => {
46935
- var _a;
46936
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
46937
- if (!collection)
46938
- return;
46939
- if (action === EventActionsEnum.OnEventCreated) {
46940
- const client = getActiveClient();
46941
- if (client.userId !== event.userId)
46942
- return;
46943
- collection.data = [...new Set([event.eventId, ...collection.data])];
46944
- }
46945
- if (action === EventActionsEnum.OnEventDeleted) {
46946
- collection.data = collection.data.filter(eventId => eventId !== event.eventId);
46947
- }
46948
- pushToCache(this.cacheKey, collection);
46949
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
46950
- };
46951
- }
46952
- subscribeRTE(createSubscriber) {
46953
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
46954
- }
46955
- }
46956
-
46957
- class MyEventLiveCollectionController extends LiveCollectionController {
46958
- constructor(query, callback) {
46959
- const queryStreamId = hash(query);
46960
- const cacheKey = ['event', 'collection', queryStreamId];
46961
- const paginationController = new MyEventPaginationController(query);
46962
- super(paginationController, queryStreamId, cacheKey, callback);
46963
- this.query = query;
46964
- this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
46965
- this.callback = callback.bind(this);
46966
- this.loadPage({ initial: true });
46967
- }
46968
- setup() {
46969
- var _a;
46970
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
46971
- if (!collection)
46972
- pushToCache(this.cacheKey, { data: [], params: {} });
46973
- }
46974
- async persistModel(queryPayload) {
46975
- await this.queryStreamController.saveToMainDB(queryPayload);
46976
- }
46977
- persistQueryStream({ response, direction, refresh, }) {
46978
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
46979
- }
46980
- startSubscription() {
46981
- return this.queryStreamController.subscribeRTE([
46982
- { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
46983
- { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
46984
- { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
46985
- { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
46986
- { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
46987
- { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
46988
- ]);
46989
- }
46990
- notifyChange({ origin, loading, error }) {
46991
- var _a, _b;
46992
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
46993
- if (!collection)
46994
- return;
46995
- const data = ((_b = collection.data
46996
- .map(eventId => pullFromCache(['event', 'get', eventId]))
46997
- .filter(isNonNullable)
46998
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
46999
- if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
47000
- return;
47001
- this.callback({
47002
- data,
47003
- error,
47004
- loading,
47005
- hasNextPage: !!this.paginationController.getNextToken(),
47006
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
47007
- });
47008
- }
47009
- }
47010
-
47011
- /**
47012
- * Get my events
47013
- *
47014
- * @param params the query parameters
47015
- * @param callback the callback to be called when the events are updated
47016
- * @returns events
47017
- *
47018
- * @category Event Live Collection
47019
- *
47020
- */
47021
- const getMyEvents = (params, callback, config) => {
47022
- const { log, cache } = getActiveClient();
47023
- if (!cache)
47024
- console.log(ENABLE_CACHE_MESSAGE);
47025
- const timestamp = Date.now();
47026
- log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
47027
- const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
47028
- const disposers = myEventLiveCollection.startSubscription();
47029
- const cacheKey = myEventLiveCollection.getCacheKey();
47030
- disposers.push(() => dropFromCache(cacheKey));
47031
- return () => {
47032
- log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
47033
- disposers.forEach(fn => fn());
47034
- };
47035
- };
47036
-
47037
- var index = /*#__PURE__*/Object.freeze({
47038
- __proto__: null,
47039
- createEvent: createEvent,
47040
- updateEvent: updateEvent,
47041
- deleteEvent: deleteEvent,
47042
- onEventCreated: onEventCreated,
47043
- onEventUpdated: onEventUpdated,
47044
- onEventDeleted: onEventDeleted,
47045
- onLocalEventCreated: onLocalEventCreated,
47046
- onLocalEventUpdated: onLocalEventUpdated,
47047
- onLocalEventDeleted: onLocalEventDeleted,
47048
- getEvent: getEvent,
47049
- getEvents: getEvents,
47050
- getMyEvents: getMyEvents
47051
- });
47052
-
47053
- export { API_REGIONS, index$4 as AdRepository, AmityEventOriginType, AmityEventResponseStatus, AmityEventStatus, AmityEventType, index$c as CategoryRepository, index$g as ChannelRepository, index$p as Client, index$b as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$d as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index as EventRepository, FeedDataTypeEnum, index$a as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$m as FileRepository, FileType, GET_WATCHER_URLS, index$2 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$1 as LiveReactionRepository, index$6 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$k as MessageRepository, index$7 as PollRepository, PostContentType, index$9 as PostRepository, PostStructureType, index$l as ReactionRepository, index$5 as StoryRepository, index$8 as StreamRepository, index$j as SubChannelRepository, SubscriptionLevels, index$n as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$3 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
47226
+ export { API_REGIONS, index$3 as AdRepository, index$c as CategoryRepository, index$g as ChannelRepository, index$p as Client, index$b as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$d as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, FeedDataTypeEnum, index$a as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$m as FileRepository, FileType, GET_WATCHER_URLS, index$1 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index as LiveReactionRepository, index$5 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$k as MessageRepository, index$6 as PollRepository, PostContentType, index$9 as PostRepository, PostStructureType, index$l as ReactionRepository, index$7 as RoomRepository, index$4 as StoryRepository, index$8 as StreamRepository, index$j as SubChannelRepository, SubscriptionLevels, index$n as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getRoomStreamerTopic, getRoomWatcherTopic, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$2 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };