@amityco/ts-sdk 7.11.1-38ad45e1.0 → 7.11.1-3b65d6ed.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 (136) 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/transport.d.ts +1 -4
  8. package/dist/@types/core/transport.d.ts.map +1 -1
  9. package/dist/@types/domains/content.d.ts +4 -1
  10. package/dist/@types/domains/content.d.ts.map +1 -1
  11. package/dist/@types/domains/feed.d.ts +2 -1
  12. package/dist/@types/domains/feed.d.ts.map +1 -1
  13. package/dist/@types/domains/post.d.ts +2 -0
  14. package/dist/@types/domains/post.d.ts.map +1 -1
  15. package/dist/@types/domains/room.d.ts +77 -0
  16. package/dist/@types/domains/room.d.ts.map +1 -0
  17. package/dist/@types/index.d.ts +2 -1
  18. package/dist/@types/index.d.ts.map +1 -1
  19. package/dist/channelRepository/api/createChannel.d.ts +1 -0
  20. package/dist/channelRepository/api/createChannel.d.ts.map +1 -1
  21. package/dist/core/events.d.ts +3 -3
  22. package/dist/core/events.d.ts.map +1 -1
  23. package/dist/core/model/idResolvers.d.ts.map +1 -1
  24. package/dist/core/model/index.d.ts.map +1 -1
  25. package/dist/index.cjs.js +994 -490
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.esm.js +833 -329
  29. package/dist/index.umd.js +3 -3
  30. package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
  31. package/dist/roomRepository/api/createRoom.d.ts +24 -0
  32. package/dist/roomRepository/api/createRoom.d.ts.map +1 -0
  33. package/dist/roomRepository/api/deleteRoom.d.ts +16 -0
  34. package/dist/roomRepository/api/deleteRoom.d.ts.map +1 -0
  35. package/dist/roomRepository/api/getRecordedUrl.d.ts +19 -0
  36. package/dist/roomRepository/api/getRecordedUrl.d.ts.map +1 -0
  37. package/dist/roomRepository/api/getRoomToken.d.ts +16 -0
  38. package/dist/roomRepository/api/getRoomToken.d.ts.map +1 -0
  39. package/dist/roomRepository/api/index.d.ts +7 -0
  40. package/dist/roomRepository/api/index.d.ts.map +1 -0
  41. package/dist/roomRepository/api/stopRoom.d.ts +16 -0
  42. package/dist/roomRepository/api/stopRoom.d.ts.map +1 -0
  43. package/dist/roomRepository/api/updateRoom.d.ts +24 -0
  44. package/dist/roomRepository/api/updateRoom.d.ts.map +1 -0
  45. package/dist/roomRepository/events/index.d.ts +12 -0
  46. package/dist/roomRepository/events/index.d.ts.map +1 -0
  47. package/dist/roomRepository/events/onRoomCreated.d.ts +17 -0
  48. package/dist/roomRepository/events/onRoomCreated.d.ts.map +1 -0
  49. package/dist/roomRepository/events/onRoomDeleted.d.ts +17 -0
  50. package/dist/roomRepository/events/onRoomDeleted.d.ts.map +1 -0
  51. package/dist/roomRepository/events/onRoomEndBroadcasting.d.ts +17 -0
  52. package/dist/roomRepository/events/onRoomEndBroadcasting.d.ts.map +1 -0
  53. package/dist/roomRepository/events/onRoomParticipantInviting.d.ts +17 -0
  54. package/dist/roomRepository/events/onRoomParticipantInviting.d.ts.map +1 -0
  55. package/dist/roomRepository/events/onRoomParticipantJoined.d.ts +17 -0
  56. package/dist/roomRepository/events/onRoomParticipantJoined.d.ts.map +1 -0
  57. package/dist/roomRepository/events/onRoomParticipantLeft.d.ts +17 -0
  58. package/dist/roomRepository/events/onRoomParticipantLeft.d.ts.map +1 -0
  59. package/dist/roomRepository/events/onRoomRecordedAvailable.d.ts +17 -0
  60. package/dist/roomRepository/events/onRoomRecordedAvailable.d.ts.map +1 -0
  61. package/dist/roomRepository/events/onRoomStartBroadcasting.d.ts +17 -0
  62. package/dist/roomRepository/events/onRoomStartBroadcasting.d.ts.map +1 -0
  63. package/dist/roomRepository/events/onRoomStopped.d.ts +17 -0
  64. package/dist/roomRepository/events/onRoomStopped.d.ts.map +1 -0
  65. package/dist/roomRepository/events/onRoomUpdated.d.ts +17 -0
  66. package/dist/roomRepository/events/onRoomUpdated.d.ts.map +1 -0
  67. package/dist/roomRepository/events/onRoomWaitingReconnect.d.ts +17 -0
  68. package/dist/roomRepository/events/onRoomWaitingReconnect.d.ts.map +1 -0
  69. package/dist/roomRepository/index.d.ts.map +1 -0
  70. package/dist/roomRepository/internalApi/getLiveChat.d.ts +16 -0
  71. package/dist/roomRepository/internalApi/getLiveChat.d.ts.map +1 -0
  72. package/dist/roomRepository/internalApi/getRoomById.d.ts +5 -0
  73. package/dist/roomRepository/internalApi/getRoomById.d.ts.map +1 -0
  74. package/dist/roomRepository/internalApi/index.d.ts +3 -0
  75. package/dist/roomRepository/internalApi/index.d.ts.map +1 -0
  76. package/dist/roomRepository/observers/enums.d.ts +10 -0
  77. package/dist/roomRepository/observers/enums.d.ts.map +1 -0
  78. package/dist/roomRepository/observers/getRoom.d.ts +2 -0
  79. package/dist/roomRepository/observers/getRoom.d.ts.map +1 -0
  80. package/dist/roomRepository/observers/getRooms/RoomLiveCollectionController.d.ts +14 -0
  81. package/dist/roomRepository/observers/getRooms/RoomLiveCollectionController.d.ts.map +1 -0
  82. package/dist/roomRepository/observers/getRooms/RoomPaginationController.d.ts +5 -0
  83. package/dist/roomRepository/observers/getRooms/RoomPaginationController.d.ts.map +1 -0
  84. package/dist/roomRepository/observers/getRooms/RoomQueryStreamController.d.ts +15 -0
  85. package/dist/roomRepository/observers/getRooms/RoomQueryStreamController.d.ts.map +1 -0
  86. package/dist/roomRepository/observers/getRooms.d.ts +29 -0
  87. package/dist/roomRepository/observers/getRooms.d.ts.map +1 -0
  88. package/dist/roomRepository/observers/index.d.ts +3 -0
  89. package/dist/roomRepository/observers/index.d.ts.map +1 -0
  90. package/dist/roomRepository/observers/utils.d.ts +6 -0
  91. package/dist/roomRepository/observers/utils.d.ts.map +1 -0
  92. package/dist/utils/linkedObject/index.d.ts +0 -1
  93. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  94. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  95. package/dist/utils/linkedObject/roomLinkedObject.d.ts +2 -0
  96. package/dist/utils/linkedObject/roomLinkedObject.d.ts.map +1 -0
  97. package/dist/utils/postTypePredicate.d.ts +1 -0
  98. package/dist/utils/postTypePredicate.d.ts.map +1 -1
  99. package/dist/utils/tests/dummy/comment.d.ts +1 -1
  100. package/package.json +1 -1
  101. package/dist/@types/domains/event.d.ts +0 -57
  102. package/dist/@types/domains/event.d.ts.map +0 -1
  103. package/dist/eventRepository/api/createEvent.d.ts +0 -16
  104. package/dist/eventRepository/api/createEvent.d.ts.map +0 -1
  105. package/dist/eventRepository/api/deleteEvent.d.ts +0 -16
  106. package/dist/eventRepository/api/deleteEvent.d.ts.map +0 -1
  107. package/dist/eventRepository/api/index.d.ts +0 -4
  108. package/dist/eventRepository/api/index.d.ts.map +0 -1
  109. package/dist/eventRepository/api/updateEvent.d.ts +0 -17
  110. package/dist/eventRepository/api/updateEvent.d.ts.map +0 -1
  111. package/dist/eventRepository/events/index.d.ts +0 -4
  112. package/dist/eventRepository/events/index.d.ts.map +0 -1
  113. package/dist/eventRepository/events/onEventCreated.d.ts +0 -17
  114. package/dist/eventRepository/events/onEventCreated.d.ts.map +0 -1
  115. package/dist/eventRepository/events/onEventDeleted.d.ts +0 -17
  116. package/dist/eventRepository/events/onEventDeleted.d.ts.map +0 -1
  117. package/dist/eventRepository/events/onEventUpdated.d.ts +0 -17
  118. package/dist/eventRepository/events/onEventUpdated.d.ts.map +0 -1
  119. package/dist/eventRepository/index.d.ts.map +0 -1
  120. package/dist/eventRepository/internalApi/getEvent.d.ts +0 -32
  121. package/dist/eventRepository/internalApi/getEvent.d.ts.map +0 -1
  122. package/dist/eventRepository/internalApi/index.d.ts +0 -2
  123. package/dist/eventRepository/internalApi/index.d.ts.map +0 -1
  124. package/dist/eventRepository/observers/getEvent.d.ts +0 -21
  125. package/dist/eventRepository/observers/getEvent.d.ts.map +0 -1
  126. package/dist/eventRepository/observers/index.d.ts +0 -2
  127. package/dist/eventRepository/observers/index.d.ts.map +0 -1
  128. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +0 -2
  129. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +0 -1
  130. package/dist/eventRepository/utils/index.d.ts +0 -3
  131. package/dist/eventRepository/utils/index.d.ts.map +0 -1
  132. package/dist/eventRepository/utils/prepareEventPayload.d.ts +0 -2
  133. package/dist/eventRepository/utils/prepareEventPayload.d.ts.map +0 -1
  134. package/dist/utils/linkedObject/eventLinkObject.d.ts +0 -2
  135. package/dist/utils/linkedObject/eventLinkObject.d.ts.map +0 -1
  136. /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,24 +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
-
198
182
  function getVersion() {
199
183
  try {
200
184
  // the string ''v7.11.0-esm'' should be replaced by actual value by @rollup/plugin-replace
@@ -643,6 +627,7 @@ const idResolvers = {
643
627
  notificationTraySeen: ({ userId }) => userId,
644
628
  invitation: ({ _id }) => _id,
645
629
  joinRequest: ({ joinRequestId }) => joinRequestId,
630
+ room: ({ roomId }) => roomId,
646
631
  };
647
632
  /**
648
633
  * Retrieve the id resolver matching a domain name
@@ -698,6 +683,7 @@ const PAYLOAD2MODEL = {
698
683
  notificationTrayItems: 'notificationTrayItem',
699
684
  invitations: 'invitation',
700
685
  joinRequests: 'joinRequest',
686
+ rooms: 'room',
701
687
  };
702
688
  /** hidden */
703
689
  const isOutdated = (prevData, nextData) => {
@@ -28142,7 +28128,7 @@ getChannel$1.locally = (channelId) => {
28142
28128
  * @category Stream API
28143
28129
  * @async
28144
28130
  */
28145
- const getLiveChat = async (stream) => {
28131
+ const getLiveChat$1 = async (stream) => {
28146
28132
  var _a;
28147
28133
  const client = getActiveClient();
28148
28134
  client.log('stream/getLiveChat', stream.streamId);
@@ -28209,7 +28195,7 @@ const streamLinkedObject = (stream) => {
28209
28195
  return streamLinkedObject(streamCache);
28210
28196
  })
28211
28197
  .filter(isNonNullable);
28212
- }, getLiveChat: () => getLiveChat(stream), isBanned: !stream.watcherUrl, watcherUrl: null, get [GET_WATCHER_URLS]() {
28198
+ }, getLiveChat: () => getLiveChat$1(stream), isBanned: !stream.watcherUrl, watcherUrl: null, get [GET_WATCHER_URLS]() {
28213
28199
  return stream.watcherUrl;
28214
28200
  } });
28215
28201
  };
@@ -28317,6 +28303,95 @@ function isAmityAudioPost(post) {
28317
28303
  'fileId' in post.data &&
28318
28304
  post.dataType === 'audio');
28319
28305
  }
28306
+ function isAmityRoomPost(post) {
28307
+ return !!(post.data &&
28308
+ typeof post.data !== 'string' &&
28309
+ 'roomId' in post.data &&
28310
+ post.dataType === 'room');
28311
+ }
28312
+
28313
+ /**
28314
+ * ```js
28315
+ * import { RoomRepository } from '@amityco/ts-sdk'
28316
+ * const stream = await getStream('foobar')
28317
+ * ```
28318
+ *
28319
+ * Fetches a {@link Amity.Channel} object linked with a current stream
28320
+ *
28321
+ * @param stream {@link Amity.Stream} that has linked live channel
28322
+ * @returns the associated {@link Amity.Channel<'live'>} object
28323
+ *
28324
+ * @category Stream API
28325
+ * @async
28326
+ */
28327
+ const getLiveChat = async (room) => {
28328
+ var _a;
28329
+ const client = getActiveClient();
28330
+ client.log('room/getLiveChat', room.roomId);
28331
+ if (room.liveChannelId) {
28332
+ const channel = (_a = pullFromCache([
28333
+ 'channel',
28334
+ 'get',
28335
+ room.liveChannelId,
28336
+ ])) === null || _a === void 0 ? void 0 : _a.data;
28337
+ if (channel)
28338
+ return channelLinkedObject(constructChannelObject(channel));
28339
+ const { data } = await getChannel$1(room.liveChannelId);
28340
+ return channelLinkedObject(constructChannelObject(data));
28341
+ }
28342
+ // No Channel ID
28343
+ // streamer: create a new live channel
28344
+ if (room.createdBy === client.userId) {
28345
+ const { data: channel } = await createChannel({
28346
+ type: 'live',
28347
+ postId: room.referenceId,
28348
+ roomId: room.roomId,
28349
+ });
28350
+ // Update channelId to stream object in cache
28351
+ mergeInCache(['room', 'get', room.roomId], {
28352
+ liveChannelId: channel.channelId,
28353
+ });
28354
+ return channel;
28355
+ }
28356
+ // watcher: return undefined
28357
+ return undefined;
28358
+ };
28359
+
28360
+ const roomLinkedObject = (room) => {
28361
+ return Object.assign(Object.assign({}, room), { get moderation() {
28362
+ var _a;
28363
+ return (_a = pullFromCache(['roomModeration', 'get', room.roomId])) === null || _a === void 0 ? void 0 : _a.data;
28364
+ },
28365
+ get post() {
28366
+ var _a;
28367
+ if (room.referenceType !== 'post')
28368
+ return;
28369
+ return (_a = pullFromCache(['post', 'get', room.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
28370
+ },
28371
+ get community() {
28372
+ var _a;
28373
+ if (room.targetType !== 'community')
28374
+ return;
28375
+ return (_a = pullFromCache(['community', 'get', room.targetId])) === null || _a === void 0 ? void 0 : _a.data;
28376
+ },
28377
+ get user() {
28378
+ var _a;
28379
+ return (_a = pullFromCache(['user', 'get', room.createdBy])) === null || _a === void 0 ? void 0 : _a.data;
28380
+ },
28381
+ get childRooms() {
28382
+ if (!room.childRoomIds || room.childRoomIds.length === 0)
28383
+ return [];
28384
+ return room.childRoomIds
28385
+ .map(id => {
28386
+ var _a;
28387
+ const roomCache = (_a = pullFromCache(['room', 'get', id])) === null || _a === void 0 ? void 0 : _a.data;
28388
+ if (!roomCache)
28389
+ return undefined;
28390
+ return roomLinkedObject(roomCache);
28391
+ })
28392
+ .filter(isNonNullable);
28393
+ }, getLiveChat: () => getLiveChat(room) });
28394
+ };
28320
28395
 
28321
28396
  const postLinkedObject = (post) => {
28322
28397
  return shallowClone(post, {
@@ -28411,6 +28486,13 @@ const postLinkedObject = (post) => {
28411
28486
  ? (_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
28412
28487
  : undefined;
28413
28488
  },
28489
+ getRoomInfo() {
28490
+ var _a, _b;
28491
+ if (!isAmityRoomPost(post))
28492
+ return;
28493
+ 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;
28494
+ return room ? roomLinkedObject(room) : undefined;
28495
+ },
28414
28496
  });
28415
28497
  };
28416
28498
 
@@ -29768,31 +29850,6 @@ const communityLinkedObject = (community) => {
29768
29850
  } });
29769
29851
  };
29770
29852
 
29771
- const eventLinkedObject = (event) => {
29772
- return Object.assign(Object.assign({}, event), { get creator() {
29773
- const cacheData = pullFromCache(['user', 'get', event.userId]);
29774
- if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29775
- return;
29776
- return userLinkedObject(cacheData.data);
29777
- },
29778
- get discussionCommunity() {
29779
- if (!event.communityId)
29780
- return;
29781
- const cacheData = pullFromCache(['community', 'get', event.communityId]);
29782
- if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29783
- return;
29784
- return communityLinkedObject(cacheData.data);
29785
- },
29786
- get liveStream() {
29787
- if (!event.livestreamId)
29788
- return;
29789
- const cacheData = pullFromCache(['stream', 'get', event.livestreamId]);
29790
- if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29791
- return;
29792
- return cacheData.data;
29793
- } });
29794
- };
29795
-
29796
29853
  const LinkedObject = {
29797
29854
  ad: adLinkedObject,
29798
29855
  comment: commentLinkedObject,
@@ -29811,7 +29868,6 @@ const LinkedObject = {
29811
29868
  invitation: invitationLinkedObject,
29812
29869
  joinRequest: joinRequestLinkedObject,
29813
29870
  channelMember: channelMemberLinkedObject,
29814
- event: eventLinkedObject,
29815
29871
  };
29816
29872
 
29817
29873
  /* begin_public_function
@@ -43796,6 +43852,729 @@ var index$8 = /*#__PURE__*/Object.freeze({
43796
43852
  getStreams: getStreams
43797
43853
  });
43798
43854
 
43855
+ /* begin_public_function
43856
+ id: room.create
43857
+ */
43858
+ /**
43859
+ * ```js
43860
+ * import { createRoom } from '@amityco/ts-sdk'
43861
+ * const created = await createRoom({ title: 'my room', 'thumbnailFileId': fileId })
43862
+ * ```
43863
+ *
43864
+ * Creates an {@link Amity.Room}
43865
+ *
43866
+ * @param bundle The data necessary to create a new {@link Amity.Room}
43867
+ * @returns The newly created {@link Amity.Room}
43868
+ *
43869
+ * @category Room API
43870
+ * @async
43871
+ */
43872
+ const createRoom = async (bundle) => {
43873
+ const client = getActiveClient();
43874
+ client.log('room/createRoom', bundle);
43875
+ const { data } = await client.http.post('/api/v1/rooms', bundle);
43876
+ fireEvent('local.room.created', data);
43877
+ const cachedAt = client.cache && Date.now();
43878
+ // TODO: check if should pick `users` filed which contains participants - if no need to ingest in the cache
43879
+ if (client.cache)
43880
+ ingestInCache(data, { cachedAt });
43881
+ const { rooms } = data;
43882
+ return {
43883
+ data: roomLinkedObject(rooms[0]),
43884
+ cachedAt,
43885
+ };
43886
+ };
43887
+ /* end_public_function */
43888
+
43889
+ /* begin_public_function
43890
+ id: room.update
43891
+ */
43892
+ /**
43893
+ * ```js
43894
+ * import { updateRoom } from '@amityco/ts-sdk'
43895
+ * const updated = await updateRoom('roomId', { title: 'updated title' })
43896
+ * ```
43897
+ *
43898
+ * Updates an {@link Amity.InternalRoom}
43899
+ *
43900
+ * @param roomId The ID of the room to update
43901
+ * @param bundle The data to update the room with
43902
+ * @returns The updated {@link Amity.InternalRoom}
43903
+ *
43904
+ * @category Room API
43905
+ * @async
43906
+ */
43907
+ const updateRoom = async (roomId, bundle) => {
43908
+ const client = getActiveClient();
43909
+ client.log('room/updateRoom', { roomId, bundle });
43910
+ const { data } = await client.http.put(`/api/v1/rooms/${roomId}`, bundle);
43911
+ fireEvent('local.room.updated', data);
43912
+ const cachedAt = client.cache && Date.now();
43913
+ if (client.cache)
43914
+ ingestInCache(data, { cachedAt });
43915
+ const { rooms } = data;
43916
+ return {
43917
+ data: rooms[0],
43918
+ cachedAt,
43919
+ };
43920
+ };
43921
+ /* end_public_function */
43922
+
43923
+ /* begin_public_function
43924
+ id: room.delete
43925
+ */
43926
+ /**
43927
+ * ```js
43928
+ * import { deleteRoom } from '@amityco/ts-sdk'
43929
+ * const result = await deleteRoom('roomId')
43930
+ * ```
43931
+ *
43932
+ * Deletes an {@link Amity.Room}
43933
+ *
43934
+ * @param roomId The ID of the room to delete
43935
+ * @returns Promise that resolves when the room is deleted
43936
+ *
43937
+ * @category Room API
43938
+ * @async
43939
+ */
43940
+ const deleteRoom = async (roomId) => {
43941
+ const client = getActiveClient();
43942
+ client.log('room/deleteRoom', { roomId });
43943
+ await client.http.delete(`/api/v1/rooms/${roomId}`);
43944
+ fireEvent('local.room.deleted', { rooms: [{ _id: roomId }] });
43945
+ };
43946
+ /* end_public_function */
43947
+
43948
+ /* begin_public_function
43949
+ id: room.stop
43950
+ */
43951
+ /**
43952
+ * ```js
43953
+ * import { stopRoom } from '@amityco/ts-sdk'
43954
+ * const result = await stopRoom('roomId')
43955
+ * ```
43956
+ *
43957
+ * Stops a room's broadcasting
43958
+ *
43959
+ * @param roomId The ID of the room to stop
43960
+ * @returns The updated room data
43961
+ *
43962
+ * @category Room API
43963
+ * @async
43964
+ */
43965
+ const stopRoom = async (roomId) => {
43966
+ const client = getActiveClient();
43967
+ client.log('room/stopRoom', { roomId });
43968
+ const { data } = await client.http.post(`/api/v1/rooms/${roomId}/stop`);
43969
+ fireEvent('local.room.stopped', data);
43970
+ const cachedAt = client.cache && Date.now();
43971
+ if (client.cache)
43972
+ ingestInCache(data, { cachedAt });
43973
+ const { rooms } = data;
43974
+ return {
43975
+ data: rooms[0],
43976
+ cachedAt,
43977
+ };
43978
+ };
43979
+ /* end_public_function */
43980
+
43981
+ /* begin_public_function
43982
+ id: room.getBroadcasterData
43983
+ */
43984
+ /**
43985
+ * ```js
43986
+ * import { getBroadcasterData } from '@amityco/ts-sdk'
43987
+ * const token = await getBroadcasterData('roomId')
43988
+ * ```
43989
+ *
43990
+ * Gets an access token for a room
43991
+ *
43992
+ * @param roomId The ID of the room to get token for
43993
+ * @returns The room access token
43994
+ *
43995
+ * @category Room API
43996
+ * @async
43997
+ */
43998
+ const getBroadcasterData = async (roomId) => {
43999
+ const client = getActiveClient();
44000
+ client.log('room/getBroadcasterData', { roomId });
44001
+ const { data } = await client.http.get(`/api/v1/rooms/${roomId}/token`);
44002
+ return data;
44003
+ };
44004
+ /* end_public_function */
44005
+
44006
+ /* begin_public_function
44007
+ id: room.getRecordedUrl
44008
+ */
44009
+ /**
44010
+ * ```js
44011
+ * import { getRecordedUrl } from '@amityco/ts-sdk'
44012
+ * const recordedUrl = await getRecordedUrl('roomId')
44013
+ * ```
44014
+ *
44015
+ * Gets the recorded URL for a room
44016
+ *
44017
+ * @param roomId The ID of the room to get recorded URL for
44018
+ * @returns The recorded URL information
44019
+ *
44020
+ * @category Room API
44021
+ * @async
44022
+ */
44023
+ const getRecordedUrl = async (roomId) => {
44024
+ const client = getActiveClient();
44025
+ client.log('room/getRecordedUrl', { roomId });
44026
+ const { data } = await client.http.get(`/api/v1/rooms/${roomId}/recorded`);
44027
+ return data;
44028
+ };
44029
+ /* end_public_function */
44030
+
44031
+ /**
44032
+ * ```js
44033
+ * import { onRoomStartBroadcasting } from '@amityco/ts-sdk'
44034
+ * const dispose = onRoomStartBroadcasting(room => {
44035
+ * // ...
44036
+ * })
44037
+ * ```
44038
+ *
44039
+ * Fired when a {@link Amity.Room} has started broadcasting
44040
+ *
44041
+ * @param callback The function to call when the event was fired
44042
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44043
+ *
44044
+ * @category Room Events
44045
+ */
44046
+ const onRoomStartBroadcasting = (callback) => {
44047
+ const client = getActiveClient();
44048
+ const filter = (payload) => {
44049
+ ingestInCache(payload);
44050
+ callback(payload.rooms[0]);
44051
+ };
44052
+ return createEventSubscriber(client, 'room/onRoomStartBroadcasting', 'room.startBroadcasting', filter);
44053
+ };
44054
+
44055
+ /**
44056
+ * ```js
44057
+ * import { onRoomWaitingReconnect } from '@amityco/ts-sdk'
44058
+ * const dispose = onRoomWaitingReconnect(room => {
44059
+ * // ...
44060
+ * })
44061
+ * ```
44062
+ *
44063
+ * Fired when a {@link Amity.Room} is waiting for reconnection
44064
+ *
44065
+ * @param callback The function to call when the event was fired
44066
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44067
+ *
44068
+ * @category Room Events
44069
+ */
44070
+ const onRoomWaitingReconnect = (callback) => {
44071
+ const client = getActiveClient();
44072
+ const filter = (payload) => {
44073
+ ingestInCache(payload);
44074
+ callback(payload.rooms[0]);
44075
+ };
44076
+ return createEventSubscriber(client, 'room/onRoomWaitingReconnect', 'room.waitingReconnect', filter);
44077
+ };
44078
+
44079
+ /**
44080
+ * ```js
44081
+ * import { onRoomEndBroadcasting } from '@amityco/ts-sdk'
44082
+ * const dispose = onRoomEndBroadcasting(room => {
44083
+ * // ...
44084
+ * })
44085
+ * ```
44086
+ *
44087
+ * Fired when a {@link Amity.Room} has ended broadcasting
44088
+ *
44089
+ * @param callback The function to call when the event was fired
44090
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44091
+ *
44092
+ * @category Room Events
44093
+ */
44094
+ const onRoomEndBroadcasting = (callback) => {
44095
+ const client = getActiveClient();
44096
+ const filter = (payload) => {
44097
+ ingestInCache(payload);
44098
+ callback(payload.rooms[0]);
44099
+ };
44100
+ return createEventSubscriber(client, 'room/onRoomEndBroadcasting', 'room.endBroadcasting', filter);
44101
+ };
44102
+
44103
+ /**
44104
+ * ```js
44105
+ * import { onRoomRecordedAvailable } from '@amityco/ts-sdk'
44106
+ * const dispose = onRoomRecordedAvailable(room => {
44107
+ * // ...
44108
+ * })
44109
+ * ```
44110
+ *
44111
+ * Fired when a {@link Amity.Room} recorded content becomes available
44112
+ *
44113
+ * @param callback The function to call when the event was fired
44114
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44115
+ *
44116
+ * @category Room Events
44117
+ */
44118
+ const onRoomRecordedAvailable = (callback) => {
44119
+ const client = getActiveClient();
44120
+ const filter = (payload) => {
44121
+ ingestInCache(payload);
44122
+ callback(payload.rooms[0]);
44123
+ };
44124
+ return createEventSubscriber(client, 'room/onRoomRecordedAvailable', 'room.recordedAvailable', filter);
44125
+ };
44126
+
44127
+ /**
44128
+ * ```js
44129
+ * import { onRoomParticipantInviting } from '@amityco/ts-sdk'
44130
+ * const dispose = onRoomParticipantInviting(room => {
44131
+ * // ...
44132
+ * })
44133
+ * ```
44134
+ *
44135
+ * Fired when a participant is being invited to a {@link Amity.Room}
44136
+ *
44137
+ * @param callback The function to call when the event was fired
44138
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44139
+ *
44140
+ * @category Room Events
44141
+ */
44142
+ const onRoomParticipantInviting = (callback) => {
44143
+ const client = getActiveClient();
44144
+ const filter = (payload) => {
44145
+ ingestInCache(payload);
44146
+ callback(payload.rooms[0]);
44147
+ };
44148
+ return createEventSubscriber(client, 'room/onRoomParticipantInviting', 'room.participantInviting', filter);
44149
+ };
44150
+
44151
+ /**
44152
+ * ```js
44153
+ * import { onRoomParticipantJoined } from '@amityco/ts-sdk'
44154
+ * const dispose = onRoomParticipantJoined(room => {
44155
+ * // ...
44156
+ * })
44157
+ * ```
44158
+ *
44159
+ * Fired when a participant has joined a {@link Amity.Room}
44160
+ *
44161
+ * @param callback The function to call when the event was fired
44162
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44163
+ *
44164
+ * @category Room Events
44165
+ */
44166
+ const onRoomParticipantJoined = (callback) => {
44167
+ const client = getActiveClient();
44168
+ const filter = (payload) => {
44169
+ ingestInCache(payload);
44170
+ callback(payload.rooms[0]);
44171
+ };
44172
+ return createEventSubscriber(client, 'room/onRoomParticipantJoined', 'room.participantJoined', filter);
44173
+ };
44174
+
44175
+ /**
44176
+ * ```js
44177
+ * import { onRoomParticipantLeft } from '@amityco/ts-sdk'
44178
+ * const dispose = onRoomParticipantLeft(room => {
44179
+ * // ...
44180
+ * })
44181
+ * ```
44182
+ *
44183
+ * Fired when a participant has left a {@link Amity.Room}
44184
+ *
44185
+ * @param callback The function to call when the event was fired
44186
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44187
+ *
44188
+ * @category Room Events
44189
+ */
44190
+ const onRoomParticipantLeft = (callback) => {
44191
+ const client = getActiveClient();
44192
+ const filter = (payload) => {
44193
+ ingestInCache(payload);
44194
+ callback(payload.rooms[0]);
44195
+ };
44196
+ return createEventSubscriber(client, 'room/onRoomParticipantLeft', 'room.participantLeft', filter);
44197
+ };
44198
+
44199
+ /**
44200
+ * ```js
44201
+ * import { onRoomCreated } from '@amityco/ts-sdk'
44202
+ * const dispose = onRoomCreated(room => {
44203
+ * // ...
44204
+ * })
44205
+ * ```
44206
+ *
44207
+ * Fired when a {@link Amity.Room} has been created locally
44208
+ *
44209
+ * @param callback The function to call when the event was fired
44210
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44211
+ *
44212
+ * @category Room Events
44213
+ */
44214
+ const onRoomCreated = (callback) => {
44215
+ const client = getActiveClient();
44216
+ const filter = (payload) => {
44217
+ ingestInCache(payload);
44218
+ callback(payload.rooms[0]);
44219
+ };
44220
+ return createEventSubscriber(client, 'room/onRoomCreated', 'local.room.created', filter);
44221
+ };
44222
+
44223
+ /**
44224
+ * ```js
44225
+ * import { onRoomUpdated } from '@amityco/ts-sdk'
44226
+ * const dispose = onRoomUpdated(room => {
44227
+ * // ...
44228
+ * })
44229
+ * ```
44230
+ *
44231
+ * Fired when a {@link Amity.Room} has been updated locally
44232
+ *
44233
+ * @param callback The function to call when the event was fired
44234
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44235
+ *
44236
+ * @category Room Events
44237
+ */
44238
+ const onRoomUpdated = (callback) => {
44239
+ const client = getActiveClient();
44240
+ const filter = (payload) => {
44241
+ ingestInCache(payload);
44242
+ callback(payload.rooms[0]);
44243
+ };
44244
+ return createEventSubscriber(client, 'room/onRoomUpdated', 'local.room.updated', filter);
44245
+ };
44246
+
44247
+ /**
44248
+ * ```js
44249
+ * import { onRoomDeleted } from '@amityco/ts-sdk'
44250
+ * const dispose = onRoomDeleted(room => {
44251
+ * // ...
44252
+ * })
44253
+ * ```
44254
+ *
44255
+ * Fired when a {@link Amity.Room} has been deleted locally
44256
+ *
44257
+ * @param callback The function to call when the event was fired
44258
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44259
+ *
44260
+ * @category Room Events
44261
+ */
44262
+ const onRoomDeleted = (callback) => {
44263
+ const client = getActiveClient();
44264
+ const filter = (payload) => {
44265
+ ingestInCache(payload);
44266
+ callback(payload.rooms[0]);
44267
+ };
44268
+ return createEventSubscriber(client, 'room/onRoomDeleted', 'local.room.deleted', filter);
44269
+ };
44270
+
44271
+ /**
44272
+ * ```js
44273
+ * import { onRoomStopped } from '@amityco/ts-sdk'
44274
+ * const dispose = onRoomStopped(room => {
44275
+ * // ...
44276
+ * })
44277
+ * ```
44278
+ *
44279
+ * Fired when a {@link Amity.Room} has been stopped locally
44280
+ *
44281
+ * @param callback The function to call when the event was fired
44282
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
44283
+ *
44284
+ * @category Room Events
44285
+ */
44286
+ const onRoomStopped = (callback) => {
44287
+ const client = getActiveClient();
44288
+ const filter = (payload) => {
44289
+ ingestInCache(payload);
44290
+ callback(payload.rooms[0]);
44291
+ };
44292
+ return createEventSubscriber(client, 'room/onRoomStopped', 'local.room.stopped', filter);
44293
+ };
44294
+
44295
+ const getRoomById = async (roomId) => {
44296
+ const client = getActiveClient();
44297
+ client.log('room/getRoomById', roomId);
44298
+ // Check if room is in tombstone
44299
+ isInTombstone('room', roomId);
44300
+ let data;
44301
+ try {
44302
+ const response = await client.http.get(`/api/v1/rooms/${roomId}`);
44303
+ data = response.data;
44304
+ }
44305
+ catch (error) {
44306
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
44307
+ pushToTombstone('room', roomId);
44308
+ }
44309
+ throw error;
44310
+ }
44311
+ const cachedAt = client.cache && Date.now();
44312
+ if (client.cache) {
44313
+ ingestInCache(data, { cachedAt });
44314
+ }
44315
+ return {
44316
+ data: data.rooms[0],
44317
+ cachedAt,
44318
+ };
44319
+ };
44320
+ getRoomById.locally = (roomId) => {
44321
+ const client = getActiveClient();
44322
+ client.log('room/getRoomById.locally', roomId);
44323
+ // Check if room is in tombstone
44324
+ isInTombstone('room', roomId);
44325
+ const cachedAt = client.cache && Date.now();
44326
+ const roomCache = pullFromCache(['room', 'get', roomId]);
44327
+ if (!roomCache)
44328
+ return;
44329
+ return {
44330
+ data: roomCache.data,
44331
+ cachedAt,
44332
+ };
44333
+ };
44334
+
44335
+ const getRoom = (roomId, callback) => {
44336
+ // TODO: add callbackDataSelector if there are linked object fields
44337
+ return liveObject(roomId, callback, '_id', getRoomById, [
44338
+ onRoomEndBroadcasting,
44339
+ onRoomStartBroadcasting,
44340
+ onRoomWaitingReconnect,
44341
+ onRoomRecordedAvailable,
44342
+ ]);
44343
+ };
44344
+
44345
+ class RoomPaginationController extends PaginationController {
44346
+ async getRequest(queryParams, token) {
44347
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
44348
+ const baseOptions = {
44349
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
44350
+ };
44351
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
44352
+ const { data: queryResponse } = await this.http.get(`/api/v1/rooms`, {
44353
+ params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
44354
+ });
44355
+ return queryResponse;
44356
+ }
44357
+ }
44358
+
44359
+ var EnumRoomActions;
44360
+ (function (EnumRoomActions) {
44361
+ EnumRoomActions["OnRoomCreated"] = "OnRoomCreated";
44362
+ EnumRoomActions["OnRoomUpdated"] = "OnRoomUpdated";
44363
+ EnumRoomActions["OnRoomDeleted"] = "OnRoomDeleted";
44364
+ EnumRoomActions["OnRoomStartBroadcasting"] = "OnRoomStartBroadcasting";
44365
+ EnumRoomActions["OnRoomEndBroadcasting"] = "OnRoomEndBroadcasting";
44366
+ EnumRoomActions["OnRoomParticipantJoined"] = "OnRoomParticipantJoined";
44367
+ EnumRoomActions["OnRoomParticipantLeft"] = "OnRoomParticipantLeft";
44368
+ })(EnumRoomActions || (EnumRoomActions = {}));
44369
+
44370
+ class RoomQueryStreamController extends QueryStreamController {
44371
+ constructor(query, cacheKey, notifyChange, preparePayload) {
44372
+ super(query, cacheKey);
44373
+ this.notifyChange = notifyChange;
44374
+ this.preparePayload = preparePayload;
44375
+ }
44376
+ async saveToMainDB(response) {
44377
+ const processedPayload = await this.preparePayload(response);
44378
+ const client = getActiveClient();
44379
+ const cachedAt = client.cache && Date.now();
44380
+ if (client.cache) {
44381
+ ingestInCache(processedPayload, { cachedAt });
44382
+ }
44383
+ }
44384
+ appendToQueryStream(response, direction, refresh = false) {
44385
+ var _a, _b;
44386
+ if (refresh) {
44387
+ pushToCache(this.cacheKey, {
44388
+ data: response.rooms.map(getResolver('room')),
44389
+ });
44390
+ }
44391
+ else {
44392
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44393
+ const rooms = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
44394
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...rooms, ...response.rooms.map(getResolver('room'))])] }));
44395
+ }
44396
+ }
44397
+ reactor(action) {
44398
+ return (room) => {
44399
+ var _a;
44400
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44401
+ if (!collection)
44402
+ return;
44403
+ if (action === EnumRoomActions.OnRoomDeleted) {
44404
+ collection.data = collection.data.filter(roomId => roomId !== room._id);
44405
+ }
44406
+ if (action === EnumRoomActions.OnRoomCreated) {
44407
+ collection.data = [...new Set([room._id, ...collection.data])];
44408
+ }
44409
+ pushToCache(this.cacheKey, collection);
44410
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
44411
+ };
44412
+ }
44413
+ subscribeRTE(createSubscriber) {
44414
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
44415
+ }
44416
+ }
44417
+
44418
+ // TODO: confirm related events
44419
+ const getRoomSubscription = () => [
44420
+ {
44421
+ fn: onRoomStartBroadcasting,
44422
+ action: EnumRoomActions.OnRoomStartBroadcasting,
44423
+ },
44424
+ {
44425
+ fn: onRoomEndBroadcasting,
44426
+ action: EnumRoomActions.OnRoomEndBroadcasting,
44427
+ },
44428
+ {
44429
+ fn: onRoomRecordedAvailable,
44430
+ action: EnumRoomActions.OnRoomUpdated,
44431
+ },
44432
+ ];
44433
+
44434
+ class RoomLiveCollectionController extends LiveCollectionController {
44435
+ constructor(query, callback) {
44436
+ const queryStreamId = hash(query);
44437
+ const cacheKey = ['rooms', 'collection', queryStreamId];
44438
+ const paginationController = new RoomPaginationController(query);
44439
+ super(paginationController, queryStreamId, cacheKey, callback);
44440
+ this.query = query;
44441
+ this.queryStreamController = new RoomQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
44442
+ this.callback = callback.bind(this);
44443
+ this.loadPage({ initial: true });
44444
+ }
44445
+ setup() {
44446
+ var _a;
44447
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44448
+ if (!collection) {
44449
+ pushToCache(this.cacheKey, {
44450
+ data: [],
44451
+ params: {},
44452
+ });
44453
+ }
44454
+ }
44455
+ async persistModel(queryPayload) {
44456
+ await this.queryStreamController.saveToMainDB(queryPayload);
44457
+ }
44458
+ persistQueryStream({ response, direction, refresh, }) {
44459
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
44460
+ }
44461
+ startSubscription() {
44462
+ return this.queryStreamController.subscribeRTE(getRoomSubscription());
44463
+ }
44464
+ notifyChange({ origin, loading, error }) {
44465
+ var _a, _b;
44466
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44467
+ if (!collection)
44468
+ return;
44469
+ const data = this.applyFilter((_b = collection.data
44470
+ .map(id => pullFromCache(['room', 'get', id]))
44471
+ .filter(isNonNullable)
44472
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(room => room); // Since Room is same as InternalRoom, no transformation needed
44473
+ if (!this.shouldNotify(data) && origin === 'event')
44474
+ return;
44475
+ this.callback({
44476
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
44477
+ data,
44478
+ hasNextPage: !!this.paginationController.getNextToken(),
44479
+ loading,
44480
+ error,
44481
+ });
44482
+ }
44483
+ applyFilter(data) {
44484
+ let rooms = data;
44485
+ if (!this.query.includeDeleted) {
44486
+ rooms = filterByPropEquality(rooms, 'isDeleted', false);
44487
+ }
44488
+ if (this.query.statuses && this.query.statuses.length > 0) {
44489
+ rooms = rooms.filter(room => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(room.status); });
44490
+ }
44491
+ if (this.query.type) {
44492
+ rooms = filterByPropEquality(rooms, 'type', this.query.type);
44493
+ }
44494
+ switch (this.query.sortBy) {
44495
+ case 'firstCreated':
44496
+ rooms = rooms.sort(sortByFirstCreated);
44497
+ break;
44498
+ case 'lastCreated':
44499
+ default:
44500
+ rooms = rooms.sort(sortByLastCreated);
44501
+ break;
44502
+ }
44503
+ return rooms;
44504
+ }
44505
+ }
44506
+
44507
+ /* begin_public_function
44508
+ id: room.get_rooms
44509
+ */
44510
+ /**
44511
+ * ```js
44512
+ * import { RoomRepository } from '@amityco/ts-sdk'
44513
+ *
44514
+ * let rooms = []
44515
+ * const unsub = RoomRepository.getRooms({
44516
+ * type: 'direct_streaming',
44517
+ * statuses: ['live', 'idle'],
44518
+ * sortBy: 'lastCreated',
44519
+ * limit: 20,
44520
+ * includeDeleted: false
44521
+ * }, response => merge(rooms, response.data))
44522
+ * ```
44523
+ *
44524
+ * Observe all mutations on a list of {@link Amity.Room} for a given query
44525
+ *
44526
+ * @param params.type the type of rooms to filter by ('direct_streaming' | 'co_hosts')
44527
+ * @param params.statuses array of room statuses to filter by (['idle', 'live', 'waiting_reconnect', 'ended', 'recorded'])
44528
+ * @param params.sortBy sort rooms by creation time ('firstCreated' | 'lastCreated')
44529
+ * @param params.limit maximum number of rooms to retrieve per page
44530
+ * @param params.includeDeleted whether to include deleted rooms in the results
44531
+ * @param callback the function to call when new data are available
44532
+ * @param config optional configuration for the live collection
44533
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the rooms
44534
+ *
44535
+ * @category Rooms Live Collection
44536
+ */
44537
+ const getRooms = (params, callback, config) => {
44538
+ const { log, cache } = getActiveClient();
44539
+ if (!cache) {
44540
+ console.log(ENABLE_CACHE_MESSAGE);
44541
+ }
44542
+ const timestamp = Date.now();
44543
+ log(`getRooms(tmpid: ${timestamp}) > listen`);
44544
+ const roomsLiveCollection = new RoomLiveCollectionController(params, callback);
44545
+ const disposers = roomsLiveCollection.startSubscription();
44546
+ const cacheKey = roomsLiveCollection.getCacheKey();
44547
+ disposers.push(() => dropFromCache(cacheKey));
44548
+ return () => {
44549
+ log(`getRooms(tmpid: ${timestamp}) > dispose`);
44550
+ disposers.forEach(fn => fn());
44551
+ };
44552
+ };
44553
+ /* end_public_function */
44554
+
44555
+ var index$7 = /*#__PURE__*/Object.freeze({
44556
+ __proto__: null,
44557
+ createRoom: createRoom,
44558
+ updateRoom: updateRoom,
44559
+ deleteRoom: deleteRoom,
44560
+ stopRoom: stopRoom,
44561
+ getBroadcasterData: getBroadcasterData,
44562
+ getRecordedUrl: getRecordedUrl,
44563
+ onRoomStartBroadcasting: onRoomStartBroadcasting,
44564
+ onRoomWaitingReconnect: onRoomWaitingReconnect,
44565
+ onRoomEndBroadcasting: onRoomEndBroadcasting,
44566
+ onRoomRecordedAvailable: onRoomRecordedAvailable,
44567
+ onRoomParticipantInviting: onRoomParticipantInviting,
44568
+ onRoomParticipantJoined: onRoomParticipantJoined,
44569
+ onRoomParticipantLeft: onRoomParticipantLeft,
44570
+ onRoomCreated: onRoomCreated,
44571
+ onRoomUpdated: onRoomUpdated,
44572
+ onRoomDeleted: onRoomDeleted,
44573
+ onRoomStopped: onRoomStopped,
44574
+ getRoom: getRoom,
44575
+ getRooms: getRooms
44576
+ });
44577
+
43799
44578
  /* begin_public_function
43800
44579
  id: poll.create
43801
44580
  */
@@ -44096,7 +44875,7 @@ const getPoll = (pollId, callback) => {
44096
44875
  };
44097
44876
  /* end_public_function */
44098
44877
 
44099
- var index$7 = /*#__PURE__*/Object.freeze({
44878
+ var index$6 = /*#__PURE__*/Object.freeze({
44100
44879
  __proto__: null,
44101
44880
  createPoll: createPoll,
44102
44881
  closePoll: closePoll,
@@ -44479,7 +45258,7 @@ const getPlayer = async (parameters) => {
44479
45258
  return video;
44480
45259
  };
44481
45260
 
44482
- var index$6 = /*#__PURE__*/Object.freeze({
45261
+ var index$5 = /*#__PURE__*/Object.freeze({
44483
45262
  __proto__: null,
44484
45263
  getPlayer: getPlayer
44485
45264
  });
@@ -45652,7 +46431,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
45652
46431
  };
45653
46432
  };
45654
46433
 
45655
- var index$5 = /*#__PURE__*/Object.freeze({
46434
+ var index$4 = /*#__PURE__*/Object.freeze({
45656
46435
  __proto__: null,
45657
46436
  createImageStory: createImageStory,
45658
46437
  createVideoStory: createVideoStory,
@@ -45689,7 +46468,7 @@ const getNetworkAds = async () => {
45689
46468
  };
45690
46469
  };
45691
46470
 
45692
- var index$4 = /*#__PURE__*/Object.freeze({
46471
+ var index$3 = /*#__PURE__*/Object.freeze({
45693
46472
  __proto__: null,
45694
46473
  getNetworkAds: getNetworkAds
45695
46474
  });
@@ -46080,7 +46859,7 @@ const markTraySeen = async (lastSeenAt) => {
46080
46859
  };
46081
46860
  /* end_public_function */
46082
46861
 
46083
- var index$3 = /*#__PURE__*/Object.freeze({
46862
+ var index$2 = /*#__PURE__*/Object.freeze({
46084
46863
  __proto__: null,
46085
46864
  getNotificationTraySeen: getNotificationTraySeen,
46086
46865
  getNotificationTrayItems: getNotificationTrayItems,
@@ -46281,7 +47060,7 @@ const getMyCommunityInvitations = (params, callback, config) => {
46281
47060
  };
46282
47061
  };
46283
47062
 
46284
- var index$2 = /*#__PURE__*/Object.freeze({
47063
+ var index$1 = /*#__PURE__*/Object.freeze({
46285
47064
  __proto__: null,
46286
47065
  onLocalInvitationCreated: onLocalInvitationCreated,
46287
47066
  onLocalInvitationUpdated: onLocalInvitationUpdated,
@@ -46422,286 +47201,11 @@ const getReactions = (postId, callback) => {
46422
47201
  };
46423
47202
  };
46424
47203
 
46425
- var index$1 = /*#__PURE__*/Object.freeze({
47204
+ var index = /*#__PURE__*/Object.freeze({
46426
47205
  __proto__: null,
46427
47206
  createReaction: createReaction,
46428
47207
  onLiveReactionCreated: onLiveReactionCreated,
46429
47208
  getReactions: getReactions
46430
47209
  });
46431
47210
 
46432
- const prepareEventPayload = (rawPayload) => {
46433
- return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
46434
- };
46435
-
46436
- const createEventEventSubscriber = (event, callback) => {
46437
- const client = getActiveClient();
46438
- const filter = (payload) => {
46439
- const unpackedPayload = prepareEventPayload(payload);
46440
- if (!client.cache) {
46441
- callback(unpackedPayload.events[0]);
46442
- }
46443
- else {
46444
- ingestInCache(unpackedPayload);
46445
- const event = pullFromCache([
46446
- 'event',
46447
- 'get',
46448
- unpackedPayload.events[0].eventId,
46449
- ]);
46450
- callback(event.data);
46451
- }
46452
- };
46453
- return createEventSubscriber(client, event, event, filter);
46454
- };
46455
-
46456
- /* begin_public_function
46457
- id: event.create
46458
- */
46459
- /**
46460
- * ```js
46461
- * import { EventRepository } from '@amityco/ts-sdk'
46462
- * const response = await EventRepository.createEvent(bundle)
46463
- * ```
46464
- *
46465
- * Creates an {@link Amity.Event}
46466
- *
46467
- * @param bundle The data necessary to create a new {@link Amity.Event}
46468
- * @returns The newly created {@link Amity.Event}
46469
- *
46470
- * @category Event API
46471
- * @async
46472
- */
46473
- const createEvent = async (bundle) => {
46474
- const client = getActiveClient();
46475
- client.log('event/createEvent', bundle);
46476
- const { data: payload } = await client.http.post('/api/v1/events', bundle);
46477
- fireEvent('event.created', payload);
46478
- const preparedPayload = prepareEventPayload(payload);
46479
- const cachedAt = client.cache && Date.now();
46480
- if (client.cache)
46481
- ingestInCache(preparedPayload, { cachedAt });
46482
- return {
46483
- data: eventLinkedObject(preparedPayload.events[0]),
46484
- cachedAt,
46485
- };
46486
- };
46487
- /* end_public_function */
46488
-
46489
- /* begin_public_function
46490
- id: event.update
46491
- */
46492
- /**
46493
- * ```js
46494
- * import { EventRepository } from '@amityco/ts-sdk'
46495
- * const response = await EventRepository.updateEvent(eventId, bundle)
46496
- * ```
46497
- *
46498
- * Updates an {@link Amity.Event}
46499
- *
46500
- * @param eventId The ID of the {@link Amity.Event} to edit
46501
- * @param bundle The data necessary to update an existing {@link Amity.Event}
46502
- * @returns the updated {@link Amity.Event}
46503
- *
46504
- * @category Event API
46505
- * @async
46506
- */
46507
- const updateEvent = async (eventId, bundle) => {
46508
- const client = getActiveClient();
46509
- client.log('event/updateEvent', eventId, bundle);
46510
- const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
46511
- fireEvent('event.updated', payload);
46512
- const preparedPayload = prepareEventPayload(payload);
46513
- const cachedAt = client.cache && Date.now();
46514
- if (client.cache)
46515
- ingestInCache(preparedPayload, { cachedAt });
46516
- return {
46517
- data: eventLinkedObject(preparedPayload.events.find(event => event.eventId === eventId)),
46518
- cachedAt,
46519
- };
46520
- };
46521
- /* end_public_function */
46522
-
46523
- /* begin_public_function
46524
- id: event.get
46525
- */
46526
- /**
46527
- * ```js
46528
- * import { EventRepository } from '@amityco/ts-sdk'
46529
- * const event = await EventRepository.getEvent(eventId)
46530
- * ```
46531
- *
46532
- * Fetches a {@link Amity.Event} object
46533
- *
46534
- * @param eventId the ID of the {@link Amity.Event} to fetch
46535
- * @returns the associated {@link Amity.Event} object
46536
- *
46537
- * @category Event API
46538
- * @async
46539
- */
46540
- const getEvent$1 = async (eventId) => {
46541
- const client = getActiveClient();
46542
- client.log('event/getEvent', eventId);
46543
- const { data: payload } = await client.http.get(`/api/v3/events/${eventId}`);
46544
- const data = prepareEventPayload(payload);
46545
- const cachedAt = client.cache && Date.now();
46546
- if (client.cache)
46547
- ingestInCache(data, { cachedAt });
46548
- return {
46549
- data: data.events.find(event => event.eventId === eventId),
46550
- cachedAt,
46551
- };
46552
- };
46553
- /* end_public_function */
46554
- /**
46555
- * ```js
46556
- * import { EventRepository } from '@amityco/ts-sdk'
46557
- * const event = EventRepository.getEvent.locally(eventId)
46558
- * ```
46559
- *
46560
- * Fetches a {@link Amity.Event} object in cache
46561
- *
46562
- * @param eventId the ID of the {@link Amity.Event} to fetch
46563
- * @returns the associated {@link Amity.Event} object
46564
- *
46565
- * @category Event API
46566
- */
46567
- getEvent$1.locally = (eventId) => {
46568
- const client = getActiveClient();
46569
- client.log('event/getEvent.locally', eventId);
46570
- if (!client.cache)
46571
- return;
46572
- const cache = pullFromCache(['event', 'get', eventId]);
46573
- if (!cache)
46574
- return;
46575
- return {
46576
- data: cache.data,
46577
- cachedAt: cache.cachedAt,
46578
- };
46579
- };
46580
-
46581
- /* begin_public_function
46582
- id: event.delete
46583
- */
46584
- /**
46585
- * ```js
46586
- * import { EventRepository } from '@amityco/ts-sdk'
46587
- * const { success } = await EventRepository.deleteEvent(eventId)
46588
- * ```
46589
- *
46590
- * Deletes a {@link Amity.Event}
46591
- *
46592
- * @param eventId The {@link Amity.Event} ID to delete
46593
- * @return A success boolean if the {@link Amity.Event} was deleted
46594
- *
46595
- * @category Event API
46596
- * @async
46597
- */
46598
- const deleteEvent = async (eventId) => {
46599
- const client = getActiveClient();
46600
- client.log('event/deleteEvent', eventId);
46601
- const event = await getEvent$1(eventId);
46602
- const { data } = await client.http.delete(`/api/v3/events/${eventId}`);
46603
- const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: data.success });
46604
- upsertInCache(['event', 'get', eventId], deletedEvent);
46605
- fireEvent('event.deleted', {
46606
- users: [],
46607
- files: [],
46608
- communities: [],
46609
- videoStreamings: [],
46610
- events: [deletedEvent],
46611
- discussionCommunities: [],
46612
- });
46613
- };
46614
- /* end_public_function */
46615
-
46616
- /**
46617
- * ```js
46618
- * import { EventRepository } from '@amityco/ts-sdk'
46619
- * const dispose = EventRepository.onEventCreated(event => {
46620
- * // ...
46621
- * })
46622
- * ```
46623
- *
46624
- * Fired when a {@link Amity.Event} has been created
46625
- *
46626
- * @param callback The function to call when the event was fired
46627
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46628
- *
46629
- * @category Event Events
46630
- */
46631
- const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
46632
-
46633
- /**
46634
- * ```js
46635
- * import { EventRepository } from '@amityco/ts-sdk'
46636
- * const dispose = EventRepository.onEventUpdated(event => {
46637
- * // ...
46638
- * })
46639
- * ```
46640
- *
46641
- * Fired when a {@link Amity.Event} has been updated
46642
- *
46643
- * @param callback The function to call when the event was fired
46644
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46645
- *
46646
- * @category Event Events
46647
- */
46648
- const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
46649
-
46650
- /**
46651
- * ```js
46652
- * import { EventRepository } from '@amityco/ts-sdk'
46653
- * const dispose = EventRepository.onEventDeleted(event => {
46654
- * // ...
46655
- * })
46656
- * ```
46657
- *
46658
- * Fired when a {@link Amity.Event} has been deleted
46659
- *
46660
- * @param callback The function to call when the event was fired
46661
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46662
- *
46663
- * @category Event Events
46664
- */
46665
- const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
46666
-
46667
- /* begin_public_function
46668
- id: event.get
46669
- */
46670
- /**
46671
- * ```js
46672
- * import { EventRepository } from '@amityco/ts-sdk';
46673
- *
46674
- * let event;
46675
- *
46676
- * const unsubscribe = EventRepository.getEvent(eventId, response => {
46677
- * event = response.data;
46678
- * });
46679
- * ```
46680
- *
46681
- * Observe all mutation on a given {@link Amity.Event}
46682
- *
46683
- * @param eventId the ID of the event to observe
46684
- * @param callback the function to call when new snapshot of event are available
46685
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the event
46686
- *
46687
- * @category Event Live Object
46688
- */
46689
- const getEvent = (eventId, callback) => {
46690
- return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventCreated, onEventUpdated, onEventDeleted], {
46691
- callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
46692
- });
46693
- };
46694
- /* end_public_function */
46695
-
46696
- var index = /*#__PURE__*/Object.freeze({
46697
- __proto__: null,
46698
- createEvent: createEvent,
46699
- updateEvent: updateEvent,
46700
- deleteEvent: deleteEvent,
46701
- onEventCreated: onEventCreated,
46702
- onEventUpdated: onEventUpdated,
46703
- onEventDeleted: onEventDeleted,
46704
- getEvent: getEvent
46705
- });
46706
-
46707
- export { API_REGIONS, index$4 as AdRepository, AmityEventOriginType, 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 };
47211
+ 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, 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 };