@amityco/ts-sdk-react-native 7.11.1-58c097c.0 → 7.11.1-b5390a83.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 +11 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +3 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +6 -0
- package/dist/@types/core/payload.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/post.d.ts +2 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/room.d.ts +76 -0
- package/dist/@types/domains/room.d.ts.map +1 -0
- package/dist/@types/index.d.ts +2 -0
- 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/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/index.cjs.js +775 -36
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +762 -24
- package/dist/index.umd.js +3 -3
- 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 +4 -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/postLinkedObject.d.ts.map +1 -1
- 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/index.esm.js
CHANGED
|
@@ -114,6 +114,7 @@ const PostContentType = Object.freeze({
|
|
|
114
114
|
POLL: 'poll',
|
|
115
115
|
CLIP: 'clip',
|
|
116
116
|
AUDIO: 'audio',
|
|
117
|
+
ROOM: 'room',
|
|
117
118
|
});
|
|
118
119
|
const PostStructureType = Object.freeze({
|
|
119
120
|
TEXT: 'text',
|
|
@@ -627,6 +628,7 @@ const idResolvers = {
|
|
|
627
628
|
notificationTraySeen: ({ userId }) => userId,
|
|
628
629
|
invitation: ({ _id }) => _id,
|
|
629
630
|
joinRequest: ({ joinRequestId }) => joinRequestId,
|
|
631
|
+
room: ({ roomId }) => roomId,
|
|
630
632
|
};
|
|
631
633
|
/**
|
|
632
634
|
* Retrieve the id resolver matching a domain name
|
|
@@ -682,6 +684,7 @@ const PAYLOAD2MODEL = {
|
|
|
682
684
|
notificationTrayItems: 'notificationTrayItem',
|
|
683
685
|
invitations: 'invitation',
|
|
684
686
|
joinRequests: 'joinRequest',
|
|
687
|
+
rooms: 'room',
|
|
685
688
|
};
|
|
686
689
|
/** hidden */
|
|
687
690
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -26697,7 +26700,7 @@ const getUserUnread = (callback) => {
|
|
|
26697
26700
|
};
|
|
26698
26701
|
};
|
|
26699
26702
|
|
|
26700
|
-
var index$
|
|
26703
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
26701
26704
|
__proto__: null,
|
|
26702
26705
|
getActiveClient: getActiveClient,
|
|
26703
26706
|
getActiveUser: getActiveUser,
|
|
@@ -27919,7 +27922,7 @@ const getMyFollowInfo = (callback) => {
|
|
|
27919
27922
|
};
|
|
27920
27923
|
/* end_public_function */
|
|
27921
27924
|
|
|
27922
|
-
var index$
|
|
27925
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
27923
27926
|
__proto__: null,
|
|
27924
27927
|
blockUser: blockUser,
|
|
27925
27928
|
unBlockUser: unBlockUser,
|
|
@@ -28447,6 +28450,12 @@ function isAmityAudioPost(post) {
|
|
|
28447
28450
|
'fileId' in post.data &&
|
|
28448
28451
|
post.dataType === 'audio');
|
|
28449
28452
|
}
|
|
28453
|
+
function isAmityRoomPost(post) {
|
|
28454
|
+
return !!(post.data &&
|
|
28455
|
+
typeof post.data !== 'string' &&
|
|
28456
|
+
'roomId' in post.data &&
|
|
28457
|
+
post.dataType === 'room');
|
|
28458
|
+
}
|
|
28450
28459
|
|
|
28451
28460
|
const postLinkedObject = (post) => {
|
|
28452
28461
|
return shallowClone(post, {
|
|
@@ -28541,6 +28550,12 @@ const postLinkedObject = (post) => {
|
|
|
28541
28550
|
? (_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
|
|
28542
28551
|
: undefined;
|
|
28543
28552
|
},
|
|
28553
|
+
getRoomInfo() {
|
|
28554
|
+
var _a, _b;
|
|
28555
|
+
if (!isAmityRoomPost(post))
|
|
28556
|
+
return;
|
|
28557
|
+
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;
|
|
28558
|
+
},
|
|
28544
28559
|
});
|
|
28545
28560
|
};
|
|
28546
28561
|
|
|
@@ -30906,9 +30921,9 @@ var AmityUserSearchMatchType;
|
|
|
30906
30921
|
AmityUserSearchMatchType["PARTIAL"] = "partial";
|
|
30907
30922
|
})(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
|
|
30908
30923
|
|
|
30909
|
-
var index$
|
|
30924
|
+
var index$n = /*#__PURE__*/Object.freeze({
|
|
30910
30925
|
__proto__: null,
|
|
30911
|
-
Relationship: index$
|
|
30926
|
+
Relationship: index$o,
|
|
30912
30927
|
getUserByIds: getUserByIds,
|
|
30913
30928
|
updateUser: updateUser,
|
|
30914
30929
|
flagUser: flagUser,
|
|
@@ -31311,7 +31326,7 @@ const uploadAudio = async (formData, onProgress) => {
|
|
|
31311
31326
|
};
|
|
31312
31327
|
/* end_public_function */
|
|
31313
31328
|
|
|
31314
|
-
var index$
|
|
31329
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
31315
31330
|
__proto__: null,
|
|
31316
31331
|
getFile: getFile,
|
|
31317
31332
|
uploadFile: uploadFile,
|
|
@@ -33123,7 +33138,7 @@ const getReactions$1 = (params, callback, config) => {
|
|
|
33123
33138
|
};
|
|
33124
33139
|
/* end_public_function */
|
|
33125
33140
|
|
|
33126
|
-
var index$
|
|
33141
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
33127
33142
|
__proto__: null,
|
|
33128
33143
|
addReaction: addReaction,
|
|
33129
33144
|
removeReaction: removeReaction,
|
|
@@ -34895,7 +34910,7 @@ const getMessages = (params, callback, config) => {
|
|
|
34895
34910
|
};
|
|
34896
34911
|
/* end_public_function */
|
|
34897
34912
|
|
|
34898
|
-
var index$
|
|
34913
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
34899
34914
|
__proto__: null,
|
|
34900
34915
|
createMessage: createMessage,
|
|
34901
34916
|
updateMessage: updateMessage,
|
|
@@ -35421,7 +35436,7 @@ const stopMessageReceiptSync = (subChannelId) => {
|
|
|
35421
35436
|
};
|
|
35422
35437
|
/* end_public_function */
|
|
35423
35438
|
|
|
35424
|
-
var index$
|
|
35439
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
35425
35440
|
__proto__: null,
|
|
35426
35441
|
getSubChannelByIds: getSubChannels$1,
|
|
35427
35442
|
createSubChannel: createSubChannel,
|
|
@@ -36748,7 +36763,7 @@ const searchMembers$1 = (params, callback, config) => {
|
|
|
36748
36763
|
};
|
|
36749
36764
|
/* end_public_function */
|
|
36750
36765
|
|
|
36751
|
-
var index$
|
|
36766
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
36752
36767
|
__proto__: null,
|
|
36753
36768
|
addMembers: addMembers$1,
|
|
36754
36769
|
removeMembers: removeMembers$1,
|
|
@@ -36951,7 +36966,7 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
36951
36966
|
};
|
|
36952
36967
|
/* end_public_function */
|
|
36953
36968
|
|
|
36954
|
-
var index$
|
|
36969
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
36955
36970
|
__proto__: null,
|
|
36956
36971
|
addRole: addRole,
|
|
36957
36972
|
removeRole: removeRole,
|
|
@@ -36961,10 +36976,10 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
36961
36976
|
unmuteMembers: unmuteMembers
|
|
36962
36977
|
});
|
|
36963
36978
|
|
|
36964
|
-
var index$
|
|
36979
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
36965
36980
|
__proto__: null,
|
|
36966
|
-
Membership: index$
|
|
36967
|
-
Moderation: index$
|
|
36981
|
+
Membership: index$i,
|
|
36982
|
+
Moderation: index$h,
|
|
36968
36983
|
getChannelByIds: getChannelByIds$1,
|
|
36969
36984
|
createChannel: createChannel,
|
|
36970
36985
|
updateChannel: updateChannel,
|
|
@@ -38367,7 +38382,7 @@ const searchMembers = (params, callback, config) => {
|
|
|
38367
38382
|
};
|
|
38368
38383
|
/* end_public_function */
|
|
38369
38384
|
|
|
38370
|
-
var index$
|
|
38385
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
38371
38386
|
__proto__: null,
|
|
38372
38387
|
addMembers: addMembers,
|
|
38373
38388
|
removeMembers: removeMembers,
|
|
@@ -39618,7 +39633,7 @@ const unbanMembers = async (communityId, userIds) => {
|
|
|
39618
39633
|
};
|
|
39619
39634
|
/* end_public_function */
|
|
39620
39635
|
|
|
39621
|
-
var index$
|
|
39636
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
39622
39637
|
__proto__: null,
|
|
39623
39638
|
addRoles: addRoles,
|
|
39624
39639
|
removeRoles: removeRoles,
|
|
@@ -39626,10 +39641,10 @@ var index$d = /*#__PURE__*/Object.freeze({
|
|
|
39626
39641
|
unbanMembers: unbanMembers
|
|
39627
39642
|
});
|
|
39628
39643
|
|
|
39629
|
-
var index$
|
|
39644
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
39630
39645
|
__proto__: null,
|
|
39631
|
-
Moderation: index$
|
|
39632
|
-
Membership: index$
|
|
39646
|
+
Moderation: index$e,
|
|
39647
|
+
Membership: index$f,
|
|
39633
39648
|
getCommunityByIds: getCommunities$1,
|
|
39634
39649
|
createCommunity: createCommunity,
|
|
39635
39650
|
updateCommunity: updateCommunity,
|
|
@@ -39863,7 +39878,7 @@ const getCategories = (params, callback, config) => {
|
|
|
39863
39878
|
};
|
|
39864
39879
|
/* end_public_function */
|
|
39865
39880
|
|
|
39866
|
-
var index$
|
|
39881
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
39867
39882
|
__proto__: null,
|
|
39868
39883
|
getCategory: getCategory,
|
|
39869
39884
|
getCategories: getCategories
|
|
@@ -40922,7 +40937,7 @@ const getComments = (params, callback, config) => {
|
|
|
40922
40937
|
};
|
|
40923
40938
|
/* end_public_function */
|
|
40924
40939
|
|
|
40925
|
-
var index$
|
|
40940
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
40926
40941
|
__proto__: null,
|
|
40927
40942
|
getCommentByIds: getCommentByIds,
|
|
40928
40943
|
createComment: createComment,
|
|
@@ -41593,7 +41608,7 @@ const getUserFeed = (params, callback, config) => {
|
|
|
41593
41608
|
};
|
|
41594
41609
|
/* end_public_function */
|
|
41595
41610
|
|
|
41596
|
-
var index$
|
|
41611
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
41597
41612
|
__proto__: null,
|
|
41598
41613
|
queryGlobalFeed: queryGlobalFeed,
|
|
41599
41614
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
@@ -43274,7 +43289,7 @@ const searchPostsByHashtag = (params, callback, config) => {
|
|
|
43274
43289
|
};
|
|
43275
43290
|
/* end_public_function */
|
|
43276
43291
|
|
|
43277
|
-
var index$
|
|
43292
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
43278
43293
|
__proto__: null,
|
|
43279
43294
|
getPostByIds: getPostByIds,
|
|
43280
43295
|
createPost: createPost,
|
|
@@ -43875,7 +43890,7 @@ const getStreams = (params, callback, config) => {
|
|
|
43875
43890
|
};
|
|
43876
43891
|
/* end_public_function */
|
|
43877
43892
|
|
|
43878
|
-
var index$
|
|
43893
|
+
var index$8 = /*#__PURE__*/Object.freeze({
|
|
43879
43894
|
__proto__: null,
|
|
43880
43895
|
createStream: createStream,
|
|
43881
43896
|
updateStream: updateStream,
|
|
@@ -43893,6 +43908,729 @@ var index$7 = /*#__PURE__*/Object.freeze({
|
|
|
43893
43908
|
getStreams: getStreams
|
|
43894
43909
|
});
|
|
43895
43910
|
|
|
43911
|
+
/* begin_public_function
|
|
43912
|
+
id: room.create
|
|
43913
|
+
*/
|
|
43914
|
+
/**
|
|
43915
|
+
* ```js
|
|
43916
|
+
* import { createRoom } from '@amityco/ts-sdk'
|
|
43917
|
+
* const created = await createRoom({ title: 'my room', 'thumbnailFileId': fileId })
|
|
43918
|
+
* ```
|
|
43919
|
+
*
|
|
43920
|
+
* Creates an {@link Amity.Room}
|
|
43921
|
+
*
|
|
43922
|
+
* @param bundle The data necessary to create a new {@link Amity.Room}
|
|
43923
|
+
* @returns The newly created {@link Amity.Room}
|
|
43924
|
+
*
|
|
43925
|
+
* @category Room API
|
|
43926
|
+
* @async
|
|
43927
|
+
*/
|
|
43928
|
+
const createRoom = async (bundle) => {
|
|
43929
|
+
const client = getActiveClient();
|
|
43930
|
+
client.log('room/createRoom', bundle);
|
|
43931
|
+
const { data } = await client.http.post('/api/v1/rooms', bundle);
|
|
43932
|
+
fireEvent('local.room.created', data);
|
|
43933
|
+
const cachedAt = client.cache && Date.now();
|
|
43934
|
+
// TODO: check if should pick `users` filed which contains participants - if no need to ingest in the cache
|
|
43935
|
+
if (client.cache)
|
|
43936
|
+
ingestInCache(data, { cachedAt });
|
|
43937
|
+
const { rooms } = data;
|
|
43938
|
+
return {
|
|
43939
|
+
data: rooms[0],
|
|
43940
|
+
cachedAt,
|
|
43941
|
+
};
|
|
43942
|
+
};
|
|
43943
|
+
/* end_public_function */
|
|
43944
|
+
|
|
43945
|
+
/* begin_public_function
|
|
43946
|
+
id: room.update
|
|
43947
|
+
*/
|
|
43948
|
+
/**
|
|
43949
|
+
* ```js
|
|
43950
|
+
* import { updateRoom } from '@amityco/ts-sdk'
|
|
43951
|
+
* const updated = await updateRoom('roomId', { title: 'updated title' })
|
|
43952
|
+
* ```
|
|
43953
|
+
*
|
|
43954
|
+
* Updates an {@link Amity.InternalRoom}
|
|
43955
|
+
*
|
|
43956
|
+
* @param roomId The ID of the room to update
|
|
43957
|
+
* @param bundle The data to update the room with
|
|
43958
|
+
* @returns The updated {@link Amity.InternalRoom}
|
|
43959
|
+
*
|
|
43960
|
+
* @category Room API
|
|
43961
|
+
* @async
|
|
43962
|
+
*/
|
|
43963
|
+
const updateRoom = async (roomId, bundle) => {
|
|
43964
|
+
const client = getActiveClient();
|
|
43965
|
+
client.log('room/updateRoom', { roomId, bundle });
|
|
43966
|
+
const { data } = await client.http.put(`/api/v1/rooms/${roomId}`, bundle);
|
|
43967
|
+
fireEvent('local.room.updated', data);
|
|
43968
|
+
const cachedAt = client.cache && Date.now();
|
|
43969
|
+
if (client.cache)
|
|
43970
|
+
ingestInCache(data, { cachedAt });
|
|
43971
|
+
const { rooms } = data;
|
|
43972
|
+
return {
|
|
43973
|
+
data: rooms[0],
|
|
43974
|
+
cachedAt,
|
|
43975
|
+
};
|
|
43976
|
+
};
|
|
43977
|
+
/* end_public_function */
|
|
43978
|
+
|
|
43979
|
+
/* begin_public_function
|
|
43980
|
+
id: room.delete
|
|
43981
|
+
*/
|
|
43982
|
+
/**
|
|
43983
|
+
* ```js
|
|
43984
|
+
* import { deleteRoom } from '@amityco/ts-sdk'
|
|
43985
|
+
* const result = await deleteRoom('roomId')
|
|
43986
|
+
* ```
|
|
43987
|
+
*
|
|
43988
|
+
* Deletes an {@link Amity.Room}
|
|
43989
|
+
*
|
|
43990
|
+
* @param roomId The ID of the room to delete
|
|
43991
|
+
* @returns Promise that resolves when the room is deleted
|
|
43992
|
+
*
|
|
43993
|
+
* @category Room API
|
|
43994
|
+
* @async
|
|
43995
|
+
*/
|
|
43996
|
+
const deleteRoom = async (roomId) => {
|
|
43997
|
+
const client = getActiveClient();
|
|
43998
|
+
client.log('room/deleteRoom', { roomId });
|
|
43999
|
+
await client.http.delete(`/api/v1/rooms/${roomId}`);
|
|
44000
|
+
fireEvent('local.room.deleted', { rooms: [{ _id: roomId }] });
|
|
44001
|
+
};
|
|
44002
|
+
/* end_public_function */
|
|
44003
|
+
|
|
44004
|
+
/* begin_public_function
|
|
44005
|
+
id: room.stop
|
|
44006
|
+
*/
|
|
44007
|
+
/**
|
|
44008
|
+
* ```js
|
|
44009
|
+
* import { stopRoom } from '@amityco/ts-sdk'
|
|
44010
|
+
* const result = await stopRoom('roomId')
|
|
44011
|
+
* ```
|
|
44012
|
+
*
|
|
44013
|
+
* Stops a room's broadcasting
|
|
44014
|
+
*
|
|
44015
|
+
* @param roomId The ID of the room to stop
|
|
44016
|
+
* @returns The updated room data
|
|
44017
|
+
*
|
|
44018
|
+
* @category Room API
|
|
44019
|
+
* @async
|
|
44020
|
+
*/
|
|
44021
|
+
const stopRoom = async (roomId) => {
|
|
44022
|
+
const client = getActiveClient();
|
|
44023
|
+
client.log('room/stopRoom', { roomId });
|
|
44024
|
+
const { data } = await client.http.post(`/api/v1/rooms/${roomId}/stop`);
|
|
44025
|
+
fireEvent('local.room.stopped', data);
|
|
44026
|
+
const cachedAt = client.cache && Date.now();
|
|
44027
|
+
if (client.cache)
|
|
44028
|
+
ingestInCache(data, { cachedAt });
|
|
44029
|
+
const { rooms } = data;
|
|
44030
|
+
return {
|
|
44031
|
+
data: rooms[0],
|
|
44032
|
+
cachedAt,
|
|
44033
|
+
};
|
|
44034
|
+
};
|
|
44035
|
+
/* end_public_function */
|
|
44036
|
+
|
|
44037
|
+
/* begin_public_function
|
|
44038
|
+
id: room.getToken
|
|
44039
|
+
*/
|
|
44040
|
+
/**
|
|
44041
|
+
* ```js
|
|
44042
|
+
* import { getRoomToken } from '@amityco/ts-sdk'
|
|
44043
|
+
* const token = await getRoomToken('roomId')
|
|
44044
|
+
* ```
|
|
44045
|
+
*
|
|
44046
|
+
* Gets an access token for a room
|
|
44047
|
+
*
|
|
44048
|
+
* @param roomId The ID of the room to get token for
|
|
44049
|
+
* @returns The room access token
|
|
44050
|
+
*
|
|
44051
|
+
* @category Room API
|
|
44052
|
+
* @async
|
|
44053
|
+
*/
|
|
44054
|
+
const getRoomToken = async (roomId) => {
|
|
44055
|
+
const client = getActiveClient();
|
|
44056
|
+
client.log('room/getRoomToken', { roomId });
|
|
44057
|
+
const { data } = await client.http.get(`/api/v1/rooms/${roomId}/token`);
|
|
44058
|
+
return data;
|
|
44059
|
+
};
|
|
44060
|
+
/* end_public_function */
|
|
44061
|
+
|
|
44062
|
+
/* begin_public_function
|
|
44063
|
+
id: room.getRecordedUrl
|
|
44064
|
+
*/
|
|
44065
|
+
/**
|
|
44066
|
+
* ```js
|
|
44067
|
+
* import { getRecordedUrl } from '@amityco/ts-sdk'
|
|
44068
|
+
* const recordedUrl = await getRecordedUrl('roomId')
|
|
44069
|
+
* ```
|
|
44070
|
+
*
|
|
44071
|
+
* Gets the recorded URL for a room
|
|
44072
|
+
*
|
|
44073
|
+
* @param roomId The ID of the room to get recorded URL for
|
|
44074
|
+
* @returns The recorded URL information
|
|
44075
|
+
*
|
|
44076
|
+
* @category Room API
|
|
44077
|
+
* @async
|
|
44078
|
+
*/
|
|
44079
|
+
const getRecordedUrl = async (roomId) => {
|
|
44080
|
+
const client = getActiveClient();
|
|
44081
|
+
client.log('room/getRecordedUrl', { roomId });
|
|
44082
|
+
const { data } = await client.http.get(`/api/v1/rooms/${roomId}/recorded`);
|
|
44083
|
+
return data;
|
|
44084
|
+
};
|
|
44085
|
+
/* end_public_function */
|
|
44086
|
+
|
|
44087
|
+
/**
|
|
44088
|
+
* ```js
|
|
44089
|
+
* import { onRoomStartBroadcasting } from '@amityco/ts-sdk'
|
|
44090
|
+
* const dispose = onRoomStartBroadcasting(room => {
|
|
44091
|
+
* // ...
|
|
44092
|
+
* })
|
|
44093
|
+
* ```
|
|
44094
|
+
*
|
|
44095
|
+
* Fired when a {@link Amity.Room} has started broadcasting
|
|
44096
|
+
*
|
|
44097
|
+
* @param callback The function to call when the event was fired
|
|
44098
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44099
|
+
*
|
|
44100
|
+
* @category Room Events
|
|
44101
|
+
*/
|
|
44102
|
+
const onRoomStartBroadcasting = (callback) => {
|
|
44103
|
+
const client = getActiveClient();
|
|
44104
|
+
const filter = (payload) => {
|
|
44105
|
+
ingestInCache(payload);
|
|
44106
|
+
callback(payload.rooms[0]);
|
|
44107
|
+
};
|
|
44108
|
+
return createEventSubscriber(client, 'room/onRoomStartBroadcasting', 'room.startBroadcasting', filter);
|
|
44109
|
+
};
|
|
44110
|
+
|
|
44111
|
+
/**
|
|
44112
|
+
* ```js
|
|
44113
|
+
* import { onRoomWaitingReconnect } from '@amityco/ts-sdk'
|
|
44114
|
+
* const dispose = onRoomWaitingReconnect(room => {
|
|
44115
|
+
* // ...
|
|
44116
|
+
* })
|
|
44117
|
+
* ```
|
|
44118
|
+
*
|
|
44119
|
+
* Fired when a {@link Amity.Room} is waiting for reconnection
|
|
44120
|
+
*
|
|
44121
|
+
* @param callback The function to call when the event was fired
|
|
44122
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44123
|
+
*
|
|
44124
|
+
* @category Room Events
|
|
44125
|
+
*/
|
|
44126
|
+
const onRoomWaitingReconnect = (callback) => {
|
|
44127
|
+
const client = getActiveClient();
|
|
44128
|
+
const filter = (payload) => {
|
|
44129
|
+
ingestInCache(payload);
|
|
44130
|
+
callback(payload.rooms[0]);
|
|
44131
|
+
};
|
|
44132
|
+
return createEventSubscriber(client, 'room/onRoomWaitingReconnect', 'room.waitingReconnect', filter);
|
|
44133
|
+
};
|
|
44134
|
+
|
|
44135
|
+
/**
|
|
44136
|
+
* ```js
|
|
44137
|
+
* import { onRoomEndBroadcasting } from '@amityco/ts-sdk'
|
|
44138
|
+
* const dispose = onRoomEndBroadcasting(room => {
|
|
44139
|
+
* // ...
|
|
44140
|
+
* })
|
|
44141
|
+
* ```
|
|
44142
|
+
*
|
|
44143
|
+
* Fired when a {@link Amity.Room} has ended broadcasting
|
|
44144
|
+
*
|
|
44145
|
+
* @param callback The function to call when the event was fired
|
|
44146
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44147
|
+
*
|
|
44148
|
+
* @category Room Events
|
|
44149
|
+
*/
|
|
44150
|
+
const onRoomEndBroadcasting = (callback) => {
|
|
44151
|
+
const client = getActiveClient();
|
|
44152
|
+
const filter = (payload) => {
|
|
44153
|
+
ingestInCache(payload);
|
|
44154
|
+
callback(payload.rooms[0]);
|
|
44155
|
+
};
|
|
44156
|
+
return createEventSubscriber(client, 'room/onRoomEndBroadcasting', 'room.endBroadcasting', filter);
|
|
44157
|
+
};
|
|
44158
|
+
|
|
44159
|
+
/**
|
|
44160
|
+
* ```js
|
|
44161
|
+
* import { onRoomRecordedAvailable } from '@amityco/ts-sdk'
|
|
44162
|
+
* const dispose = onRoomRecordedAvailable(room => {
|
|
44163
|
+
* // ...
|
|
44164
|
+
* })
|
|
44165
|
+
* ```
|
|
44166
|
+
*
|
|
44167
|
+
* Fired when a {@link Amity.Room} recorded content becomes available
|
|
44168
|
+
*
|
|
44169
|
+
* @param callback The function to call when the event was fired
|
|
44170
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44171
|
+
*
|
|
44172
|
+
* @category Room Events
|
|
44173
|
+
*/
|
|
44174
|
+
const onRoomRecordedAvailable = (callback) => {
|
|
44175
|
+
const client = getActiveClient();
|
|
44176
|
+
const filter = (payload) => {
|
|
44177
|
+
ingestInCache(payload);
|
|
44178
|
+
callback(payload.rooms[0]);
|
|
44179
|
+
};
|
|
44180
|
+
return createEventSubscriber(client, 'room/onRoomRecordedAvailable', 'room.recordedAvailable', filter);
|
|
44181
|
+
};
|
|
44182
|
+
|
|
44183
|
+
/**
|
|
44184
|
+
* ```js
|
|
44185
|
+
* import { onRoomParticipantInviting } from '@amityco/ts-sdk'
|
|
44186
|
+
* const dispose = onRoomParticipantInviting(room => {
|
|
44187
|
+
* // ...
|
|
44188
|
+
* })
|
|
44189
|
+
* ```
|
|
44190
|
+
*
|
|
44191
|
+
* Fired when a participant is being invited to a {@link Amity.Room}
|
|
44192
|
+
*
|
|
44193
|
+
* @param callback The function to call when the event was fired
|
|
44194
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44195
|
+
*
|
|
44196
|
+
* @category Room Events
|
|
44197
|
+
*/
|
|
44198
|
+
const onRoomParticipantInviting = (callback) => {
|
|
44199
|
+
const client = getActiveClient();
|
|
44200
|
+
const filter = (payload) => {
|
|
44201
|
+
ingestInCache(payload);
|
|
44202
|
+
callback(payload.rooms[0]);
|
|
44203
|
+
};
|
|
44204
|
+
return createEventSubscriber(client, 'room/onRoomParticipantInviting', 'room.participantInviting', filter);
|
|
44205
|
+
};
|
|
44206
|
+
|
|
44207
|
+
/**
|
|
44208
|
+
* ```js
|
|
44209
|
+
* import { onRoomParticipantJoined } from '@amityco/ts-sdk'
|
|
44210
|
+
* const dispose = onRoomParticipantJoined(room => {
|
|
44211
|
+
* // ...
|
|
44212
|
+
* })
|
|
44213
|
+
* ```
|
|
44214
|
+
*
|
|
44215
|
+
* Fired when a participant has joined a {@link Amity.Room}
|
|
44216
|
+
*
|
|
44217
|
+
* @param callback The function to call when the event was fired
|
|
44218
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44219
|
+
*
|
|
44220
|
+
* @category Room Events
|
|
44221
|
+
*/
|
|
44222
|
+
const onRoomParticipantJoined = (callback) => {
|
|
44223
|
+
const client = getActiveClient();
|
|
44224
|
+
const filter = (payload) => {
|
|
44225
|
+
ingestInCache(payload);
|
|
44226
|
+
callback(payload.rooms[0]);
|
|
44227
|
+
};
|
|
44228
|
+
return createEventSubscriber(client, 'room/onRoomParticipantJoined', 'room.participantJoined', filter);
|
|
44229
|
+
};
|
|
44230
|
+
|
|
44231
|
+
/**
|
|
44232
|
+
* ```js
|
|
44233
|
+
* import { onRoomParticipantLeft } from '@amityco/ts-sdk'
|
|
44234
|
+
* const dispose = onRoomParticipantLeft(room => {
|
|
44235
|
+
* // ...
|
|
44236
|
+
* })
|
|
44237
|
+
* ```
|
|
44238
|
+
*
|
|
44239
|
+
* Fired when a participant has left a {@link Amity.Room}
|
|
44240
|
+
*
|
|
44241
|
+
* @param callback The function to call when the event was fired
|
|
44242
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44243
|
+
*
|
|
44244
|
+
* @category Room Events
|
|
44245
|
+
*/
|
|
44246
|
+
const onRoomParticipantLeft = (callback) => {
|
|
44247
|
+
const client = getActiveClient();
|
|
44248
|
+
const filter = (payload) => {
|
|
44249
|
+
ingestInCache(payload);
|
|
44250
|
+
callback(payload.rooms[0]);
|
|
44251
|
+
};
|
|
44252
|
+
return createEventSubscriber(client, 'room/onRoomParticipantLeft', 'room.participantLeft', filter);
|
|
44253
|
+
};
|
|
44254
|
+
|
|
44255
|
+
/**
|
|
44256
|
+
* ```js
|
|
44257
|
+
* import { onRoomCreated } from '@amityco/ts-sdk'
|
|
44258
|
+
* const dispose = onRoomCreated(room => {
|
|
44259
|
+
* // ...
|
|
44260
|
+
* })
|
|
44261
|
+
* ```
|
|
44262
|
+
*
|
|
44263
|
+
* Fired when a {@link Amity.Room} has been created locally
|
|
44264
|
+
*
|
|
44265
|
+
* @param callback The function to call when the event was fired
|
|
44266
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44267
|
+
*
|
|
44268
|
+
* @category Room Events
|
|
44269
|
+
*/
|
|
44270
|
+
const onRoomCreated = (callback) => {
|
|
44271
|
+
const client = getActiveClient();
|
|
44272
|
+
const filter = (payload) => {
|
|
44273
|
+
ingestInCache(payload);
|
|
44274
|
+
callback(payload.rooms[0]);
|
|
44275
|
+
};
|
|
44276
|
+
return createEventSubscriber(client, 'room/onRoomCreated', 'local.room.created', filter);
|
|
44277
|
+
};
|
|
44278
|
+
|
|
44279
|
+
/**
|
|
44280
|
+
* ```js
|
|
44281
|
+
* import { onRoomUpdated } from '@amityco/ts-sdk'
|
|
44282
|
+
* const dispose = onRoomUpdated(room => {
|
|
44283
|
+
* // ...
|
|
44284
|
+
* })
|
|
44285
|
+
* ```
|
|
44286
|
+
*
|
|
44287
|
+
* Fired when a {@link Amity.Room} has been updated locally
|
|
44288
|
+
*
|
|
44289
|
+
* @param callback The function to call when the event was fired
|
|
44290
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44291
|
+
*
|
|
44292
|
+
* @category Room Events
|
|
44293
|
+
*/
|
|
44294
|
+
const onRoomUpdated = (callback) => {
|
|
44295
|
+
const client = getActiveClient();
|
|
44296
|
+
const filter = (payload) => {
|
|
44297
|
+
ingestInCache(payload);
|
|
44298
|
+
callback(payload.rooms[0]);
|
|
44299
|
+
};
|
|
44300
|
+
return createEventSubscriber(client, 'room/onRoomUpdated', 'local.room.updated', filter);
|
|
44301
|
+
};
|
|
44302
|
+
|
|
44303
|
+
/**
|
|
44304
|
+
* ```js
|
|
44305
|
+
* import { onRoomDeleted } from '@amityco/ts-sdk'
|
|
44306
|
+
* const dispose = onRoomDeleted(room => {
|
|
44307
|
+
* // ...
|
|
44308
|
+
* })
|
|
44309
|
+
* ```
|
|
44310
|
+
*
|
|
44311
|
+
* Fired when a {@link Amity.Room} has been deleted locally
|
|
44312
|
+
*
|
|
44313
|
+
* @param callback The function to call when the event was fired
|
|
44314
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44315
|
+
*
|
|
44316
|
+
* @category Room Events
|
|
44317
|
+
*/
|
|
44318
|
+
const onRoomDeleted = (callback) => {
|
|
44319
|
+
const client = getActiveClient();
|
|
44320
|
+
const filter = (payload) => {
|
|
44321
|
+
ingestInCache(payload);
|
|
44322
|
+
callback(payload.rooms[0]);
|
|
44323
|
+
};
|
|
44324
|
+
return createEventSubscriber(client, 'room/onRoomDeleted', 'local.room.deleted', filter);
|
|
44325
|
+
};
|
|
44326
|
+
|
|
44327
|
+
/**
|
|
44328
|
+
* ```js
|
|
44329
|
+
* import { onRoomStopped } from '@amityco/ts-sdk'
|
|
44330
|
+
* const dispose = onRoomStopped(room => {
|
|
44331
|
+
* // ...
|
|
44332
|
+
* })
|
|
44333
|
+
* ```
|
|
44334
|
+
*
|
|
44335
|
+
* Fired when a {@link Amity.Room} has been stopped locally
|
|
44336
|
+
*
|
|
44337
|
+
* @param callback The function to call when the event was fired
|
|
44338
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44339
|
+
*
|
|
44340
|
+
* @category Room Events
|
|
44341
|
+
*/
|
|
44342
|
+
const onRoomStopped = (callback) => {
|
|
44343
|
+
const client = getActiveClient();
|
|
44344
|
+
const filter = (payload) => {
|
|
44345
|
+
ingestInCache(payload);
|
|
44346
|
+
callback(payload.rooms[0]);
|
|
44347
|
+
};
|
|
44348
|
+
return createEventSubscriber(client, 'room/onRoomStopped', 'local.room.stopped', filter);
|
|
44349
|
+
};
|
|
44350
|
+
|
|
44351
|
+
const getRoomById = async (roomId) => {
|
|
44352
|
+
const client = getActiveClient();
|
|
44353
|
+
client.log('room/getRoomById', roomId);
|
|
44354
|
+
// Check if room is in tombstone
|
|
44355
|
+
isInTombstone('room', roomId);
|
|
44356
|
+
let data;
|
|
44357
|
+
try {
|
|
44358
|
+
const response = await client.http.get(`/api/v1/rooms/${roomId}`);
|
|
44359
|
+
data = response.data;
|
|
44360
|
+
}
|
|
44361
|
+
catch (error) {
|
|
44362
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
44363
|
+
pushToTombstone('room', roomId);
|
|
44364
|
+
}
|
|
44365
|
+
throw error;
|
|
44366
|
+
}
|
|
44367
|
+
const cachedAt = client.cache && Date.now();
|
|
44368
|
+
if (client.cache) {
|
|
44369
|
+
ingestInCache(data, { cachedAt });
|
|
44370
|
+
}
|
|
44371
|
+
return {
|
|
44372
|
+
data: data.rooms[0],
|
|
44373
|
+
cachedAt,
|
|
44374
|
+
};
|
|
44375
|
+
};
|
|
44376
|
+
getRoomById.locally = (roomId) => {
|
|
44377
|
+
const client = getActiveClient();
|
|
44378
|
+
client.log('room/getRoomById.locally', roomId);
|
|
44379
|
+
// Check if room is in tombstone
|
|
44380
|
+
isInTombstone('room', roomId);
|
|
44381
|
+
const cachedAt = client.cache && Date.now();
|
|
44382
|
+
const roomCache = pullFromCache(['room', 'get', roomId]);
|
|
44383
|
+
if (!roomCache)
|
|
44384
|
+
return;
|
|
44385
|
+
return {
|
|
44386
|
+
data: roomCache.data,
|
|
44387
|
+
cachedAt,
|
|
44388
|
+
};
|
|
44389
|
+
};
|
|
44390
|
+
|
|
44391
|
+
const getRoom = (roomId, callback) => {
|
|
44392
|
+
// TODO: add callbackDataSelector if there are linked object fields
|
|
44393
|
+
return liveObject(roomId, callback, '_id', getRoomById, [
|
|
44394
|
+
onRoomEndBroadcasting,
|
|
44395
|
+
onRoomStartBroadcasting,
|
|
44396
|
+
onRoomWaitingReconnect,
|
|
44397
|
+
onRoomRecordedAvailable,
|
|
44398
|
+
]);
|
|
44399
|
+
};
|
|
44400
|
+
|
|
44401
|
+
class RoomPaginationController extends PaginationController {
|
|
44402
|
+
async getRequest(queryParams, token) {
|
|
44403
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
44404
|
+
const baseOptions = {
|
|
44405
|
+
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
44406
|
+
};
|
|
44407
|
+
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
44408
|
+
const { data: queryResponse } = await this.http.get(`/api/v1/rooms`, {
|
|
44409
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
|
|
44410
|
+
});
|
|
44411
|
+
return queryResponse;
|
|
44412
|
+
}
|
|
44413
|
+
}
|
|
44414
|
+
|
|
44415
|
+
var EnumRoomActions;
|
|
44416
|
+
(function (EnumRoomActions) {
|
|
44417
|
+
EnumRoomActions["OnRoomCreated"] = "OnRoomCreated";
|
|
44418
|
+
EnumRoomActions["OnRoomUpdated"] = "OnRoomUpdated";
|
|
44419
|
+
EnumRoomActions["OnRoomDeleted"] = "OnRoomDeleted";
|
|
44420
|
+
EnumRoomActions["OnRoomStartBroadcasting"] = "OnRoomStartBroadcasting";
|
|
44421
|
+
EnumRoomActions["OnRoomEndBroadcasting"] = "OnRoomEndBroadcasting";
|
|
44422
|
+
EnumRoomActions["OnRoomParticipantJoined"] = "OnRoomParticipantJoined";
|
|
44423
|
+
EnumRoomActions["OnRoomParticipantLeft"] = "OnRoomParticipantLeft";
|
|
44424
|
+
})(EnumRoomActions || (EnumRoomActions = {}));
|
|
44425
|
+
|
|
44426
|
+
class RoomQueryStreamController extends QueryStreamController {
|
|
44427
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
44428
|
+
super(query, cacheKey);
|
|
44429
|
+
this.notifyChange = notifyChange;
|
|
44430
|
+
this.preparePayload = preparePayload;
|
|
44431
|
+
}
|
|
44432
|
+
async saveToMainDB(response) {
|
|
44433
|
+
const processedPayload = await this.preparePayload(response);
|
|
44434
|
+
const client = getActiveClient();
|
|
44435
|
+
const cachedAt = client.cache && Date.now();
|
|
44436
|
+
if (client.cache) {
|
|
44437
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
44438
|
+
}
|
|
44439
|
+
}
|
|
44440
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
44441
|
+
var _a, _b;
|
|
44442
|
+
if (refresh) {
|
|
44443
|
+
pushToCache(this.cacheKey, {
|
|
44444
|
+
data: response.rooms.map(getResolver('room')),
|
|
44445
|
+
});
|
|
44446
|
+
}
|
|
44447
|
+
else {
|
|
44448
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
44449
|
+
const rooms = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
44450
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...rooms, ...response.rooms.map(getResolver('room'))])] }));
|
|
44451
|
+
}
|
|
44452
|
+
}
|
|
44453
|
+
reactor(action) {
|
|
44454
|
+
return (room) => {
|
|
44455
|
+
var _a;
|
|
44456
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
44457
|
+
if (!collection)
|
|
44458
|
+
return;
|
|
44459
|
+
if (action === EnumRoomActions.OnRoomDeleted) {
|
|
44460
|
+
collection.data = collection.data.filter(roomId => roomId !== room._id);
|
|
44461
|
+
}
|
|
44462
|
+
if (action === EnumRoomActions.OnRoomCreated) {
|
|
44463
|
+
collection.data = [...new Set([room._id, ...collection.data])];
|
|
44464
|
+
}
|
|
44465
|
+
pushToCache(this.cacheKey, collection);
|
|
44466
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
44467
|
+
};
|
|
44468
|
+
}
|
|
44469
|
+
subscribeRTE(createSubscriber) {
|
|
44470
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
44471
|
+
}
|
|
44472
|
+
}
|
|
44473
|
+
|
|
44474
|
+
// TODO: confirm related events
|
|
44475
|
+
const getRoomSubscription = () => [
|
|
44476
|
+
{
|
|
44477
|
+
fn: onRoomStartBroadcasting,
|
|
44478
|
+
action: EnumRoomActions.OnRoomStartBroadcasting,
|
|
44479
|
+
},
|
|
44480
|
+
{
|
|
44481
|
+
fn: onRoomEndBroadcasting,
|
|
44482
|
+
action: EnumRoomActions.OnRoomEndBroadcasting,
|
|
44483
|
+
},
|
|
44484
|
+
{
|
|
44485
|
+
fn: onRoomRecordedAvailable,
|
|
44486
|
+
action: EnumRoomActions.OnRoomUpdated,
|
|
44487
|
+
},
|
|
44488
|
+
];
|
|
44489
|
+
|
|
44490
|
+
class RoomLiveCollectionController extends LiveCollectionController {
|
|
44491
|
+
constructor(query, callback) {
|
|
44492
|
+
const queryStreamId = hash(query);
|
|
44493
|
+
const cacheKey = ['rooms', 'collection', queryStreamId];
|
|
44494
|
+
const paginationController = new RoomPaginationController(query);
|
|
44495
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
44496
|
+
this.query = query;
|
|
44497
|
+
this.queryStreamController = new RoomQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
|
|
44498
|
+
this.callback = callback.bind(this);
|
|
44499
|
+
this.loadPage({ initial: true });
|
|
44500
|
+
}
|
|
44501
|
+
setup() {
|
|
44502
|
+
var _a;
|
|
44503
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
44504
|
+
if (!collection) {
|
|
44505
|
+
pushToCache(this.cacheKey, {
|
|
44506
|
+
data: [],
|
|
44507
|
+
params: {},
|
|
44508
|
+
});
|
|
44509
|
+
}
|
|
44510
|
+
}
|
|
44511
|
+
async persistModel(queryPayload) {
|
|
44512
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
44513
|
+
}
|
|
44514
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
44515
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
44516
|
+
}
|
|
44517
|
+
startSubscription() {
|
|
44518
|
+
return this.queryStreamController.subscribeRTE(getRoomSubscription());
|
|
44519
|
+
}
|
|
44520
|
+
notifyChange({ origin, loading, error }) {
|
|
44521
|
+
var _a, _b;
|
|
44522
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
44523
|
+
if (!collection)
|
|
44524
|
+
return;
|
|
44525
|
+
const data = this.applyFilter((_b = collection.data
|
|
44526
|
+
.map(id => pullFromCache(['room', 'get', id]))
|
|
44527
|
+
.filter(isNonNullable)
|
|
44528
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(room => room); // Since Room is same as InternalRoom, no transformation needed
|
|
44529
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
44530
|
+
return;
|
|
44531
|
+
this.callback({
|
|
44532
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
44533
|
+
data,
|
|
44534
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
44535
|
+
loading,
|
|
44536
|
+
error,
|
|
44537
|
+
});
|
|
44538
|
+
}
|
|
44539
|
+
applyFilter(data) {
|
|
44540
|
+
let rooms = data;
|
|
44541
|
+
if (!this.query.includeDeleted) {
|
|
44542
|
+
rooms = filterByPropEquality(rooms, 'isDeleted', false);
|
|
44543
|
+
}
|
|
44544
|
+
if (this.query.statuses && this.query.statuses.length > 0) {
|
|
44545
|
+
rooms = rooms.filter(room => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(room.status); });
|
|
44546
|
+
}
|
|
44547
|
+
if (this.query.type) {
|
|
44548
|
+
rooms = filterByPropEquality(rooms, 'type', this.query.type);
|
|
44549
|
+
}
|
|
44550
|
+
switch (this.query.sortBy) {
|
|
44551
|
+
case 'firstCreated':
|
|
44552
|
+
rooms = rooms.sort(sortByFirstCreated);
|
|
44553
|
+
break;
|
|
44554
|
+
case 'lastCreated':
|
|
44555
|
+
default:
|
|
44556
|
+
rooms = rooms.sort(sortByLastCreated);
|
|
44557
|
+
break;
|
|
44558
|
+
}
|
|
44559
|
+
return rooms;
|
|
44560
|
+
}
|
|
44561
|
+
}
|
|
44562
|
+
|
|
44563
|
+
/* begin_public_function
|
|
44564
|
+
id: room.get_rooms
|
|
44565
|
+
*/
|
|
44566
|
+
/**
|
|
44567
|
+
* ```js
|
|
44568
|
+
* import { RoomRepository } from '@amityco/ts-sdk'
|
|
44569
|
+
*
|
|
44570
|
+
* let rooms = []
|
|
44571
|
+
* const unsub = RoomRepository.getRooms({
|
|
44572
|
+
* type: 'direct_streaming',
|
|
44573
|
+
* statuses: ['live', 'idle'],
|
|
44574
|
+
* sortBy: 'lastCreated',
|
|
44575
|
+
* limit: 20,
|
|
44576
|
+
* includeDeleted: false
|
|
44577
|
+
* }, response => merge(rooms, response.data))
|
|
44578
|
+
* ```
|
|
44579
|
+
*
|
|
44580
|
+
* Observe all mutations on a list of {@link Amity.Room} for a given query
|
|
44581
|
+
*
|
|
44582
|
+
* @param params.type the type of rooms to filter by ('direct_streaming' | 'co_hosts')
|
|
44583
|
+
* @param params.statuses array of room statuses to filter by (['idle', 'live', 'waiting_reconnect', 'ended', 'recorded'])
|
|
44584
|
+
* @param params.sortBy sort rooms by creation time ('firstCreated' | 'lastCreated')
|
|
44585
|
+
* @param params.limit maximum number of rooms to retrieve per page
|
|
44586
|
+
* @param params.includeDeleted whether to include deleted rooms in the results
|
|
44587
|
+
* @param callback the function to call when new data are available
|
|
44588
|
+
* @param config optional configuration for the live collection
|
|
44589
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the rooms
|
|
44590
|
+
*
|
|
44591
|
+
* @category Rooms Live Collection
|
|
44592
|
+
*/
|
|
44593
|
+
const getRooms = (params, callback, config) => {
|
|
44594
|
+
const { log, cache } = getActiveClient();
|
|
44595
|
+
if (!cache) {
|
|
44596
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
44597
|
+
}
|
|
44598
|
+
const timestamp = Date.now();
|
|
44599
|
+
log(`getRooms(tmpid: ${timestamp}) > listen`);
|
|
44600
|
+
const roomsLiveCollection = new RoomLiveCollectionController(params, callback);
|
|
44601
|
+
const disposers = roomsLiveCollection.startSubscription();
|
|
44602
|
+
const cacheKey = roomsLiveCollection.getCacheKey();
|
|
44603
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
44604
|
+
return () => {
|
|
44605
|
+
log(`getRooms(tmpid: ${timestamp}) > dispose`);
|
|
44606
|
+
disposers.forEach(fn => fn());
|
|
44607
|
+
};
|
|
44608
|
+
};
|
|
44609
|
+
/* end_public_function */
|
|
44610
|
+
|
|
44611
|
+
var index$7 = /*#__PURE__*/Object.freeze({
|
|
44612
|
+
__proto__: null,
|
|
44613
|
+
createRoom: createRoom,
|
|
44614
|
+
updateRoom: updateRoom,
|
|
44615
|
+
deleteRoom: deleteRoom,
|
|
44616
|
+
stopRoom: stopRoom,
|
|
44617
|
+
getRoomToken: getRoomToken,
|
|
44618
|
+
getRecordedUrl: getRecordedUrl,
|
|
44619
|
+
onRoomStartBroadcasting: onRoomStartBroadcasting,
|
|
44620
|
+
onRoomWaitingReconnect: onRoomWaitingReconnect,
|
|
44621
|
+
onRoomEndBroadcasting: onRoomEndBroadcasting,
|
|
44622
|
+
onRoomRecordedAvailable: onRoomRecordedAvailable,
|
|
44623
|
+
onRoomParticipantInviting: onRoomParticipantInviting,
|
|
44624
|
+
onRoomParticipantJoined: onRoomParticipantJoined,
|
|
44625
|
+
onRoomParticipantLeft: onRoomParticipantLeft,
|
|
44626
|
+
onRoomCreated: onRoomCreated,
|
|
44627
|
+
onRoomUpdated: onRoomUpdated,
|
|
44628
|
+
onRoomDeleted: onRoomDeleted,
|
|
44629
|
+
onRoomStopped: onRoomStopped,
|
|
44630
|
+
getRoom: getRoom,
|
|
44631
|
+
getRooms: getRooms
|
|
44632
|
+
});
|
|
44633
|
+
|
|
43896
44634
|
/* begin_public_function
|
|
43897
44635
|
id: poll.create
|
|
43898
44636
|
*/
|
|
@@ -46525,4 +47263,4 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
46525
47263
|
getReactions: getReactions
|
|
46526
47264
|
});
|
|
46527
47265
|
|
|
46528
|
-
export { API_REGIONS, index$3 as AdRepository, index$
|
|
47266
|
+
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 };
|