@amityco/ts-sdk 7.11.1-b8fc6951.0 → 7.11.1-bd338235.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/events.d.ts +13 -32
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +3 -2
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +4 -15
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/transport.d.ts +0 -3
- package/dist/@types/core/transport.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +1 -8
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/content.d.ts +4 -1
- package/dist/@types/domains/content.d.ts.map +1 -1
- package/dist/@types/domains/feed.d.ts +2 -1
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/@types/domains/partials.d.ts +2 -2
- package/dist/@types/domains/partials.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +2 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/room.d.ts +74 -0
- package/dist/@types/domains/room.d.ts.map +1 -0
- package/dist/@types/index.d.ts +2 -1
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/index.cjs.js +1295 -1020
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +747 -472
- package/dist/index.umd.js +3 -3
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -1
- package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
- package/dist/roomRepository/api/createRoom.d.ts +24 -0
- package/dist/roomRepository/api/createRoom.d.ts.map +1 -0
- package/dist/roomRepository/api/deleteRoom.d.ts +16 -0
- package/dist/roomRepository/api/deleteRoom.d.ts.map +1 -0
- package/dist/roomRepository/api/getRecordedUrl.d.ts +19 -0
- package/dist/roomRepository/api/getRecordedUrl.d.ts.map +1 -0
- package/dist/roomRepository/api/getRoomToken.d.ts +16 -0
- package/dist/roomRepository/api/getRoomToken.d.ts.map +1 -0
- package/dist/roomRepository/api/index.d.ts +7 -0
- package/dist/roomRepository/api/index.d.ts.map +1 -0
- package/dist/roomRepository/api/stopRoom.d.ts +16 -0
- package/dist/roomRepository/api/stopRoom.d.ts.map +1 -0
- package/dist/roomRepository/api/updateRoom.d.ts +24 -0
- package/dist/roomRepository/api/updateRoom.d.ts.map +1 -0
- package/dist/roomRepository/events/index.d.ts +12 -0
- package/dist/roomRepository/events/index.d.ts.map +1 -0
- package/dist/roomRepository/events/onRoomCreated.d.ts +17 -0
- package/dist/roomRepository/events/onRoomCreated.d.ts.map +1 -0
- package/dist/roomRepository/events/onRoomDeleted.d.ts +17 -0
- package/dist/roomRepository/events/onRoomDeleted.d.ts.map +1 -0
- package/dist/roomRepository/events/onRoomEndBroadcasting.d.ts +17 -0
- package/dist/roomRepository/events/onRoomEndBroadcasting.d.ts.map +1 -0
- package/dist/roomRepository/events/onRoomParticipantInviting.d.ts +17 -0
- package/dist/roomRepository/events/onRoomParticipantInviting.d.ts.map +1 -0
- package/dist/roomRepository/events/onRoomParticipantJoined.d.ts +17 -0
- package/dist/roomRepository/events/onRoomParticipantJoined.d.ts.map +1 -0
- package/dist/roomRepository/events/onRoomParticipantLeft.d.ts +17 -0
- package/dist/roomRepository/events/onRoomParticipantLeft.d.ts.map +1 -0
- package/dist/roomRepository/events/onRoomRecordedAvailable.d.ts +17 -0
- package/dist/roomRepository/events/onRoomRecordedAvailable.d.ts.map +1 -0
- package/dist/roomRepository/events/onRoomStartBroadcasting.d.ts +17 -0
- package/dist/roomRepository/events/onRoomStartBroadcasting.d.ts.map +1 -0
- package/dist/roomRepository/events/onRoomStopped.d.ts +17 -0
- package/dist/roomRepository/events/onRoomStopped.d.ts.map +1 -0
- package/dist/roomRepository/events/onRoomUpdated.d.ts +17 -0
- package/dist/roomRepository/events/onRoomUpdated.d.ts.map +1 -0
- package/dist/roomRepository/events/onRoomWaitingReconnect.d.ts +17 -0
- package/dist/roomRepository/events/onRoomWaitingReconnect.d.ts.map +1 -0
- package/dist/roomRepository/index.d.ts.map +1 -0
- package/dist/roomRepository/internalApi/getRoomById.d.ts +5 -0
- package/dist/roomRepository/internalApi/getRoomById.d.ts.map +1 -0
- package/dist/roomRepository/internalApi/index.d.ts +2 -0
- package/dist/roomRepository/internalApi/index.d.ts.map +1 -0
- package/dist/roomRepository/observers/enums.d.ts +10 -0
- package/dist/roomRepository/observers/enums.d.ts.map +1 -0
- package/dist/roomRepository/observers/getRoom.d.ts +2 -0
- package/dist/roomRepository/observers/getRoom.d.ts.map +1 -0
- package/dist/roomRepository/observers/getRooms/RoomLiveCollectionController.d.ts +14 -0
- package/dist/roomRepository/observers/getRooms/RoomLiveCollectionController.d.ts.map +1 -0
- package/dist/roomRepository/observers/getRooms/RoomPaginationController.d.ts +5 -0
- package/dist/roomRepository/observers/getRooms/RoomPaginationController.d.ts.map +1 -0
- package/dist/roomRepository/observers/getRooms/RoomQueryStreamController.d.ts +15 -0
- package/dist/roomRepository/observers/getRooms/RoomQueryStreamController.d.ts.map +1 -0
- package/dist/roomRepository/observers/getRooms.d.ts +29 -0
- package/dist/roomRepository/observers/getRooms.d.ts.map +1 -0
- package/dist/roomRepository/observers/index.d.ts +3 -0
- package/dist/roomRepository/observers/index.d.ts.map +1 -0
- package/dist/roomRepository/observers/utils.d.ts +6 -0
- package/dist/roomRepository/observers/utils.d.ts.map +1 -0
- package/dist/utils/linkedObject/index.d.ts +0 -1
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/roomLinkedObject.d.ts +4 -0
- package/dist/utils/linkedObject/roomLinkedObject.d.ts.map +1 -0
- package/dist/utils/postTypePredicate.d.ts +1 -0
- package/dist/utils/postTypePredicate.d.ts.map +1 -1
- package/dist/utils/tests/dummy/comment.d.ts +1 -1
- package/package.json +1 -1
- package/dist/@types/domains/event.d.ts +0 -66
- package/dist/@types/domains/event.d.ts.map +0 -1
- package/dist/eventRepository/api/createEvent.d.ts +0 -16
- package/dist/eventRepository/api/createEvent.d.ts.map +0 -1
- package/dist/eventRepository/api/deleteEvent.d.ts +0 -15
- package/dist/eventRepository/api/deleteEvent.d.ts.map +0 -1
- package/dist/eventRepository/api/index.d.ts +0 -4
- package/dist/eventRepository/api/index.d.ts.map +0 -1
- package/dist/eventRepository/api/updateEvent.d.ts +0 -17
- package/dist/eventRepository/api/updateEvent.d.ts.map +0 -1
- package/dist/eventRepository/events/enums.d.ts +0 -6
- package/dist/eventRepository/events/enums.d.ts.map +0 -1
- package/dist/eventRepository/events/index.d.ts +0 -4
- package/dist/eventRepository/events/index.d.ts.map +0 -1
- package/dist/eventRepository/events/onEventCreated.d.ts +0 -17
- package/dist/eventRepository/events/onEventCreated.d.ts.map +0 -1
- package/dist/eventRepository/events/onEventDeleted.d.ts +0 -17
- package/dist/eventRepository/events/onEventDeleted.d.ts.map +0 -1
- package/dist/eventRepository/events/onEventUpdated.d.ts +0 -17
- package/dist/eventRepository/events/onEventUpdated.d.ts.map +0 -1
- package/dist/eventRepository/index.d.ts.map +0 -1
- package/dist/eventRepository/internalApi/getEvent.d.ts +0 -32
- package/dist/eventRepository/internalApi/getEvent.d.ts.map +0 -1
- package/dist/eventRepository/internalApi/index.d.ts +0 -2
- package/dist/eventRepository/internalApi/index.d.ts.map +0 -1
- package/dist/eventRepository/observers/getEvent.d.ts +0 -21
- package/dist/eventRepository/observers/getEvent.d.ts.map +0 -1
- package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts +0 -13
- package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts.map +0 -1
- package/dist/eventRepository/observers/getEvents/PaginationController.d.ts +0 -5
- package/dist/eventRepository/observers/getEvents/PaginationController.d.ts.map +0 -1
- package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts +0 -15
- package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts.map +0 -1
- package/dist/eventRepository/observers/getEvents.d.ts +0 -12
- package/dist/eventRepository/observers/getEvents.d.ts.map +0 -1
- package/dist/eventRepository/observers/index.d.ts +0 -3
- package/dist/eventRepository/observers/index.d.ts.map +0 -1
- package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +0 -2
- package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +0 -1
- package/dist/eventRepository/utils/index.d.ts +0 -3
- package/dist/eventRepository/utils/index.d.ts.map +0 -1
- package/dist/eventRepository/utils/prepareEventPayload.d.ts +0 -2
- package/dist/eventRepository/utils/prepareEventPayload.d.ts.map +0 -1
- package/dist/utils/linkedObject/eventLinkObject.d.ts +0 -2
- package/dist/utils/linkedObject/eventLinkObject.d.ts.map +0 -1
- /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,7 +627,7 @@ const idResolvers = {
|
|
|
643
627
|
notificationTraySeen: ({ userId }) => userId,
|
|
644
628
|
invitation: ({ _id }) => _id,
|
|
645
629
|
joinRequest: ({ joinRequestId }) => joinRequestId,
|
|
646
|
-
|
|
630
|
+
room: ({ roomId }) => roomId,
|
|
647
631
|
};
|
|
648
632
|
/**
|
|
649
633
|
* Retrieve the id resolver matching a domain name
|
|
@@ -699,8 +683,7 @@ const PAYLOAD2MODEL = {
|
|
|
699
683
|
notificationTrayItems: 'notificationTrayItem',
|
|
700
684
|
invitations: 'invitation',
|
|
701
685
|
joinRequests: 'joinRequest',
|
|
702
|
-
|
|
703
|
-
discussionCommunities: 'community',
|
|
686
|
+
rooms: 'room',
|
|
704
687
|
};
|
|
705
688
|
/** hidden */
|
|
706
689
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -28320,6 +28303,12 @@ function isAmityAudioPost(post) {
|
|
|
28320
28303
|
'fileId' in post.data &&
|
|
28321
28304
|
post.dataType === 'audio');
|
|
28322
28305
|
}
|
|
28306
|
+
function isAmityRoomPost(post) {
|
|
28307
|
+
return !!(post.data &&
|
|
28308
|
+
typeof post.data !== 'string' &&
|
|
28309
|
+
'roomId' in post.data &&
|
|
28310
|
+
post.dataType === 'room');
|
|
28311
|
+
}
|
|
28323
28312
|
|
|
28324
28313
|
const postLinkedObject = (post) => {
|
|
28325
28314
|
return shallowClone(post, {
|
|
@@ -28414,6 +28403,12 @@ const postLinkedObject = (post) => {
|
|
|
28414
28403
|
? (_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
|
|
28415
28404
|
: undefined;
|
|
28416
28405
|
},
|
|
28406
|
+
getRoomInfo() {
|
|
28407
|
+
var _a, _b;
|
|
28408
|
+
if (!isAmityRoomPost(post))
|
|
28409
|
+
return;
|
|
28410
|
+
return (_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;
|
|
28411
|
+
},
|
|
28417
28412
|
});
|
|
28418
28413
|
};
|
|
28419
28414
|
|
|
@@ -29771,35 +29766,6 @@ const communityLinkedObject = (community) => {
|
|
|
29771
29766
|
} });
|
|
29772
29767
|
};
|
|
29773
29768
|
|
|
29774
|
-
const eventLinkedObject = (event) => {
|
|
29775
|
-
return Object.assign(Object.assign({}, event), { get creator() {
|
|
29776
|
-
const cacheData = pullFromCache(['user', 'get', event.userId]);
|
|
29777
|
-
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
29778
|
-
return;
|
|
29779
|
-
return userLinkedObject(cacheData.data);
|
|
29780
|
-
},
|
|
29781
|
-
get discussionCommunity() {
|
|
29782
|
-
if (!event.discussionCommunityId)
|
|
29783
|
-
return;
|
|
29784
|
-
const cacheData = pullFromCache([
|
|
29785
|
-
'community',
|
|
29786
|
-
'get',
|
|
29787
|
-
event.discussionCommunityId,
|
|
29788
|
-
]);
|
|
29789
|
-
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
29790
|
-
return;
|
|
29791
|
-
return communityLinkedObject(cacheData.data);
|
|
29792
|
-
},
|
|
29793
|
-
get liveStream() {
|
|
29794
|
-
if (!event.livestreamId)
|
|
29795
|
-
return;
|
|
29796
|
-
const cacheData = pullFromCache(['stream', 'get', event.livestreamId]);
|
|
29797
|
-
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
29798
|
-
return;
|
|
29799
|
-
return cacheData.data;
|
|
29800
|
-
} });
|
|
29801
|
-
};
|
|
29802
|
-
|
|
29803
29769
|
const LinkedObject = {
|
|
29804
29770
|
ad: adLinkedObject,
|
|
29805
29771
|
comment: commentLinkedObject,
|
|
@@ -29818,7 +29784,6 @@ const LinkedObject = {
|
|
|
29818
29784
|
invitation: invitationLinkedObject,
|
|
29819
29785
|
joinRequest: joinRequestLinkedObject,
|
|
29820
29786
|
channelMember: channelMemberLinkedObject,
|
|
29821
|
-
event: eventLinkedObject,
|
|
29822
29787
|
};
|
|
29823
29788
|
|
|
29824
29789
|
/* begin_public_function
|
|
@@ -43803,6 +43768,729 @@ var index$8 = /*#__PURE__*/Object.freeze({
|
|
|
43803
43768
|
getStreams: getStreams
|
|
43804
43769
|
});
|
|
43805
43770
|
|
|
43771
|
+
/* begin_public_function
|
|
43772
|
+
id: room.create
|
|
43773
|
+
*/
|
|
43774
|
+
/**
|
|
43775
|
+
* ```js
|
|
43776
|
+
* import { createRoom } from '@amityco/ts-sdk'
|
|
43777
|
+
* const created = await createRoom({ title: 'my room', 'thumbnailFileId': fileId })
|
|
43778
|
+
* ```
|
|
43779
|
+
*
|
|
43780
|
+
* Creates an {@link Amity.Room}
|
|
43781
|
+
*
|
|
43782
|
+
* @param bundle The data necessary to create a new {@link Amity.Room}
|
|
43783
|
+
* @returns The newly created {@link Amity.Room}
|
|
43784
|
+
*
|
|
43785
|
+
* @category Room API
|
|
43786
|
+
* @async
|
|
43787
|
+
*/
|
|
43788
|
+
const createRoom = async (bundle) => {
|
|
43789
|
+
const client = getActiveClient();
|
|
43790
|
+
client.log('room/createRoom', bundle);
|
|
43791
|
+
const { data } = await client.http.post('/api/v1/rooms', bundle);
|
|
43792
|
+
fireEvent('local.room.created', data);
|
|
43793
|
+
const cachedAt = client.cache && Date.now();
|
|
43794
|
+
// TODO: check if should pick `users` filed which contains participants - if no need to ingest in the cache
|
|
43795
|
+
if (client.cache)
|
|
43796
|
+
ingestInCache(data, { cachedAt });
|
|
43797
|
+
const { rooms } = data;
|
|
43798
|
+
return {
|
|
43799
|
+
data: rooms[0],
|
|
43800
|
+
cachedAt,
|
|
43801
|
+
};
|
|
43802
|
+
};
|
|
43803
|
+
/* end_public_function */
|
|
43804
|
+
|
|
43805
|
+
/* begin_public_function
|
|
43806
|
+
id: room.update
|
|
43807
|
+
*/
|
|
43808
|
+
/**
|
|
43809
|
+
* ```js
|
|
43810
|
+
* import { updateRoom } from '@amityco/ts-sdk'
|
|
43811
|
+
* const updated = await updateRoom('roomId', { title: 'updated title' })
|
|
43812
|
+
* ```
|
|
43813
|
+
*
|
|
43814
|
+
* Updates an {@link Amity.InternalRoom}
|
|
43815
|
+
*
|
|
43816
|
+
* @param roomId The ID of the room to update
|
|
43817
|
+
* @param bundle The data to update the room with
|
|
43818
|
+
* @returns The updated {@link Amity.InternalRoom}
|
|
43819
|
+
*
|
|
43820
|
+
* @category Room API
|
|
43821
|
+
* @async
|
|
43822
|
+
*/
|
|
43823
|
+
const updateRoom = async (roomId, bundle) => {
|
|
43824
|
+
const client = getActiveClient();
|
|
43825
|
+
client.log('room/updateRoom', { roomId, bundle });
|
|
43826
|
+
const { data } = await client.http.put(`/api/v1/rooms/${roomId}`, bundle);
|
|
43827
|
+
fireEvent('local.room.updated', data);
|
|
43828
|
+
const cachedAt = client.cache && Date.now();
|
|
43829
|
+
if (client.cache)
|
|
43830
|
+
ingestInCache(data, { cachedAt });
|
|
43831
|
+
const { rooms } = data;
|
|
43832
|
+
return {
|
|
43833
|
+
data: rooms[0],
|
|
43834
|
+
cachedAt,
|
|
43835
|
+
};
|
|
43836
|
+
};
|
|
43837
|
+
/* end_public_function */
|
|
43838
|
+
|
|
43839
|
+
/* begin_public_function
|
|
43840
|
+
id: room.delete
|
|
43841
|
+
*/
|
|
43842
|
+
/**
|
|
43843
|
+
* ```js
|
|
43844
|
+
* import { deleteRoom } from '@amityco/ts-sdk'
|
|
43845
|
+
* const result = await deleteRoom('roomId')
|
|
43846
|
+
* ```
|
|
43847
|
+
*
|
|
43848
|
+
* Deletes an {@link Amity.Room}
|
|
43849
|
+
*
|
|
43850
|
+
* @param roomId The ID of the room to delete
|
|
43851
|
+
* @returns Promise that resolves when the room is deleted
|
|
43852
|
+
*
|
|
43853
|
+
* @category Room API
|
|
43854
|
+
* @async
|
|
43855
|
+
*/
|
|
43856
|
+
const deleteRoom = async (roomId) => {
|
|
43857
|
+
const client = getActiveClient();
|
|
43858
|
+
client.log('room/deleteRoom', { roomId });
|
|
43859
|
+
await client.http.delete(`/api/v1/rooms/${roomId}`);
|
|
43860
|
+
fireEvent('local.room.deleted', { rooms: [{ _id: roomId }] });
|
|
43861
|
+
};
|
|
43862
|
+
/* end_public_function */
|
|
43863
|
+
|
|
43864
|
+
/* begin_public_function
|
|
43865
|
+
id: room.stop
|
|
43866
|
+
*/
|
|
43867
|
+
/**
|
|
43868
|
+
* ```js
|
|
43869
|
+
* import { stopRoom } from '@amityco/ts-sdk'
|
|
43870
|
+
* const result = await stopRoom('roomId')
|
|
43871
|
+
* ```
|
|
43872
|
+
*
|
|
43873
|
+
* Stops a room's broadcasting
|
|
43874
|
+
*
|
|
43875
|
+
* @param roomId The ID of the room to stop
|
|
43876
|
+
* @returns The updated room data
|
|
43877
|
+
*
|
|
43878
|
+
* @category Room API
|
|
43879
|
+
* @async
|
|
43880
|
+
*/
|
|
43881
|
+
const stopRoom = async (roomId) => {
|
|
43882
|
+
const client = getActiveClient();
|
|
43883
|
+
client.log('room/stopRoom', { roomId });
|
|
43884
|
+
const { data } = await client.http.post(`/api/v1/rooms/${roomId}/stop`);
|
|
43885
|
+
fireEvent('local.room.stopped', data);
|
|
43886
|
+
const cachedAt = client.cache && Date.now();
|
|
43887
|
+
if (client.cache)
|
|
43888
|
+
ingestInCache(data, { cachedAt });
|
|
43889
|
+
const { rooms } = data;
|
|
43890
|
+
return {
|
|
43891
|
+
data: rooms[0],
|
|
43892
|
+
cachedAt,
|
|
43893
|
+
};
|
|
43894
|
+
};
|
|
43895
|
+
/* end_public_function */
|
|
43896
|
+
|
|
43897
|
+
/* begin_public_function
|
|
43898
|
+
id: room.getBroadcasterData
|
|
43899
|
+
*/
|
|
43900
|
+
/**
|
|
43901
|
+
* ```js
|
|
43902
|
+
* import { getBroadcasterData } from '@amityco/ts-sdk'
|
|
43903
|
+
* const token = await getBroadcasterData('roomId')
|
|
43904
|
+
* ```
|
|
43905
|
+
*
|
|
43906
|
+
* Gets an access token for a room
|
|
43907
|
+
*
|
|
43908
|
+
* @param roomId The ID of the room to get token for
|
|
43909
|
+
* @returns The room access token
|
|
43910
|
+
*
|
|
43911
|
+
* @category Room API
|
|
43912
|
+
* @async
|
|
43913
|
+
*/
|
|
43914
|
+
const getBroadcasterData = async (roomId) => {
|
|
43915
|
+
const client = getActiveClient();
|
|
43916
|
+
client.log('room/getBroadcasterData', { roomId });
|
|
43917
|
+
const { data } = await client.http.get(`/api/v1/rooms/${roomId}/token`);
|
|
43918
|
+
return data;
|
|
43919
|
+
};
|
|
43920
|
+
/* end_public_function */
|
|
43921
|
+
|
|
43922
|
+
/* begin_public_function
|
|
43923
|
+
id: room.getRecordedUrl
|
|
43924
|
+
*/
|
|
43925
|
+
/**
|
|
43926
|
+
* ```js
|
|
43927
|
+
* import { getRecordedUrl } from '@amityco/ts-sdk'
|
|
43928
|
+
* const recordedUrl = await getRecordedUrl('roomId')
|
|
43929
|
+
* ```
|
|
43930
|
+
*
|
|
43931
|
+
* Gets the recorded URL for a room
|
|
43932
|
+
*
|
|
43933
|
+
* @param roomId The ID of the room to get recorded URL for
|
|
43934
|
+
* @returns The recorded URL information
|
|
43935
|
+
*
|
|
43936
|
+
* @category Room API
|
|
43937
|
+
* @async
|
|
43938
|
+
*/
|
|
43939
|
+
const getRecordedUrl = async (roomId) => {
|
|
43940
|
+
const client = getActiveClient();
|
|
43941
|
+
client.log('room/getRecordedUrl', { roomId });
|
|
43942
|
+
const { data } = await client.http.get(`/api/v1/rooms/${roomId}/recorded`);
|
|
43943
|
+
return data;
|
|
43944
|
+
};
|
|
43945
|
+
/* end_public_function */
|
|
43946
|
+
|
|
43947
|
+
/**
|
|
43948
|
+
* ```js
|
|
43949
|
+
* import { onRoomStartBroadcasting } from '@amityco/ts-sdk'
|
|
43950
|
+
* const dispose = onRoomStartBroadcasting(room => {
|
|
43951
|
+
* // ...
|
|
43952
|
+
* })
|
|
43953
|
+
* ```
|
|
43954
|
+
*
|
|
43955
|
+
* Fired when a {@link Amity.Room} has started broadcasting
|
|
43956
|
+
*
|
|
43957
|
+
* @param callback The function to call when the event was fired
|
|
43958
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
43959
|
+
*
|
|
43960
|
+
* @category Room Events
|
|
43961
|
+
*/
|
|
43962
|
+
const onRoomStartBroadcasting = (callback) => {
|
|
43963
|
+
const client = getActiveClient();
|
|
43964
|
+
const filter = (payload) => {
|
|
43965
|
+
ingestInCache(payload);
|
|
43966
|
+
callback(payload.rooms[0]);
|
|
43967
|
+
};
|
|
43968
|
+
return createEventSubscriber(client, 'room/onRoomStartBroadcasting', 'room.startBroadcasting', filter);
|
|
43969
|
+
};
|
|
43970
|
+
|
|
43971
|
+
/**
|
|
43972
|
+
* ```js
|
|
43973
|
+
* import { onRoomWaitingReconnect } from '@amityco/ts-sdk'
|
|
43974
|
+
* const dispose = onRoomWaitingReconnect(room => {
|
|
43975
|
+
* // ...
|
|
43976
|
+
* })
|
|
43977
|
+
* ```
|
|
43978
|
+
*
|
|
43979
|
+
* Fired when a {@link Amity.Room} is waiting for reconnection
|
|
43980
|
+
*
|
|
43981
|
+
* @param callback The function to call when the event was fired
|
|
43982
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
43983
|
+
*
|
|
43984
|
+
* @category Room Events
|
|
43985
|
+
*/
|
|
43986
|
+
const onRoomWaitingReconnect = (callback) => {
|
|
43987
|
+
const client = getActiveClient();
|
|
43988
|
+
const filter = (payload) => {
|
|
43989
|
+
ingestInCache(payload);
|
|
43990
|
+
callback(payload.rooms[0]);
|
|
43991
|
+
};
|
|
43992
|
+
return createEventSubscriber(client, 'room/onRoomWaitingReconnect', 'room.waitingReconnect', filter);
|
|
43993
|
+
};
|
|
43994
|
+
|
|
43995
|
+
/**
|
|
43996
|
+
* ```js
|
|
43997
|
+
* import { onRoomEndBroadcasting } from '@amityco/ts-sdk'
|
|
43998
|
+
* const dispose = onRoomEndBroadcasting(room => {
|
|
43999
|
+
* // ...
|
|
44000
|
+
* })
|
|
44001
|
+
* ```
|
|
44002
|
+
*
|
|
44003
|
+
* Fired when a {@link Amity.Room} has ended broadcasting
|
|
44004
|
+
*
|
|
44005
|
+
* @param callback The function to call when the event was fired
|
|
44006
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44007
|
+
*
|
|
44008
|
+
* @category Room Events
|
|
44009
|
+
*/
|
|
44010
|
+
const onRoomEndBroadcasting = (callback) => {
|
|
44011
|
+
const client = getActiveClient();
|
|
44012
|
+
const filter = (payload) => {
|
|
44013
|
+
ingestInCache(payload);
|
|
44014
|
+
callback(payload.rooms[0]);
|
|
44015
|
+
};
|
|
44016
|
+
return createEventSubscriber(client, 'room/onRoomEndBroadcasting', 'room.endBroadcasting', filter);
|
|
44017
|
+
};
|
|
44018
|
+
|
|
44019
|
+
/**
|
|
44020
|
+
* ```js
|
|
44021
|
+
* import { onRoomRecordedAvailable } from '@amityco/ts-sdk'
|
|
44022
|
+
* const dispose = onRoomRecordedAvailable(room => {
|
|
44023
|
+
* // ...
|
|
44024
|
+
* })
|
|
44025
|
+
* ```
|
|
44026
|
+
*
|
|
44027
|
+
* Fired when a {@link Amity.Room} recorded content becomes available
|
|
44028
|
+
*
|
|
44029
|
+
* @param callback The function to call when the event was fired
|
|
44030
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44031
|
+
*
|
|
44032
|
+
* @category Room Events
|
|
44033
|
+
*/
|
|
44034
|
+
const onRoomRecordedAvailable = (callback) => {
|
|
44035
|
+
const client = getActiveClient();
|
|
44036
|
+
const filter = (payload) => {
|
|
44037
|
+
ingestInCache(payload);
|
|
44038
|
+
callback(payload.rooms[0]);
|
|
44039
|
+
};
|
|
44040
|
+
return createEventSubscriber(client, 'room/onRoomRecordedAvailable', 'room.recordedAvailable', filter);
|
|
44041
|
+
};
|
|
44042
|
+
|
|
44043
|
+
/**
|
|
44044
|
+
* ```js
|
|
44045
|
+
* import { onRoomParticipantInviting } from '@amityco/ts-sdk'
|
|
44046
|
+
* const dispose = onRoomParticipantInviting(room => {
|
|
44047
|
+
* // ...
|
|
44048
|
+
* })
|
|
44049
|
+
* ```
|
|
44050
|
+
*
|
|
44051
|
+
* Fired when a participant is being invited to a {@link Amity.Room}
|
|
44052
|
+
*
|
|
44053
|
+
* @param callback The function to call when the event was fired
|
|
44054
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44055
|
+
*
|
|
44056
|
+
* @category Room Events
|
|
44057
|
+
*/
|
|
44058
|
+
const onRoomParticipantInviting = (callback) => {
|
|
44059
|
+
const client = getActiveClient();
|
|
44060
|
+
const filter = (payload) => {
|
|
44061
|
+
ingestInCache(payload);
|
|
44062
|
+
callback(payload.rooms[0]);
|
|
44063
|
+
};
|
|
44064
|
+
return createEventSubscriber(client, 'room/onRoomParticipantInviting', 'room.participantInviting', filter);
|
|
44065
|
+
};
|
|
44066
|
+
|
|
44067
|
+
/**
|
|
44068
|
+
* ```js
|
|
44069
|
+
* import { onRoomParticipantJoined } from '@amityco/ts-sdk'
|
|
44070
|
+
* const dispose = onRoomParticipantJoined(room => {
|
|
44071
|
+
* // ...
|
|
44072
|
+
* })
|
|
44073
|
+
* ```
|
|
44074
|
+
*
|
|
44075
|
+
* Fired when a participant has joined a {@link Amity.Room}
|
|
44076
|
+
*
|
|
44077
|
+
* @param callback The function to call when the event was fired
|
|
44078
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44079
|
+
*
|
|
44080
|
+
* @category Room Events
|
|
44081
|
+
*/
|
|
44082
|
+
const onRoomParticipantJoined = (callback) => {
|
|
44083
|
+
const client = getActiveClient();
|
|
44084
|
+
const filter = (payload) => {
|
|
44085
|
+
ingestInCache(payload);
|
|
44086
|
+
callback(payload.rooms[0]);
|
|
44087
|
+
};
|
|
44088
|
+
return createEventSubscriber(client, 'room/onRoomParticipantJoined', 'room.participantJoined', filter);
|
|
44089
|
+
};
|
|
44090
|
+
|
|
44091
|
+
/**
|
|
44092
|
+
* ```js
|
|
44093
|
+
* import { onRoomParticipantLeft } from '@amityco/ts-sdk'
|
|
44094
|
+
* const dispose = onRoomParticipantLeft(room => {
|
|
44095
|
+
* // ...
|
|
44096
|
+
* })
|
|
44097
|
+
* ```
|
|
44098
|
+
*
|
|
44099
|
+
* Fired when a participant has left a {@link Amity.Room}
|
|
44100
|
+
*
|
|
44101
|
+
* @param callback The function to call when the event was fired
|
|
44102
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44103
|
+
*
|
|
44104
|
+
* @category Room Events
|
|
44105
|
+
*/
|
|
44106
|
+
const onRoomParticipantLeft = (callback) => {
|
|
44107
|
+
const client = getActiveClient();
|
|
44108
|
+
const filter = (payload) => {
|
|
44109
|
+
ingestInCache(payload);
|
|
44110
|
+
callback(payload.rooms[0]);
|
|
44111
|
+
};
|
|
44112
|
+
return createEventSubscriber(client, 'room/onRoomParticipantLeft', 'room.participantLeft', filter);
|
|
44113
|
+
};
|
|
44114
|
+
|
|
44115
|
+
/**
|
|
44116
|
+
* ```js
|
|
44117
|
+
* import { onRoomCreated } from '@amityco/ts-sdk'
|
|
44118
|
+
* const dispose = onRoomCreated(room => {
|
|
44119
|
+
* // ...
|
|
44120
|
+
* })
|
|
44121
|
+
* ```
|
|
44122
|
+
*
|
|
44123
|
+
* Fired when a {@link Amity.Room} has been created locally
|
|
44124
|
+
*
|
|
44125
|
+
* @param callback The function to call when the event was fired
|
|
44126
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44127
|
+
*
|
|
44128
|
+
* @category Room Events
|
|
44129
|
+
*/
|
|
44130
|
+
const onRoomCreated = (callback) => {
|
|
44131
|
+
const client = getActiveClient();
|
|
44132
|
+
const filter = (payload) => {
|
|
44133
|
+
ingestInCache(payload);
|
|
44134
|
+
callback(payload.rooms[0]);
|
|
44135
|
+
};
|
|
44136
|
+
return createEventSubscriber(client, 'room/onRoomCreated', 'local.room.created', filter);
|
|
44137
|
+
};
|
|
44138
|
+
|
|
44139
|
+
/**
|
|
44140
|
+
* ```js
|
|
44141
|
+
* import { onRoomUpdated } from '@amityco/ts-sdk'
|
|
44142
|
+
* const dispose = onRoomUpdated(room => {
|
|
44143
|
+
* // ...
|
|
44144
|
+
* })
|
|
44145
|
+
* ```
|
|
44146
|
+
*
|
|
44147
|
+
* Fired when a {@link Amity.Room} has been updated locally
|
|
44148
|
+
*
|
|
44149
|
+
* @param callback The function to call when the event was fired
|
|
44150
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44151
|
+
*
|
|
44152
|
+
* @category Room Events
|
|
44153
|
+
*/
|
|
44154
|
+
const onRoomUpdated = (callback) => {
|
|
44155
|
+
const client = getActiveClient();
|
|
44156
|
+
const filter = (payload) => {
|
|
44157
|
+
ingestInCache(payload);
|
|
44158
|
+
callback(payload.rooms[0]);
|
|
44159
|
+
};
|
|
44160
|
+
return createEventSubscriber(client, 'room/onRoomUpdated', 'local.room.updated', filter);
|
|
44161
|
+
};
|
|
44162
|
+
|
|
44163
|
+
/**
|
|
44164
|
+
* ```js
|
|
44165
|
+
* import { onRoomDeleted } from '@amityco/ts-sdk'
|
|
44166
|
+
* const dispose = onRoomDeleted(room => {
|
|
44167
|
+
* // ...
|
|
44168
|
+
* })
|
|
44169
|
+
* ```
|
|
44170
|
+
*
|
|
44171
|
+
* Fired when a {@link Amity.Room} has been deleted locally
|
|
44172
|
+
*
|
|
44173
|
+
* @param callback The function to call when the event was fired
|
|
44174
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44175
|
+
*
|
|
44176
|
+
* @category Room Events
|
|
44177
|
+
*/
|
|
44178
|
+
const onRoomDeleted = (callback) => {
|
|
44179
|
+
const client = getActiveClient();
|
|
44180
|
+
const filter = (payload) => {
|
|
44181
|
+
ingestInCache(payload);
|
|
44182
|
+
callback(payload.rooms[0]);
|
|
44183
|
+
};
|
|
44184
|
+
return createEventSubscriber(client, 'room/onRoomDeleted', 'local.room.deleted', filter);
|
|
44185
|
+
};
|
|
44186
|
+
|
|
44187
|
+
/**
|
|
44188
|
+
* ```js
|
|
44189
|
+
* import { onRoomStopped } from '@amityco/ts-sdk'
|
|
44190
|
+
* const dispose = onRoomStopped(room => {
|
|
44191
|
+
* // ...
|
|
44192
|
+
* })
|
|
44193
|
+
* ```
|
|
44194
|
+
*
|
|
44195
|
+
* Fired when a {@link Amity.Room} has been stopped locally
|
|
44196
|
+
*
|
|
44197
|
+
* @param callback The function to call when the event was fired
|
|
44198
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44199
|
+
*
|
|
44200
|
+
* @category Room Events
|
|
44201
|
+
*/
|
|
44202
|
+
const onRoomStopped = (callback) => {
|
|
44203
|
+
const client = getActiveClient();
|
|
44204
|
+
const filter = (payload) => {
|
|
44205
|
+
ingestInCache(payload);
|
|
44206
|
+
callback(payload.rooms[0]);
|
|
44207
|
+
};
|
|
44208
|
+
return createEventSubscriber(client, 'room/onRoomStopped', 'local.room.stopped', filter);
|
|
44209
|
+
};
|
|
44210
|
+
|
|
44211
|
+
const getRoomById = async (roomId) => {
|
|
44212
|
+
const client = getActiveClient();
|
|
44213
|
+
client.log('room/getRoomById', roomId);
|
|
44214
|
+
// Check if room is in tombstone
|
|
44215
|
+
isInTombstone('room', roomId);
|
|
44216
|
+
let data;
|
|
44217
|
+
try {
|
|
44218
|
+
const response = await client.http.get(`/api/v1/rooms/${roomId}`);
|
|
44219
|
+
data = response.data;
|
|
44220
|
+
}
|
|
44221
|
+
catch (error) {
|
|
44222
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
44223
|
+
pushToTombstone('room', roomId);
|
|
44224
|
+
}
|
|
44225
|
+
throw error;
|
|
44226
|
+
}
|
|
44227
|
+
const cachedAt = client.cache && Date.now();
|
|
44228
|
+
if (client.cache) {
|
|
44229
|
+
ingestInCache(data, { cachedAt });
|
|
44230
|
+
}
|
|
44231
|
+
return {
|
|
44232
|
+
data: data.rooms[0],
|
|
44233
|
+
cachedAt,
|
|
44234
|
+
};
|
|
44235
|
+
};
|
|
44236
|
+
getRoomById.locally = (roomId) => {
|
|
44237
|
+
const client = getActiveClient();
|
|
44238
|
+
client.log('room/getRoomById.locally', roomId);
|
|
44239
|
+
// Check if room is in tombstone
|
|
44240
|
+
isInTombstone('room', roomId);
|
|
44241
|
+
const cachedAt = client.cache && Date.now();
|
|
44242
|
+
const roomCache = pullFromCache(['room', 'get', roomId]);
|
|
44243
|
+
if (!roomCache)
|
|
44244
|
+
return;
|
|
44245
|
+
return {
|
|
44246
|
+
data: roomCache.data,
|
|
44247
|
+
cachedAt,
|
|
44248
|
+
};
|
|
44249
|
+
};
|
|
44250
|
+
|
|
44251
|
+
const getRoom = (roomId, callback) => {
|
|
44252
|
+
// TODO: add callbackDataSelector if there are linked object fields
|
|
44253
|
+
return liveObject(roomId, callback, '_id', getRoomById, [
|
|
44254
|
+
onRoomEndBroadcasting,
|
|
44255
|
+
onRoomStartBroadcasting,
|
|
44256
|
+
onRoomWaitingReconnect,
|
|
44257
|
+
onRoomRecordedAvailable,
|
|
44258
|
+
]);
|
|
44259
|
+
};
|
|
44260
|
+
|
|
44261
|
+
class RoomPaginationController extends PaginationController {
|
|
44262
|
+
async getRequest(queryParams, token) {
|
|
44263
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
44264
|
+
const baseOptions = {
|
|
44265
|
+
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
44266
|
+
};
|
|
44267
|
+
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
44268
|
+
const { data: queryResponse } = await this.http.get(`/api/v1/rooms`, {
|
|
44269
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
|
|
44270
|
+
});
|
|
44271
|
+
return queryResponse;
|
|
44272
|
+
}
|
|
44273
|
+
}
|
|
44274
|
+
|
|
44275
|
+
var EnumRoomActions;
|
|
44276
|
+
(function (EnumRoomActions) {
|
|
44277
|
+
EnumRoomActions["OnRoomCreated"] = "OnRoomCreated";
|
|
44278
|
+
EnumRoomActions["OnRoomUpdated"] = "OnRoomUpdated";
|
|
44279
|
+
EnumRoomActions["OnRoomDeleted"] = "OnRoomDeleted";
|
|
44280
|
+
EnumRoomActions["OnRoomStartBroadcasting"] = "OnRoomStartBroadcasting";
|
|
44281
|
+
EnumRoomActions["OnRoomEndBroadcasting"] = "OnRoomEndBroadcasting";
|
|
44282
|
+
EnumRoomActions["OnRoomParticipantJoined"] = "OnRoomParticipantJoined";
|
|
44283
|
+
EnumRoomActions["OnRoomParticipantLeft"] = "OnRoomParticipantLeft";
|
|
44284
|
+
})(EnumRoomActions || (EnumRoomActions = {}));
|
|
44285
|
+
|
|
44286
|
+
class RoomQueryStreamController extends QueryStreamController {
|
|
44287
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
44288
|
+
super(query, cacheKey);
|
|
44289
|
+
this.notifyChange = notifyChange;
|
|
44290
|
+
this.preparePayload = preparePayload;
|
|
44291
|
+
}
|
|
44292
|
+
async saveToMainDB(response) {
|
|
44293
|
+
const processedPayload = await this.preparePayload(response);
|
|
44294
|
+
const client = getActiveClient();
|
|
44295
|
+
const cachedAt = client.cache && Date.now();
|
|
44296
|
+
if (client.cache) {
|
|
44297
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
44298
|
+
}
|
|
44299
|
+
}
|
|
44300
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
44301
|
+
var _a, _b;
|
|
44302
|
+
if (refresh) {
|
|
44303
|
+
pushToCache(this.cacheKey, {
|
|
44304
|
+
data: response.rooms.map(getResolver('room')),
|
|
44305
|
+
});
|
|
44306
|
+
}
|
|
44307
|
+
else {
|
|
44308
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
44309
|
+
const rooms = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
44310
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...rooms, ...response.rooms.map(getResolver('room'))])] }));
|
|
44311
|
+
}
|
|
44312
|
+
}
|
|
44313
|
+
reactor(action) {
|
|
44314
|
+
return (room) => {
|
|
44315
|
+
var _a;
|
|
44316
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
44317
|
+
if (!collection)
|
|
44318
|
+
return;
|
|
44319
|
+
if (action === EnumRoomActions.OnRoomDeleted) {
|
|
44320
|
+
collection.data = collection.data.filter(roomId => roomId !== room._id);
|
|
44321
|
+
}
|
|
44322
|
+
if (action === EnumRoomActions.OnRoomCreated) {
|
|
44323
|
+
collection.data = [...new Set([room._id, ...collection.data])];
|
|
44324
|
+
}
|
|
44325
|
+
pushToCache(this.cacheKey, collection);
|
|
44326
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
44327
|
+
};
|
|
44328
|
+
}
|
|
44329
|
+
subscribeRTE(createSubscriber) {
|
|
44330
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
44331
|
+
}
|
|
44332
|
+
}
|
|
44333
|
+
|
|
44334
|
+
// TODO: confirm related events
|
|
44335
|
+
const getRoomSubscription = () => [
|
|
44336
|
+
{
|
|
44337
|
+
fn: onRoomStartBroadcasting,
|
|
44338
|
+
action: EnumRoomActions.OnRoomStartBroadcasting,
|
|
44339
|
+
},
|
|
44340
|
+
{
|
|
44341
|
+
fn: onRoomEndBroadcasting,
|
|
44342
|
+
action: EnumRoomActions.OnRoomEndBroadcasting,
|
|
44343
|
+
},
|
|
44344
|
+
{
|
|
44345
|
+
fn: onRoomRecordedAvailable,
|
|
44346
|
+
action: EnumRoomActions.OnRoomUpdated,
|
|
44347
|
+
},
|
|
44348
|
+
];
|
|
44349
|
+
|
|
44350
|
+
class RoomLiveCollectionController extends LiveCollectionController {
|
|
44351
|
+
constructor(query, callback) {
|
|
44352
|
+
const queryStreamId = hash(query);
|
|
44353
|
+
const cacheKey = ['rooms', 'collection', queryStreamId];
|
|
44354
|
+
const paginationController = new RoomPaginationController(query);
|
|
44355
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
44356
|
+
this.query = query;
|
|
44357
|
+
this.queryStreamController = new RoomQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
|
|
44358
|
+
this.callback = callback.bind(this);
|
|
44359
|
+
this.loadPage({ initial: true });
|
|
44360
|
+
}
|
|
44361
|
+
setup() {
|
|
44362
|
+
var _a;
|
|
44363
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
44364
|
+
if (!collection) {
|
|
44365
|
+
pushToCache(this.cacheKey, {
|
|
44366
|
+
data: [],
|
|
44367
|
+
params: {},
|
|
44368
|
+
});
|
|
44369
|
+
}
|
|
44370
|
+
}
|
|
44371
|
+
async persistModel(queryPayload) {
|
|
44372
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
44373
|
+
}
|
|
44374
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
44375
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
44376
|
+
}
|
|
44377
|
+
startSubscription() {
|
|
44378
|
+
return this.queryStreamController.subscribeRTE(getRoomSubscription());
|
|
44379
|
+
}
|
|
44380
|
+
notifyChange({ origin, loading, error }) {
|
|
44381
|
+
var _a, _b;
|
|
44382
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
44383
|
+
if (!collection)
|
|
44384
|
+
return;
|
|
44385
|
+
const data = this.applyFilter((_b = collection.data
|
|
44386
|
+
.map(id => pullFromCache(['room', 'get', id]))
|
|
44387
|
+
.filter(isNonNullable)
|
|
44388
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(room => room); // Since Room is same as InternalRoom, no transformation needed
|
|
44389
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
44390
|
+
return;
|
|
44391
|
+
this.callback({
|
|
44392
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
44393
|
+
data,
|
|
44394
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
44395
|
+
loading,
|
|
44396
|
+
error,
|
|
44397
|
+
});
|
|
44398
|
+
}
|
|
44399
|
+
applyFilter(data) {
|
|
44400
|
+
let rooms = data;
|
|
44401
|
+
if (!this.query.includeDeleted) {
|
|
44402
|
+
rooms = filterByPropEquality(rooms, 'isDeleted', false);
|
|
44403
|
+
}
|
|
44404
|
+
if (this.query.statuses && this.query.statuses.length > 0) {
|
|
44405
|
+
rooms = rooms.filter(room => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(room.status); });
|
|
44406
|
+
}
|
|
44407
|
+
if (this.query.type) {
|
|
44408
|
+
rooms = filterByPropEquality(rooms, 'type', this.query.type);
|
|
44409
|
+
}
|
|
44410
|
+
switch (this.query.sortBy) {
|
|
44411
|
+
case 'firstCreated':
|
|
44412
|
+
rooms = rooms.sort(sortByFirstCreated);
|
|
44413
|
+
break;
|
|
44414
|
+
case 'lastCreated':
|
|
44415
|
+
default:
|
|
44416
|
+
rooms = rooms.sort(sortByLastCreated);
|
|
44417
|
+
break;
|
|
44418
|
+
}
|
|
44419
|
+
return rooms;
|
|
44420
|
+
}
|
|
44421
|
+
}
|
|
44422
|
+
|
|
44423
|
+
/* begin_public_function
|
|
44424
|
+
id: room.get_rooms
|
|
44425
|
+
*/
|
|
44426
|
+
/**
|
|
44427
|
+
* ```js
|
|
44428
|
+
* import { RoomRepository } from '@amityco/ts-sdk'
|
|
44429
|
+
*
|
|
44430
|
+
* let rooms = []
|
|
44431
|
+
* const unsub = RoomRepository.getRooms({
|
|
44432
|
+
* type: 'direct_streaming',
|
|
44433
|
+
* statuses: ['live', 'idle'],
|
|
44434
|
+
* sortBy: 'lastCreated',
|
|
44435
|
+
* limit: 20,
|
|
44436
|
+
* includeDeleted: false
|
|
44437
|
+
* }, response => merge(rooms, response.data))
|
|
44438
|
+
* ```
|
|
44439
|
+
*
|
|
44440
|
+
* Observe all mutations on a list of {@link Amity.Room} for a given query
|
|
44441
|
+
*
|
|
44442
|
+
* @param params.type the type of rooms to filter by ('direct_streaming' | 'co_hosts')
|
|
44443
|
+
* @param params.statuses array of room statuses to filter by (['idle', 'live', 'waiting_reconnect', 'ended', 'recorded'])
|
|
44444
|
+
* @param params.sortBy sort rooms by creation time ('firstCreated' | 'lastCreated')
|
|
44445
|
+
* @param params.limit maximum number of rooms to retrieve per page
|
|
44446
|
+
* @param params.includeDeleted whether to include deleted rooms in the results
|
|
44447
|
+
* @param callback the function to call when new data are available
|
|
44448
|
+
* @param config optional configuration for the live collection
|
|
44449
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the rooms
|
|
44450
|
+
*
|
|
44451
|
+
* @category Rooms Live Collection
|
|
44452
|
+
*/
|
|
44453
|
+
const getRooms = (params, callback, config) => {
|
|
44454
|
+
const { log, cache } = getActiveClient();
|
|
44455
|
+
if (!cache) {
|
|
44456
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
44457
|
+
}
|
|
44458
|
+
const timestamp = Date.now();
|
|
44459
|
+
log(`getRooms(tmpid: ${timestamp}) > listen`);
|
|
44460
|
+
const roomsLiveCollection = new RoomLiveCollectionController(params, callback);
|
|
44461
|
+
const disposers = roomsLiveCollection.startSubscription();
|
|
44462
|
+
const cacheKey = roomsLiveCollection.getCacheKey();
|
|
44463
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
44464
|
+
return () => {
|
|
44465
|
+
log(`getRooms(tmpid: ${timestamp}) > dispose`);
|
|
44466
|
+
disposers.forEach(fn => fn());
|
|
44467
|
+
};
|
|
44468
|
+
};
|
|
44469
|
+
/* end_public_function */
|
|
44470
|
+
|
|
44471
|
+
var index$7 = /*#__PURE__*/Object.freeze({
|
|
44472
|
+
__proto__: null,
|
|
44473
|
+
createRoom: createRoom,
|
|
44474
|
+
updateRoom: updateRoom,
|
|
44475
|
+
deleteRoom: deleteRoom,
|
|
44476
|
+
stopRoom: stopRoom,
|
|
44477
|
+
getBroadcasterData: getBroadcasterData,
|
|
44478
|
+
getRecordedUrl: getRecordedUrl,
|
|
44479
|
+
onRoomStartBroadcasting: onRoomStartBroadcasting,
|
|
44480
|
+
onRoomWaitingReconnect: onRoomWaitingReconnect,
|
|
44481
|
+
onRoomEndBroadcasting: onRoomEndBroadcasting,
|
|
44482
|
+
onRoomRecordedAvailable: onRoomRecordedAvailable,
|
|
44483
|
+
onRoomParticipantInviting: onRoomParticipantInviting,
|
|
44484
|
+
onRoomParticipantJoined: onRoomParticipantJoined,
|
|
44485
|
+
onRoomParticipantLeft: onRoomParticipantLeft,
|
|
44486
|
+
onRoomCreated: onRoomCreated,
|
|
44487
|
+
onRoomUpdated: onRoomUpdated,
|
|
44488
|
+
onRoomDeleted: onRoomDeleted,
|
|
44489
|
+
onRoomStopped: onRoomStopped,
|
|
44490
|
+
getRoom: getRoom,
|
|
44491
|
+
getRooms: getRooms
|
|
44492
|
+
});
|
|
44493
|
+
|
|
43806
44494
|
/* begin_public_function
|
|
43807
44495
|
id: poll.create
|
|
43808
44496
|
*/
|
|
@@ -44103,7 +44791,7 @@ const getPoll = (pollId, callback) => {
|
|
|
44103
44791
|
};
|
|
44104
44792
|
/* end_public_function */
|
|
44105
44793
|
|
|
44106
|
-
var index$
|
|
44794
|
+
var index$6 = /*#__PURE__*/Object.freeze({
|
|
44107
44795
|
__proto__: null,
|
|
44108
44796
|
createPoll: createPoll,
|
|
44109
44797
|
closePoll: closePoll,
|
|
@@ -44486,7 +45174,7 @@ const getPlayer = async (parameters) => {
|
|
|
44486
45174
|
return video;
|
|
44487
45175
|
};
|
|
44488
45176
|
|
|
44489
|
-
var index$
|
|
45177
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
44490
45178
|
__proto__: null,
|
|
44491
45179
|
getPlayer: getPlayer
|
|
44492
45180
|
});
|
|
@@ -45659,7 +46347,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
|
|
|
45659
46347
|
};
|
|
45660
46348
|
};
|
|
45661
46349
|
|
|
45662
|
-
var index$
|
|
46350
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
45663
46351
|
__proto__: null,
|
|
45664
46352
|
createImageStory: createImageStory,
|
|
45665
46353
|
createVideoStory: createVideoStory,
|
|
@@ -45696,7 +46384,7 @@ const getNetworkAds = async () => {
|
|
|
45696
46384
|
};
|
|
45697
46385
|
};
|
|
45698
46386
|
|
|
45699
|
-
var index$
|
|
46387
|
+
var index$3 = /*#__PURE__*/Object.freeze({
|
|
45700
46388
|
__proto__: null,
|
|
45701
46389
|
getNetworkAds: getNetworkAds
|
|
45702
46390
|
});
|
|
@@ -46087,7 +46775,7 @@ const markTraySeen = async (lastSeenAt) => {
|
|
|
46087
46775
|
};
|
|
46088
46776
|
/* end_public_function */
|
|
46089
46777
|
|
|
46090
|
-
var index$
|
|
46778
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
46091
46779
|
__proto__: null,
|
|
46092
46780
|
getNotificationTraySeen: getNotificationTraySeen,
|
|
46093
46781
|
getNotificationTrayItems: getNotificationTrayItems,
|
|
@@ -46288,7 +46976,7 @@ const getMyCommunityInvitations = (params, callback, config) => {
|
|
|
46288
46976
|
};
|
|
46289
46977
|
};
|
|
46290
46978
|
|
|
46291
|
-
var index$
|
|
46979
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
46292
46980
|
__proto__: null,
|
|
46293
46981
|
onLocalInvitationCreated: onLocalInvitationCreated,
|
|
46294
46982
|
onLocalInvitationUpdated: onLocalInvitationUpdated,
|
|
@@ -46429,424 +47117,11 @@ const getReactions = (postId, callback) => {
|
|
|
46429
47117
|
};
|
|
46430
47118
|
};
|
|
46431
47119
|
|
|
46432
|
-
var index
|
|
47120
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
46433
47121
|
__proto__: null,
|
|
46434
47122
|
createReaction: createReaction,
|
|
46435
47123
|
onLiveReactionCreated: onLiveReactionCreated,
|
|
46436
47124
|
getReactions: getReactions
|
|
46437
47125
|
});
|
|
46438
47126
|
|
|
46439
|
-
|
|
46440
|
-
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
46441
|
-
};
|
|
46442
|
-
|
|
46443
|
-
const createEventEventSubscriber = (event, callback) => {
|
|
46444
|
-
const client = getActiveClient();
|
|
46445
|
-
const filter = (payload) => {
|
|
46446
|
-
const unpackedPayload = prepareEventPayload(payload);
|
|
46447
|
-
if (!client.cache) {
|
|
46448
|
-
callback(unpackedPayload.events[0]);
|
|
46449
|
-
}
|
|
46450
|
-
else {
|
|
46451
|
-
ingestInCache(unpackedPayload);
|
|
46452
|
-
const event = pullFromCache([
|
|
46453
|
-
'event',
|
|
46454
|
-
'get',
|
|
46455
|
-
unpackedPayload.events[0].eventId,
|
|
46456
|
-
]);
|
|
46457
|
-
callback(event.data);
|
|
46458
|
-
}
|
|
46459
|
-
};
|
|
46460
|
-
return createEventSubscriber(client, event, event, filter);
|
|
46461
|
-
};
|
|
46462
|
-
|
|
46463
|
-
/* begin_public_function
|
|
46464
|
-
id: event.create
|
|
46465
|
-
*/
|
|
46466
|
-
/**
|
|
46467
|
-
* ```js
|
|
46468
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46469
|
-
* const response = await EventRepository.createEvent(bundle)
|
|
46470
|
-
* ```
|
|
46471
|
-
*
|
|
46472
|
-
* Creates an {@link Amity.Event}
|
|
46473
|
-
*
|
|
46474
|
-
* @param bundle The data necessary to create a new {@link Amity.Event}
|
|
46475
|
-
* @returns The newly created {@link Amity.Event}
|
|
46476
|
-
*
|
|
46477
|
-
* @category Event API
|
|
46478
|
-
* @async
|
|
46479
|
-
*/
|
|
46480
|
-
const createEvent = async (bundle) => {
|
|
46481
|
-
const client = getActiveClient();
|
|
46482
|
-
client.log('event/createEvent', bundle);
|
|
46483
|
-
const { data: payload } = await client.http.post('/api/v1/events', bundle);
|
|
46484
|
-
fireEvent('event.created', payload);
|
|
46485
|
-
const preparedPayload = prepareEventPayload(payload);
|
|
46486
|
-
const cachedAt = client.cache && Date.now();
|
|
46487
|
-
if (client.cache)
|
|
46488
|
-
ingestInCache(preparedPayload, { cachedAt });
|
|
46489
|
-
return {
|
|
46490
|
-
data: eventLinkedObject(preparedPayload.events[0]),
|
|
46491
|
-
cachedAt,
|
|
46492
|
-
};
|
|
46493
|
-
};
|
|
46494
|
-
/* end_public_function */
|
|
46495
|
-
|
|
46496
|
-
/* begin_public_function
|
|
46497
|
-
id: event.update
|
|
46498
|
-
*/
|
|
46499
|
-
/**
|
|
46500
|
-
* ```js
|
|
46501
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46502
|
-
* const response = await EventRepository.updateEvent(eventId, bundle)
|
|
46503
|
-
* ```
|
|
46504
|
-
*
|
|
46505
|
-
* Updates an {@link Amity.Event}
|
|
46506
|
-
*
|
|
46507
|
-
* @param eventId The ID of the {@link Amity.Event} to edit
|
|
46508
|
-
* @param bundle The data necessary to update an existing {@link Amity.Event}
|
|
46509
|
-
* @returns the updated {@link Amity.Event}
|
|
46510
|
-
*
|
|
46511
|
-
* @category Event API
|
|
46512
|
-
* @async
|
|
46513
|
-
*/
|
|
46514
|
-
const updateEvent = async (eventId, bundle) => {
|
|
46515
|
-
const client = getActiveClient();
|
|
46516
|
-
client.log('event/updateEvent', eventId, bundle);
|
|
46517
|
-
const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
|
|
46518
|
-
fireEvent('event.updated', payload);
|
|
46519
|
-
const preparedPayload = prepareEventPayload(payload);
|
|
46520
|
-
const cachedAt = client.cache && Date.now();
|
|
46521
|
-
if (client.cache)
|
|
46522
|
-
ingestInCache(preparedPayload, { cachedAt });
|
|
46523
|
-
return {
|
|
46524
|
-
data: eventLinkedObject(preparedPayload.events.find(event => event.eventId === eventId)),
|
|
46525
|
-
cachedAt,
|
|
46526
|
-
};
|
|
46527
|
-
};
|
|
46528
|
-
/* end_public_function */
|
|
46529
|
-
|
|
46530
|
-
/* begin_public_function
|
|
46531
|
-
id: event.get
|
|
46532
|
-
*/
|
|
46533
|
-
/**
|
|
46534
|
-
* ```js
|
|
46535
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46536
|
-
* const event = await EventRepository.getEvent(eventId)
|
|
46537
|
-
* ```
|
|
46538
|
-
*
|
|
46539
|
-
* Fetches a {@link Amity.Event} object
|
|
46540
|
-
*
|
|
46541
|
-
* @param eventId the ID of the {@link Amity.Event} to fetch
|
|
46542
|
-
* @returns the associated {@link Amity.Event} object
|
|
46543
|
-
*
|
|
46544
|
-
* @category Event API
|
|
46545
|
-
* @async
|
|
46546
|
-
*/
|
|
46547
|
-
const getEvent$1 = async (eventId) => {
|
|
46548
|
-
const client = getActiveClient();
|
|
46549
|
-
client.log('event/getEvent', eventId);
|
|
46550
|
-
const { data: payload } = await client.http.get(`/api/v3/events/${eventId}`);
|
|
46551
|
-
const data = prepareEventPayload(payload);
|
|
46552
|
-
const cachedAt = client.cache && Date.now();
|
|
46553
|
-
if (client.cache)
|
|
46554
|
-
ingestInCache(data, { cachedAt });
|
|
46555
|
-
return {
|
|
46556
|
-
data: data.events.find(event => event.eventId === eventId),
|
|
46557
|
-
cachedAt,
|
|
46558
|
-
};
|
|
46559
|
-
};
|
|
46560
|
-
/* end_public_function */
|
|
46561
|
-
/**
|
|
46562
|
-
* ```js
|
|
46563
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46564
|
-
* const event = EventRepository.getEvent.locally(eventId)
|
|
46565
|
-
* ```
|
|
46566
|
-
*
|
|
46567
|
-
* Fetches a {@link Amity.Event} object in cache
|
|
46568
|
-
*
|
|
46569
|
-
* @param eventId the ID of the {@link Amity.Event} to fetch
|
|
46570
|
-
* @returns the associated {@link Amity.Event} object
|
|
46571
|
-
*
|
|
46572
|
-
* @category Event API
|
|
46573
|
-
*/
|
|
46574
|
-
getEvent$1.locally = (eventId) => {
|
|
46575
|
-
const client = getActiveClient();
|
|
46576
|
-
client.log('event/getEvent.locally', eventId);
|
|
46577
|
-
if (!client.cache)
|
|
46578
|
-
return;
|
|
46579
|
-
const cache = pullFromCache(['event', 'get', eventId]);
|
|
46580
|
-
if (!cache)
|
|
46581
|
-
return;
|
|
46582
|
-
return {
|
|
46583
|
-
data: cache.data,
|
|
46584
|
-
cachedAt: cache.cachedAt,
|
|
46585
|
-
};
|
|
46586
|
-
};
|
|
46587
|
-
|
|
46588
|
-
/* begin_public_function
|
|
46589
|
-
id: event.delete
|
|
46590
|
-
*/
|
|
46591
|
-
/**
|
|
46592
|
-
* ```js
|
|
46593
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46594
|
-
* const { success } = await EventRepository.deleteEvent(eventId)
|
|
46595
|
-
* ```
|
|
46596
|
-
*
|
|
46597
|
-
* Deletes a {@link Amity.Event}
|
|
46598
|
-
*
|
|
46599
|
-
* @param eventId The {@link Amity.Event} ID to delete
|
|
46600
|
-
*
|
|
46601
|
-
* @category Event API
|
|
46602
|
-
* @async
|
|
46603
|
-
*/
|
|
46604
|
-
const deleteEvent = async (eventId) => {
|
|
46605
|
-
const client = getActiveClient();
|
|
46606
|
-
client.log('event/deleteEvent', eventId);
|
|
46607
|
-
const event = await getEvent$1(eventId);
|
|
46608
|
-
await client.http.delete(`/api/v3/events/${eventId}`);
|
|
46609
|
-
const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
|
|
46610
|
-
upsertInCache(['event', 'get', eventId], deletedEvent);
|
|
46611
|
-
fireEvent('event.deleted', {
|
|
46612
|
-
users: [],
|
|
46613
|
-
files: [],
|
|
46614
|
-
communities: [],
|
|
46615
|
-
videoStreamings: [],
|
|
46616
|
-
events: [deletedEvent],
|
|
46617
|
-
discussionCommunities: [],
|
|
46618
|
-
});
|
|
46619
|
-
};
|
|
46620
|
-
/* end_public_function */
|
|
46621
|
-
|
|
46622
|
-
/**
|
|
46623
|
-
* ```js
|
|
46624
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46625
|
-
* const dispose = EventRepository.onEventCreated(event => {
|
|
46626
|
-
* // ...
|
|
46627
|
-
* })
|
|
46628
|
-
* ```
|
|
46629
|
-
*
|
|
46630
|
-
* Fired when a {@link Amity.Event} has been created
|
|
46631
|
-
*
|
|
46632
|
-
* @param callback The function to call when the event was fired
|
|
46633
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
46634
|
-
*
|
|
46635
|
-
* @category Event Events
|
|
46636
|
-
*/
|
|
46637
|
-
const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
|
|
46638
|
-
|
|
46639
|
-
/**
|
|
46640
|
-
* ```js
|
|
46641
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46642
|
-
* const dispose = EventRepository.onEventUpdated(event => {
|
|
46643
|
-
* // ...
|
|
46644
|
-
* })
|
|
46645
|
-
* ```
|
|
46646
|
-
*
|
|
46647
|
-
* Fired when a {@link Amity.Event} has been updated
|
|
46648
|
-
*
|
|
46649
|
-
* @param callback The function to call when the event was fired
|
|
46650
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
46651
|
-
*
|
|
46652
|
-
* @category Event Events
|
|
46653
|
-
*/
|
|
46654
|
-
const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
|
|
46655
|
-
|
|
46656
|
-
/**
|
|
46657
|
-
* ```js
|
|
46658
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
46659
|
-
* const dispose = EventRepository.onEventDeleted(event => {
|
|
46660
|
-
* // ...
|
|
46661
|
-
* })
|
|
46662
|
-
* ```
|
|
46663
|
-
*
|
|
46664
|
-
* Fired when a {@link Amity.Event} has been deleted
|
|
46665
|
-
*
|
|
46666
|
-
* @param callback The function to call when the event was fired
|
|
46667
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
46668
|
-
*
|
|
46669
|
-
* @category Event Events
|
|
46670
|
-
*/
|
|
46671
|
-
const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
|
|
46672
|
-
|
|
46673
|
-
/* begin_public_function
|
|
46674
|
-
id: event.get
|
|
46675
|
-
*/
|
|
46676
|
-
/**
|
|
46677
|
-
* ```js
|
|
46678
|
-
* import { EventRepository } from '@amityco/ts-sdk';
|
|
46679
|
-
*
|
|
46680
|
-
* let event;
|
|
46681
|
-
*
|
|
46682
|
-
* const unsubscribe = EventRepository.getEvent(eventId, response => {
|
|
46683
|
-
* event = response.data;
|
|
46684
|
-
* });
|
|
46685
|
-
* ```
|
|
46686
|
-
*
|
|
46687
|
-
* Observe all mutation on a given {@link Amity.Event}
|
|
46688
|
-
*
|
|
46689
|
-
* @param eventId the ID of the event to observe
|
|
46690
|
-
* @param callback the function to call when new snapshot of event are available
|
|
46691
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the event
|
|
46692
|
-
*
|
|
46693
|
-
* @category Event Live Object
|
|
46694
|
-
*/
|
|
46695
|
-
const getEvent = (eventId, callback) => {
|
|
46696
|
-
return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventCreated, onEventUpdated, onEventDeleted], {
|
|
46697
|
-
callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
|
|
46698
|
-
});
|
|
46699
|
-
};
|
|
46700
|
-
/* end_public_function */
|
|
46701
|
-
|
|
46702
|
-
var EventActionsEnum;
|
|
46703
|
-
(function (EventActionsEnum) {
|
|
46704
|
-
EventActionsEnum["OnEventCreated"] = "onEventCreated";
|
|
46705
|
-
EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
|
|
46706
|
-
EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
|
|
46707
|
-
})(EventActionsEnum || (EventActionsEnum = {}));
|
|
46708
|
-
|
|
46709
|
-
class EventPaginationController extends PaginationController {
|
|
46710
|
-
async getRequest(queryParams, token) {
|
|
46711
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
46712
|
-
const options = token ? { token } : { limit };
|
|
46713
|
-
const { data: response } = await this.http.get(`/api/v1/events`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
46714
|
-
return response;
|
|
46715
|
-
}
|
|
46716
|
-
}
|
|
46717
|
-
|
|
46718
|
-
class EventQueryStreamController extends QueryStreamController {
|
|
46719
|
-
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
46720
|
-
super(query, cacheKey);
|
|
46721
|
-
this.notifyChange = notifyChange;
|
|
46722
|
-
this.preparePayload = preparePayload;
|
|
46723
|
-
}
|
|
46724
|
-
async saveToMainDB(response) {
|
|
46725
|
-
const processedPayload = this.preparePayload(response);
|
|
46726
|
-
const client = getActiveClient();
|
|
46727
|
-
const cachedAt = client.cache && Date.now();
|
|
46728
|
-
if (client.cache)
|
|
46729
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
46730
|
-
}
|
|
46731
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
46732
|
-
var _a, _b;
|
|
46733
|
-
if (refresh) {
|
|
46734
|
-
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
46735
|
-
}
|
|
46736
|
-
else {
|
|
46737
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46738
|
-
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
46739
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
46740
|
-
}
|
|
46741
|
-
}
|
|
46742
|
-
reactor(action) {
|
|
46743
|
-
return (event) => {
|
|
46744
|
-
var _a;
|
|
46745
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46746
|
-
if (!collection)
|
|
46747
|
-
return;
|
|
46748
|
-
if (action === EventActionsEnum.OnEventCreated) {
|
|
46749
|
-
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
46750
|
-
}
|
|
46751
|
-
if (action === EventActionsEnum.OnEventDeleted) {
|
|
46752
|
-
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
46753
|
-
}
|
|
46754
|
-
pushToCache(this.cacheKey, collection);
|
|
46755
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
46756
|
-
};
|
|
46757
|
-
}
|
|
46758
|
-
subscribeRTE(createSubscriber) {
|
|
46759
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
46760
|
-
}
|
|
46761
|
-
}
|
|
46762
|
-
|
|
46763
|
-
class EventLiveCollectionController extends LiveCollectionController {
|
|
46764
|
-
constructor(query, callback) {
|
|
46765
|
-
const queryStreamId = hash(query);
|
|
46766
|
-
const cacheKey = ['event', 'collection', queryStreamId];
|
|
46767
|
-
const paginationController = new EventPaginationController(query);
|
|
46768
|
-
super(paginationController, queryStreamId, cacheKey, callback);
|
|
46769
|
-
this.query = query;
|
|
46770
|
-
this.queryStreamController = new EventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
46771
|
-
this.callback = callback.bind(this);
|
|
46772
|
-
this.loadPage({ initial: true });
|
|
46773
|
-
}
|
|
46774
|
-
setup() {
|
|
46775
|
-
var _a;
|
|
46776
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46777
|
-
if (!collection)
|
|
46778
|
-
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
46779
|
-
}
|
|
46780
|
-
async persistModel(queryPayload) {
|
|
46781
|
-
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
46782
|
-
}
|
|
46783
|
-
persistQueryStream({ response, direction, refresh, }) {
|
|
46784
|
-
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
46785
|
-
}
|
|
46786
|
-
startSubscription() {
|
|
46787
|
-
return this.queryStreamController.subscribeRTE([
|
|
46788
|
-
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
46789
|
-
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
46790
|
-
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
46791
|
-
]);
|
|
46792
|
-
}
|
|
46793
|
-
notifyChange({ origin, loading, error }) {
|
|
46794
|
-
var _a, _b;
|
|
46795
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
46796
|
-
if (!collection)
|
|
46797
|
-
return;
|
|
46798
|
-
const data = ((_b = collection.data
|
|
46799
|
-
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
46800
|
-
.filter(isNonNullable)
|
|
46801
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
46802
|
-
if (!this.shouldNotify(data) && origin === 'event')
|
|
46803
|
-
return;
|
|
46804
|
-
this.callback({
|
|
46805
|
-
data,
|
|
46806
|
-
error,
|
|
46807
|
-
loading,
|
|
46808
|
-
hasNextPage: !!this.paginationController.getNextToken(),
|
|
46809
|
-
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
46810
|
-
});
|
|
46811
|
-
}
|
|
46812
|
-
}
|
|
46813
|
-
|
|
46814
|
-
/**
|
|
46815
|
-
* Get events
|
|
46816
|
-
*
|
|
46817
|
-
* @param params the query parameters
|
|
46818
|
-
* @param callback the callback to be called when the events are updated
|
|
46819
|
-
* @returns events
|
|
46820
|
-
*
|
|
46821
|
-
* @category Event Live Collection
|
|
46822
|
-
*
|
|
46823
|
-
*/
|
|
46824
|
-
const getEvents = (params, callback, config) => {
|
|
46825
|
-
const { log, cache } = getActiveClient();
|
|
46826
|
-
if (!cache)
|
|
46827
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
46828
|
-
const timestamp = Date.now();
|
|
46829
|
-
log(`getEvents: (tmpid: ${timestamp}) > listen`);
|
|
46830
|
-
const eventLiveCollection = new EventLiveCollectionController(params, callback);
|
|
46831
|
-
const disposers = eventLiveCollection.startSubscription();
|
|
46832
|
-
const cacheKey = eventLiveCollection.getCacheKey();
|
|
46833
|
-
disposers.push(() => dropFromCache(cacheKey));
|
|
46834
|
-
return () => {
|
|
46835
|
-
log(`getEvents (tmpid: ${timestamp}) > dispose`);
|
|
46836
|
-
disposers.forEach(fn => fn());
|
|
46837
|
-
};
|
|
46838
|
-
};
|
|
46839
|
-
|
|
46840
|
-
var index = /*#__PURE__*/Object.freeze({
|
|
46841
|
-
__proto__: null,
|
|
46842
|
-
createEvent: createEvent,
|
|
46843
|
-
updateEvent: updateEvent,
|
|
46844
|
-
deleteEvent: deleteEvent,
|
|
46845
|
-
onEventCreated: onEventCreated,
|
|
46846
|
-
onEventUpdated: onEventUpdated,
|
|
46847
|
-
onEventDeleted: onEventDeleted,
|
|
46848
|
-
getEvent: getEvent,
|
|
46849
|
-
getEvents: getEvents
|
|
46850
|
-
});
|
|
46851
|
-
|
|
46852
|
-
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 };
|
|
47127
|
+
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 };
|