@amityco/ts-sdk 7.11.1-1440698f.0 → 7.11.1-19ae17f9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/events.d.ts +0 -3
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +0 -2
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +0 -16
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/room.d.ts +0 -11
- package/dist/@types/domains/room.d.ts.map +1 -1
- package/dist/client/api/resumeSession.d.ts.map +1 -1
- package/dist/client/utils/ObjectResolver/objectResolverEngine.d.ts.map +1 -0
- package/dist/client/utils/ObjectResolver/objectResolverEngineOnLoginHandler.d.ts.map +1 -0
- package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts.map +1 -0
- package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts.map +1 -0
- package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +1 -0
- package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngineOnLoginHandler.d.ts.map +1 -0
- 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 +46 -501
- package/dist/index.esm.js +46 -501
- package/dist/index.umd.js +3 -3
- package/dist/invitationRepository/api/index.d.ts +0 -1
- package/dist/invitationRepository/api/index.d.ts.map +1 -1
- package/dist/roomRepository/api/removeParticipant.d.ts.map +1 -1
- package/dist/roomRepository/events/onRoomCoHostInviteAccepted.d.ts +1 -1
- package/dist/roomRepository/events/onRoomCoHostInviteAccepted.d.ts.map +1 -1
- package/dist/roomRepository/index.d.ts +0 -1
- package/dist/roomRepository/index.d.ts.map +1 -1
- package/dist/roomRepository/internalApi/index.d.ts +0 -2
- package/dist/roomRepository/internalApi/index.d.ts.map +1 -1
- package/dist/roomRepository/observers/getRoom.d.ts.map +1 -1
- package/dist/roomRepository/observers/index.d.ts +0 -2
- package/dist/roomRepository/observers/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/client/api/getPresenceSetting.d.ts +0 -2
- package/dist/client/api/getPresenceSetting.d.ts.map +0 -1
- package/dist/client/services/ObjectResolver/objectResolverEngine.d.ts.map +0 -1
- package/dist/client/services/ObjectResolver/objectResolverEngineOnLoginHandler.d.ts.map +0 -1
- package/dist/client/services/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts.map +0 -1
- package/dist/client/services/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts.map +0 -1
- package/dist/client/services/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +0 -1
- package/dist/client/services/ReadReceiptSync/readReceiptSyncEngineOnLoginHandler.d.ts.map +0 -1
- package/dist/invitationRepository/api/acceptInvitation.d.ts +0 -16
- package/dist/invitationRepository/api/acceptInvitation.d.ts.map +0 -1
- package/dist/invitationRepository/api/getMyInvitation.d.ts +0 -16
- package/dist/invitationRepository/api/getMyInvitation.d.ts.map +0 -1
- package/dist/roomRepository/events/onRoomParticipantRemovedLocal.d.ts +0 -17
- package/dist/roomRepository/events/onRoomParticipantRemovedLocal.d.ts.map +0 -1
- package/dist/roomRepository/events/onRoomWatchingCountUpdated.d.ts +0 -17
- package/dist/roomRepository/events/onRoomWatchingCountUpdated.d.ts.map +0 -1
- package/dist/roomRepository/events/onRoomWatchingUsersFetched.d.ts +0 -17
- package/dist/roomRepository/events/onRoomWatchingUsersFetched.d.ts.map +0 -1
- package/dist/roomRepository/internalApi/getWatchingCount.d.ts +0 -2
- package/dist/roomRepository/internalApi/getWatchingCount.d.ts.map +0 -1
- package/dist/roomRepository/internalApi/getWatchingUsers.d.ts +0 -2
- package/dist/roomRepository/internalApi/getWatchingUsers.d.ts.map +0 -1
- package/dist/roomRepository/observers/getWatchingCount.d.ts +0 -18
- package/dist/roomRepository/observers/getWatchingCount.d.ts.map +0 -1
- package/dist/roomRepository/observers/getWatchingUsers.d.ts +0 -18
- package/dist/roomRepository/observers/getWatchingUsers.d.ts.map +0 -1
- package/dist/roomRepository/services/WatchingSync/WatchingSyncEngine.d.ts +0 -24
- package/dist/roomRepository/services/WatchingSync/WatchingSyncEngine.d.ts.map +0 -1
- package/dist/roomRepository/services/WatchingSync/index.d.ts +0 -2
- package/dist/roomRepository/services/WatchingSync/index.d.ts.map +0 -1
- package/dist/roomRepository/services/WatchingSync/watchingSyncEngineFactory.d.ts +0 -32
- package/dist/roomRepository/services/WatchingSync/watchingSyncEngineFactory.d.ts.map +0 -1
- package/dist/roomRepository/services/index.d.ts +0 -2
- package/dist/roomRepository/services/index.d.ts.map +0 -1
- package/dist/utils/linkedObject/roomWatchingUserLinkedObject.d.ts +0 -2
- package/dist/utils/linkedObject/roomWatchingUserLinkedObject.d.ts.map +0 -1
- /package/dist/client/{services → utils}/ObjectResolver/objectResolverEngine.d.ts +0 -0
- /package/dist/client/{services → utils}/ObjectResolver/objectResolverEngineOnLoginHandler.d.ts +0 -0
- /package/dist/client/{services → utils}/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts +0 -0
- /package/dist/client/{services → utils}/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts +0 -0
- /package/dist/client/{services → utils}/ReadReceiptSync/readReceiptSyncEngine.d.ts +0 -0
- /package/dist/client/{services → utils}/ReadReceiptSync/readReceiptSyncEngineOnLoginHandler.d.ts +0 -0
package/dist/index.cjs.js
CHANGED
|
@@ -732,7 +732,6 @@ const PAYLOAD2MODEL = {
|
|
|
732
732
|
rooms: 'room',
|
|
733
733
|
events: 'event',
|
|
734
734
|
discussionCommunities: 'discussionCommunity',
|
|
735
|
-
viewers: 'viewer',
|
|
736
735
|
};
|
|
737
736
|
/** hidden */
|
|
738
737
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -1463,14 +1462,12 @@ const createEventEmitter = () => {
|
|
|
1463
1462
|
const proxyMqttEvents = (mqttClient, emitter) => {
|
|
1464
1463
|
MQTT_EVENTS.forEach(event => {
|
|
1465
1464
|
mqttClient === null || mqttClient === void 0 ? void 0 : mqttClient.on(event, (...params) => {
|
|
1466
|
-
console.log('global event received => ', event);
|
|
1467
1465
|
emitter.emit(event, params.length === 1 ? params[0] : params);
|
|
1468
1466
|
});
|
|
1469
1467
|
});
|
|
1470
1468
|
// @ts-ignore
|
|
1471
1469
|
mqttClient.on('message', (topic, payload) => {
|
|
1472
1470
|
const message = JSON.parse(payload.toString());
|
|
1473
|
-
console.log('message event received => ', message.eventType, message.data);
|
|
1474
1471
|
emitter.emit(message.eventType, message.data);
|
|
1475
1472
|
});
|
|
1476
1473
|
};
|
|
@@ -12372,7 +12369,7 @@ const createInvitations = async (bundle) => {
|
|
|
12372
12369
|
* @category Invitation API
|
|
12373
12370
|
* @async
|
|
12374
12371
|
*/
|
|
12375
|
-
const acceptInvitation
|
|
12372
|
+
const acceptInvitation = async (invitationId) => {
|
|
12376
12373
|
var _a;
|
|
12377
12374
|
const client = getActiveClient();
|
|
12378
12375
|
client.log('invitation/acceptInvitation', invitationId);
|
|
@@ -12458,7 +12455,7 @@ const invitationLinkedObject = (invitation) => {
|
|
|
12458
12455
|
}
|
|
12459
12456
|
return undefined;
|
|
12460
12457
|
}, accept: async () => {
|
|
12461
|
-
await acceptInvitation
|
|
12458
|
+
await acceptInvitation(invitation._id);
|
|
12462
12459
|
}, reject: async () => {
|
|
12463
12460
|
await rejectInvitation(invitation._id);
|
|
12464
12461
|
} });
|
|
@@ -28068,7 +28065,9 @@ const getRecordedUrl = async (roomId) => {
|
|
|
28068
28065
|
const removeParticipant = async (roomId, participantUserId) => {
|
|
28069
28066
|
const client = getActiveClient();
|
|
28070
28067
|
client.log('room/removeParticipant', { roomId, participantUserId });
|
|
28071
|
-
await client.http.delete(`/api/v1/rooms/${roomId}/participants
|
|
28068
|
+
await client.http.delete(`/api/v1/rooms/${roomId}/participants`, {
|
|
28069
|
+
data: { participantUserId },
|
|
28070
|
+
});
|
|
28072
28071
|
fireEvent('local.room.participantRemoved', {
|
|
28073
28072
|
rooms: [{ _id: roomId }],
|
|
28074
28073
|
users: [{ _id: participantUserId }],
|
|
@@ -28224,64 +28223,6 @@ const onRoomCoHostInvited = (callback) => {
|
|
|
28224
28223
|
return createEventSubscriber(client, 'room/onRoomCoHostInvited', 'room.didCohostInvite', filter);
|
|
28225
28224
|
};
|
|
28226
28225
|
|
|
28227
|
-
const getRoomById = async (roomId) => {
|
|
28228
|
-
const client = getActiveClient();
|
|
28229
|
-
client.log('room/getRoomById', roomId);
|
|
28230
|
-
// Check if room is in tombstone
|
|
28231
|
-
isInTombstone('room', roomId);
|
|
28232
|
-
let data;
|
|
28233
|
-
try {
|
|
28234
|
-
const response = await client.http.get(`/api/v1/rooms/${roomId}`);
|
|
28235
|
-
data = response.data;
|
|
28236
|
-
}
|
|
28237
|
-
catch (error) {
|
|
28238
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
28239
|
-
pushToTombstone('room', roomId);
|
|
28240
|
-
}
|
|
28241
|
-
throw error;
|
|
28242
|
-
}
|
|
28243
|
-
const cachedAt = client.cache && Date.now();
|
|
28244
|
-
if (client.cache) {
|
|
28245
|
-
ingestInCache(data, { cachedAt });
|
|
28246
|
-
}
|
|
28247
|
-
return {
|
|
28248
|
-
data: data.rooms[0],
|
|
28249
|
-
cachedAt,
|
|
28250
|
-
};
|
|
28251
|
-
};
|
|
28252
|
-
getRoomById.locally = (roomId) => {
|
|
28253
|
-
const client = getActiveClient();
|
|
28254
|
-
client.log('room/getRoomById.locally', roomId);
|
|
28255
|
-
// Check if room is in tombstone
|
|
28256
|
-
isInTombstone('room', roomId);
|
|
28257
|
-
const cachedAt = client.cache && Date.now();
|
|
28258
|
-
const roomCache = pullFromCache(['room', 'get', roomId]);
|
|
28259
|
-
if (!roomCache)
|
|
28260
|
-
return;
|
|
28261
|
-
return {
|
|
28262
|
-
data: roomCache.data,
|
|
28263
|
-
cachedAt,
|
|
28264
|
-
};
|
|
28265
|
-
};
|
|
28266
|
-
|
|
28267
|
-
const getWatchingCount$1 = async (roomId) => {
|
|
28268
|
-
const client = getActiveClient();
|
|
28269
|
-
client.log('room/getWatchingCount', { roomId });
|
|
28270
|
-
const { data } = await client.http.get(`/api/v1/presence/rooms/${roomId}/users/count`);
|
|
28271
|
-
pushToCache(['get', 'watchingCount', roomId], data);
|
|
28272
|
-
fireEvent('local.room.watchingCountUpdated', data);
|
|
28273
|
-
return data;
|
|
28274
|
-
};
|
|
28275
|
-
|
|
28276
|
-
const getWatchingUsers$1 = async (roomId) => {
|
|
28277
|
-
const client = getActiveClient();
|
|
28278
|
-
client.log('room/getWatchingUsers', { roomId });
|
|
28279
|
-
const { data } = await client.http.get(`/api/v1/presence/rooms/${roomId}/users`);
|
|
28280
|
-
pushToCache(['watchingUsers', 'collection', roomId], data.viewers.map(viewer => viewer.userId));
|
|
28281
|
-
fireEvent('local.room.watchingUsersFetched', data.viewers);
|
|
28282
|
-
return data.viewers;
|
|
28283
|
-
};
|
|
28284
|
-
|
|
28285
28226
|
/**
|
|
28286
28227
|
* ```js
|
|
28287
28228
|
* import { onRoomCoHostInviteAccepted } from '@amityco/ts-sdk'
|
|
@@ -28299,12 +28240,10 @@ const getWatchingUsers$1 = async (roomId) => {
|
|
|
28299
28240
|
*/
|
|
28300
28241
|
const onRoomCoHostInviteAccepted = (callback) => {
|
|
28301
28242
|
const client = getActiveClient();
|
|
28302
|
-
const filter =
|
|
28303
|
-
var _a;
|
|
28243
|
+
const filter = (payload) => {
|
|
28304
28244
|
const data = prepareMyInvitationsPayload(payload);
|
|
28305
|
-
await getRoomById((_a = data.invitations) === null || _a === void 0 ? void 0 : _a[0].targetId);
|
|
28306
28245
|
ingestInCache(data);
|
|
28307
|
-
callback(data.invitations
|
|
28246
|
+
callback(data.invitations);
|
|
28308
28247
|
};
|
|
28309
28248
|
return createEventSubscriber(client, 'room/onRoomCoHostInviteAccepted', 'room.didCohostInviteAccept', filter);
|
|
28310
28249
|
};
|
|
@@ -28524,7 +28463,7 @@ const onRoomParticipantRemoved = (callback) => {
|
|
|
28524
28463
|
ingestInCache(payload);
|
|
28525
28464
|
callback(payload.rooms[0]);
|
|
28526
28465
|
};
|
|
28527
|
-
return createEventSubscriber(client, 'room/onRoomParticipantRemoved', 'room.participantRemoved', filter);
|
|
28466
|
+
return createEventSubscriber(client, 'room/onRoomParticipantRemoved', 'local.room.participantRemoved', filter);
|
|
28528
28467
|
};
|
|
28529
28468
|
|
|
28530
28469
|
/**
|
|
@@ -28551,28 +28490,44 @@ const onRoomLeft = (callback) => {
|
|
|
28551
28490
|
return createEventSubscriber(client, 'room/onRoomLeft', 'local.room.left', filter);
|
|
28552
28491
|
};
|
|
28553
28492
|
|
|
28554
|
-
|
|
28555
|
-
* ```js
|
|
28556
|
-
* import { onRoomParticipantRemoved } from '@amityco/ts-sdk'
|
|
28557
|
-
* const dispose = onRoomParticipantRemoved(room => {
|
|
28558
|
-
* // ...
|
|
28559
|
-
* })
|
|
28560
|
-
* ```
|
|
28561
|
-
*
|
|
28562
|
-
* Fired when a participant has been removed from a {@link Amity.Room} locally
|
|
28563
|
-
*
|
|
28564
|
-
* @param callback The function to call when the event was fired
|
|
28565
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
28566
|
-
*
|
|
28567
|
-
* @category Room Events
|
|
28568
|
-
*/
|
|
28569
|
-
const onRoomParticipantRemovedLocal = (callback) => {
|
|
28493
|
+
const getRoomById = async (roomId) => {
|
|
28570
28494
|
const client = getActiveClient();
|
|
28571
|
-
|
|
28572
|
-
|
|
28573
|
-
|
|
28495
|
+
client.log('room/getRoomById', roomId);
|
|
28496
|
+
// Check if room is in tombstone
|
|
28497
|
+
isInTombstone('room', roomId);
|
|
28498
|
+
let data;
|
|
28499
|
+
try {
|
|
28500
|
+
const response = await client.http.get(`/api/v1/rooms/${roomId}`);
|
|
28501
|
+
data = response.data;
|
|
28502
|
+
}
|
|
28503
|
+
catch (error) {
|
|
28504
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
28505
|
+
pushToTombstone('room', roomId);
|
|
28506
|
+
}
|
|
28507
|
+
throw error;
|
|
28508
|
+
}
|
|
28509
|
+
const cachedAt = client.cache && Date.now();
|
|
28510
|
+
if (client.cache) {
|
|
28511
|
+
ingestInCache(data, { cachedAt });
|
|
28512
|
+
}
|
|
28513
|
+
return {
|
|
28514
|
+
data: data.rooms[0],
|
|
28515
|
+
cachedAt,
|
|
28516
|
+
};
|
|
28517
|
+
};
|
|
28518
|
+
getRoomById.locally = (roomId) => {
|
|
28519
|
+
const client = getActiveClient();
|
|
28520
|
+
client.log('room/getRoomById.locally', roomId);
|
|
28521
|
+
// Check if room is in tombstone
|
|
28522
|
+
isInTombstone('room', roomId);
|
|
28523
|
+
const cachedAt = client.cache && Date.now();
|
|
28524
|
+
const roomCache = pullFromCache(['room', 'get', roomId]);
|
|
28525
|
+
if (!roomCache)
|
|
28526
|
+
return;
|
|
28527
|
+
return {
|
|
28528
|
+
data: roomCache.data,
|
|
28529
|
+
cachedAt,
|
|
28574
28530
|
};
|
|
28575
|
-
return createEventSubscriber(client, 'room/onRoomParticipantRemoved', 'local.room.participantRemoved', filter);
|
|
28576
28531
|
};
|
|
28577
28532
|
|
|
28578
28533
|
const getRoom = (roomId, callback) => {
|
|
@@ -28584,9 +28539,6 @@ const getRoom = (roomId, callback) => {
|
|
|
28584
28539
|
onRoomRecordedAvailable,
|
|
28585
28540
|
onRoomParticipantJoined,
|
|
28586
28541
|
onRoomParticipantLeft,
|
|
28587
|
-
onRoomParticipantRemoved,
|
|
28588
|
-
onRoomParticipantRemovedLocal,
|
|
28589
|
-
convertEventPayload(onRoomCoHostInviteAccepted, 'targetId', 'room'),
|
|
28590
28542
|
], {
|
|
28591
28543
|
callbackDataSelector: (data) => {
|
|
28592
28544
|
if (!data)
|
|
@@ -28806,381 +28758,6 @@ const getRooms = (params, callback, config) => {
|
|
|
28806
28758
|
};
|
|
28807
28759
|
/* end_public_function */
|
|
28808
28760
|
|
|
28809
|
-
/**
|
|
28810
|
-
* ```js
|
|
28811
|
-
* import { onRoomWaitingReconnect } from '@amityco/ts-sdk'
|
|
28812
|
-
* const dispose = onRoomWaitingReconnect(room => {
|
|
28813
|
-
* // ...
|
|
28814
|
-
* })
|
|
28815
|
-
* ```
|
|
28816
|
-
*
|
|
28817
|
-
* Fired when a {@link Amity.RoomWatchingCount} is waiting for reconnection
|
|
28818
|
-
*
|
|
28819
|
-
* @param callback The function to call when the event was fired
|
|
28820
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
28821
|
-
*
|
|
28822
|
-
* @category Room Events
|
|
28823
|
-
*/
|
|
28824
|
-
const onRoomWatchingCountUpdated = (callback) => {
|
|
28825
|
-
const client = getActiveClient();
|
|
28826
|
-
const filter = (payload) => {
|
|
28827
|
-
callback(payload);
|
|
28828
|
-
};
|
|
28829
|
-
return createEventSubscriber(client, 'room/onRoomWatchingCountUpdated', 'local.room.watchingCountUpdated', filter);
|
|
28830
|
-
};
|
|
28831
|
-
|
|
28832
|
-
/**
|
|
28833
|
-
* ```js
|
|
28834
|
-
* import RoomRepository from '@amityco/ts-sdk'
|
|
28835
|
-
* const unsubscribe = RoomRepository.getWatchingCount('roomId', ({count}) => {
|
|
28836
|
-
* console.log('Current watching count:', count);
|
|
28837
|
-
* });
|
|
28838
|
-
* ```
|
|
28839
|
-
*
|
|
28840
|
-
* Observe the watching count for a room with real-time updates
|
|
28841
|
-
*
|
|
28842
|
-
* @param roomId The ID of the room to observe watching count for
|
|
28843
|
-
* @param callback The function to call when watching count changes
|
|
28844
|
-
* @returns An {@link Amity.Unsubscriber} function to stop observing
|
|
28845
|
-
*
|
|
28846
|
-
* @category Room Observable
|
|
28847
|
-
*/
|
|
28848
|
-
const getWatchingCount = (roomId, callback) => {
|
|
28849
|
-
const { _id: userId } = getCurrentUser();
|
|
28850
|
-
if (!userId)
|
|
28851
|
-
throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
28852
|
-
const { log, cache } = getActiveClient();
|
|
28853
|
-
if (!cache) {
|
|
28854
|
-
console.log('For using Live Object feature you need to enable Cache!');
|
|
28855
|
-
}
|
|
28856
|
-
const timestamp = Date.now();
|
|
28857
|
-
log(`liveWatchingCount(tmpid: ${timestamp}) > listen`);
|
|
28858
|
-
const disposers = [];
|
|
28859
|
-
let model;
|
|
28860
|
-
const dispatcher = (data) => {
|
|
28861
|
-
callback(data !== null && data !== void 0 ? data : { count: 0, referenceTimestamp: undefined });
|
|
28862
|
-
};
|
|
28863
|
-
const realtimeRouter = (_) => {
|
|
28864
|
-
var _a;
|
|
28865
|
-
const data = (_a = pullFromCache(['get', 'watchingCount', roomId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28866
|
-
if (isEqual(model, data))
|
|
28867
|
-
return;
|
|
28868
|
-
dispatcher(data);
|
|
28869
|
-
};
|
|
28870
|
-
const onFetch = () => {
|
|
28871
|
-
var _a;
|
|
28872
|
-
const data = (_a = pullFromCache(['get', 'watchingCount', roomId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28873
|
-
dispatcher(data);
|
|
28874
|
-
};
|
|
28875
|
-
disposers.push(onRoomWatchingCountUpdated(realtimeRouter));
|
|
28876
|
-
onFetch();
|
|
28877
|
-
return () => {
|
|
28878
|
-
disposers.forEach(fn => fn());
|
|
28879
|
-
};
|
|
28880
|
-
};
|
|
28881
|
-
|
|
28882
|
-
/**
|
|
28883
|
-
* ```js
|
|
28884
|
-
* import { onRoomWatchingUsersFetched } from '@amityco/ts-sdk'
|
|
28885
|
-
* const dispose = onRoomWatchingUsersFetched(users => {
|
|
28886
|
-
* console.log('Watching users fetched:', users);
|
|
28887
|
-
* })
|
|
28888
|
-
* ```
|
|
28889
|
-
*
|
|
28890
|
-
* Fired when {@link Amity.User[]} watching users data is fetched
|
|
28891
|
-
*
|
|
28892
|
-
* @param callback The function to call when the event was fired
|
|
28893
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
28894
|
-
*
|
|
28895
|
-
* @category Room Events
|
|
28896
|
-
*/
|
|
28897
|
-
const onRoomWatchingUsersFetched = (callback) => {
|
|
28898
|
-
const client = getActiveClient();
|
|
28899
|
-
const filter = (payload) => {
|
|
28900
|
-
callback(payload);
|
|
28901
|
-
};
|
|
28902
|
-
return createEventSubscriber(client, 'room/onRoomWatchingUsersFetched', 'local.room.watchingUsersFetched', filter);
|
|
28903
|
-
};
|
|
28904
|
-
|
|
28905
|
-
/**
|
|
28906
|
-
* ```js
|
|
28907
|
-
* import RoomRepository from '@amityco/ts-sdk'
|
|
28908
|
-
* const unsubscribe = RoomRepository.getWatchingUsers('roomId', ({count}) => {
|
|
28909
|
-
* console.log('Current watching count:', count);
|
|
28910
|
-
* });
|
|
28911
|
-
* ```
|
|
28912
|
-
*
|
|
28913
|
-
* Observe the watching count for a room with real-time updates
|
|
28914
|
-
*
|
|
28915
|
-
* @param roomId The ID of the room to observe watching count for
|
|
28916
|
-
* @param callback The function to call when watching count changes
|
|
28917
|
-
* @returns An {@link Amity.Unsubscriber} function to stop observing
|
|
28918
|
-
*
|
|
28919
|
-
* @category Room Observable
|
|
28920
|
-
*/
|
|
28921
|
-
const getWatchingUsers = (roomId, callback) => {
|
|
28922
|
-
const { _id: userId } = getCurrentUser();
|
|
28923
|
-
if (!userId)
|
|
28924
|
-
throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
28925
|
-
const { log, cache } = getActiveClient();
|
|
28926
|
-
if (!cache) {
|
|
28927
|
-
console.log('For using Live Object feature you need to enable Cache!');
|
|
28928
|
-
}
|
|
28929
|
-
const timestamp = Date.now();
|
|
28930
|
-
log(`liveWatchingCount(tmpid: ${timestamp}) > listen`);
|
|
28931
|
-
const disposers = [];
|
|
28932
|
-
let model;
|
|
28933
|
-
const dispatcher = (data) => {
|
|
28934
|
-
var _a;
|
|
28935
|
-
const callbackData = (_a = data === null || data === void 0 ? void 0 : data.map((userId) => { var _a; return (_a = pullFromCache(['user', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data; }).filter(isNonNullable).map(LinkedObject.user)) !== null && _a !== void 0 ? _a : [];
|
|
28936
|
-
callback(callbackData);
|
|
28937
|
-
};
|
|
28938
|
-
const realtimeRouter = (_) => {
|
|
28939
|
-
var _a;
|
|
28940
|
-
const data = (_a = pullFromCache([
|
|
28941
|
-
'watchingUsers',
|
|
28942
|
-
'collection',
|
|
28943
|
-
roomId,
|
|
28944
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28945
|
-
if (isEqual(model, data))
|
|
28946
|
-
return;
|
|
28947
|
-
dispatcher(data);
|
|
28948
|
-
};
|
|
28949
|
-
const onFetch = () => {
|
|
28950
|
-
var _a;
|
|
28951
|
-
const data = (_a = pullFromCache([
|
|
28952
|
-
'watchingUsers',
|
|
28953
|
-
'collection',
|
|
28954
|
-
roomId,
|
|
28955
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28956
|
-
dispatcher(data);
|
|
28957
|
-
};
|
|
28958
|
-
disposers.push(onRoomWatchingUsersFetched(realtimeRouter));
|
|
28959
|
-
onFetch();
|
|
28960
|
-
return () => {
|
|
28961
|
-
disposers.forEach(fn => fn());
|
|
28962
|
-
};
|
|
28963
|
-
};
|
|
28964
|
-
|
|
28965
|
-
const getPresenceSetting = async () => {
|
|
28966
|
-
const client = getActiveClient();
|
|
28967
|
-
client.log('presence/getPresenceSetting');
|
|
28968
|
-
const { data } = await client.http.get('/api/v1/presence/settings');
|
|
28969
|
-
pushToCache(['get', 'presenceSetting'], data);
|
|
28970
|
-
return data;
|
|
28971
|
-
};
|
|
28972
|
-
|
|
28973
|
-
class WatchingSyncEngine {
|
|
28974
|
-
constructor(roomId) {
|
|
28975
|
-
this.roomId = roomId;
|
|
28976
|
-
this.config = {
|
|
28977
|
-
heartbeatInterval: 1 * MINUTE,
|
|
28978
|
-
presenceSyncInterval: 30 * SECOND$1,
|
|
28979
|
-
};
|
|
28980
|
-
// Initialize config asynchronously - don't await in constructor
|
|
28981
|
-
this.initializeConfig().catch(error => {
|
|
28982
|
-
console.error('Failed to initialize WatchingSyncEngine config in constructor:', error);
|
|
28983
|
-
});
|
|
28984
|
-
}
|
|
28985
|
-
async initializeConfig() {
|
|
28986
|
-
try {
|
|
28987
|
-
// Get presence settings from API with retry logic
|
|
28988
|
-
const presenceSettings = await WatchingSyncEngine.getPresenceSettingWithRetry();
|
|
28989
|
-
if (presenceSettings) {
|
|
28990
|
-
// Set intervals from network settings (convert from minutes to milliseconds)
|
|
28991
|
-
this.config = {
|
|
28992
|
-
heartbeatInterval: (presenceSettings.network.heartbeatInterval || 5) * 60 * 1000,
|
|
28993
|
-
presenceSyncInterval: (presenceSettings.network.presenceSyncInterval || 1) * 60 * 1000,
|
|
28994
|
-
};
|
|
28995
|
-
}
|
|
28996
|
-
else {
|
|
28997
|
-
// Use default intervals if all retries failed
|
|
28998
|
-
this.config.heartbeatInterval = 5 * 60 * 1000; // 5 minutes
|
|
28999
|
-
this.config.presenceSyncInterval = 1 * 60 * 1000; // 1 minute
|
|
29000
|
-
}
|
|
29001
|
-
}
|
|
29002
|
-
catch (error) {
|
|
29003
|
-
console.error('Failed to initialize WatchingSyncEngine config:', error);
|
|
29004
|
-
// Use default intervals if settings fetch fails
|
|
29005
|
-
this.config.heartbeatInterval = 5 * 60 * 1000; // 5 minutes
|
|
29006
|
-
this.config.presenceSyncInterval = 1 * 60 * 1000; // 1 minute
|
|
29007
|
-
}
|
|
29008
|
-
}
|
|
29009
|
-
static async getPresenceSettingWithRetry(maxRetries = 5) {
|
|
29010
|
-
for (let attempt = 0; attempt < maxRetries; attempt += 1) {
|
|
29011
|
-
try {
|
|
29012
|
-
// eslint-disable-next-line no-await-in-loop
|
|
29013
|
-
const presenceSettings = await getPresenceSetting();
|
|
29014
|
-
return presenceSettings;
|
|
29015
|
-
}
|
|
29016
|
-
catch (error) {
|
|
29017
|
-
if (attempt >= maxRetries - 1) {
|
|
29018
|
-
console.error(`Failed to get presence setting after ${maxRetries} attempts:`, error);
|
|
29019
|
-
return null;
|
|
29020
|
-
}
|
|
29021
|
-
// Calculate delay: 20 seconds + random jitter (0-5 seconds)
|
|
29022
|
-
const jitter = Math.random() * 5000; // 0-5 seconds in milliseconds
|
|
29023
|
-
const delay = 20000 + jitter; // 20 seconds + jitter
|
|
29024
|
-
console.warn(`Failed to get presence setting (attempt ${attempt + 1}/${maxRetries}), retrying in ${Math.round(delay / 1000)}s:`, error);
|
|
29025
|
-
// Wait before retry
|
|
29026
|
-
// eslint-disable-next-line no-await-in-loop
|
|
29027
|
-
await new Promise(resolve => {
|
|
29028
|
-
setTimeout(resolve, delay);
|
|
29029
|
-
});
|
|
29030
|
-
}
|
|
29031
|
-
}
|
|
29032
|
-
return null;
|
|
29033
|
-
}
|
|
29034
|
-
startWatching() {
|
|
29035
|
-
if (!this.roomId) {
|
|
29036
|
-
console.error('WatchingSyncEngine: roomId is required');
|
|
29037
|
-
return;
|
|
29038
|
-
}
|
|
29039
|
-
// Stop existing timer if any
|
|
29040
|
-
this.stopWatching();
|
|
29041
|
-
// Send immediate heartbeat when starting
|
|
29042
|
-
this.sendHeartbeat();
|
|
29043
|
-
// Start heartbeat timer
|
|
29044
|
-
this.heartbeatTimer = setInterval(() => {
|
|
29045
|
-
this.sendHeartbeat();
|
|
29046
|
-
}, this.config.heartbeatInterval);
|
|
29047
|
-
}
|
|
29048
|
-
async sendHeartbeat() {
|
|
29049
|
-
if (!this.roomId)
|
|
29050
|
-
return;
|
|
29051
|
-
try {
|
|
29052
|
-
const client = getActiveClient();
|
|
29053
|
-
await client.http.post(`/api/v1/presence/rooms/${this.roomId}/heartbeat`);
|
|
29054
|
-
}
|
|
29055
|
-
catch (error) {
|
|
29056
|
-
console.error('Heartbeat failed:', error);
|
|
29057
|
-
}
|
|
29058
|
-
}
|
|
29059
|
-
stopWatching() {
|
|
29060
|
-
if (this.heartbeatTimer) {
|
|
29061
|
-
clearInterval(this.heartbeatTimer);
|
|
29062
|
-
this.heartbeatTimer = undefined;
|
|
29063
|
-
}
|
|
29064
|
-
}
|
|
29065
|
-
syncWatchingUsers() {
|
|
29066
|
-
if (!this.roomId) {
|
|
29067
|
-
console.error('WatchingSyncEngine: roomId is required');
|
|
29068
|
-
return;
|
|
29069
|
-
}
|
|
29070
|
-
// Stop existing timer if any
|
|
29071
|
-
this.stopSyncWatchingUsers();
|
|
29072
|
-
// Fetch watching data immediately when starting
|
|
29073
|
-
this.fetchWatchingData();
|
|
29074
|
-
// Start watching users sync timer
|
|
29075
|
-
this.watchingUsersTimer = setInterval(() => {
|
|
29076
|
-
this.fetchWatchingData();
|
|
29077
|
-
}, this.config.presenceSyncInterval);
|
|
29078
|
-
}
|
|
29079
|
-
async fetchWatchingData() {
|
|
29080
|
-
if (!this.roomId)
|
|
29081
|
-
return;
|
|
29082
|
-
try {
|
|
29083
|
-
// Call both APIs to sync watching data
|
|
29084
|
-
const [count, users] = await Promise.all([
|
|
29085
|
-
getWatchingCount$1(this.roomId),
|
|
29086
|
-
getWatchingUsers$1(this.roomId),
|
|
29087
|
-
]);
|
|
29088
|
-
// Data is automatically cached by the individual API calls
|
|
29089
|
-
const client = getActiveClient();
|
|
29090
|
-
client.log('room/watchingSync', { roomId: this.roomId, count, usersCount: users.length });
|
|
29091
|
-
}
|
|
29092
|
-
catch (error) {
|
|
29093
|
-
console.error('Watching users sync failed:', error);
|
|
29094
|
-
}
|
|
29095
|
-
}
|
|
29096
|
-
stopSyncWatchingUsers() {
|
|
29097
|
-
if (this.watchingUsersTimer) {
|
|
29098
|
-
clearInterval(this.watchingUsersTimer);
|
|
29099
|
-
this.watchingUsersTimer = undefined;
|
|
29100
|
-
}
|
|
29101
|
-
}
|
|
29102
|
-
/**
|
|
29103
|
-
* Cleanup method to stop all timers and release resources
|
|
29104
|
-
* Call this when the engine instance is no longer needed
|
|
29105
|
-
*/
|
|
29106
|
-
destroy() {
|
|
29107
|
-
// Stop all active timers
|
|
29108
|
-
this.stopWatching();
|
|
29109
|
-
this.stopSyncWatchingUsers();
|
|
29110
|
-
}
|
|
29111
|
-
// Session Management
|
|
29112
|
-
onSessionDestroyed() {
|
|
29113
|
-
// Stop all timers when session is destroyed and cleanup
|
|
29114
|
-
this.destroy();
|
|
29115
|
-
}
|
|
29116
|
-
onTokenExpired() {
|
|
29117
|
-
// Stop timers when token expires
|
|
29118
|
-
this.stopWatching();
|
|
29119
|
-
this.stopSyncWatchingUsers();
|
|
29120
|
-
}
|
|
29121
|
-
}
|
|
29122
|
-
|
|
29123
|
-
// Global map to store instances
|
|
29124
|
-
const engineInstances = new Map();
|
|
29125
|
-
/**
|
|
29126
|
-
* Get or create a WatchingSyncEngine instance for a room
|
|
29127
|
-
*
|
|
29128
|
-
* @param roomId The room ID to get/create engine for
|
|
29129
|
-
* @returns WatchingSyncEngine instance for the room
|
|
29130
|
-
*/
|
|
29131
|
-
const getWatchingSyncEngine = (roomId) => {
|
|
29132
|
-
let engine = engineInstances.get(roomId);
|
|
29133
|
-
if (!engine) {
|
|
29134
|
-
engine = new WatchingSyncEngine(roomId);
|
|
29135
|
-
engineInstances.set(roomId, engine);
|
|
29136
|
-
}
|
|
29137
|
-
return engine;
|
|
29138
|
-
};
|
|
29139
|
-
/**
|
|
29140
|
-
* Destroy and remove engine instance for a room
|
|
29141
|
-
*
|
|
29142
|
-
* @param roomId The room ID to destroy engine for
|
|
29143
|
-
*/
|
|
29144
|
-
const destroyWatchingSyncEngine = (roomId) => {
|
|
29145
|
-
const engine = engineInstances.get(roomId);
|
|
29146
|
-
if (engine) {
|
|
29147
|
-
engine.destroy();
|
|
29148
|
-
engineInstances.delete(roomId);
|
|
29149
|
-
}
|
|
29150
|
-
};
|
|
29151
|
-
/**
|
|
29152
|
-
* Get all active room IDs with engines
|
|
29153
|
-
*/
|
|
29154
|
-
const getActiveWatchingRooms = () => {
|
|
29155
|
-
return Array.from(engineInstances.keys());
|
|
29156
|
-
};
|
|
29157
|
-
/**
|
|
29158
|
-
* Check if a room has an active engine
|
|
29159
|
-
*/
|
|
29160
|
-
const hasWatchingSyncEngine = (roomId) => {
|
|
29161
|
-
return engineInstances.has(roomId);
|
|
29162
|
-
};
|
|
29163
|
-
/**
|
|
29164
|
-
* Destroy all engines
|
|
29165
|
-
*/
|
|
29166
|
-
const destroyAllWatchingSyncEngines = () => {
|
|
29167
|
-
engineInstances.forEach(engine => {
|
|
29168
|
-
engine.destroy();
|
|
29169
|
-
});
|
|
29170
|
-
engineInstances.clear();
|
|
29171
|
-
};
|
|
29172
|
-
/**
|
|
29173
|
-
* Session management functions
|
|
29174
|
-
*/
|
|
29175
|
-
const onWatchingSyncSessionDestroyed = () => {
|
|
29176
|
-
destroyAllWatchingSyncEngines();
|
|
29177
|
-
};
|
|
29178
|
-
const onWatchingSyncTokenExpired = () => {
|
|
29179
|
-
engineInstances.forEach(engine => {
|
|
29180
|
-
engine.onTokenExpired();
|
|
29181
|
-
});
|
|
29182
|
-
};
|
|
29183
|
-
|
|
29184
28761
|
var index$8 = /*#__PURE__*/Object.freeze({
|
|
29185
28762
|
__proto__: null,
|
|
29186
28763
|
createRoom: createRoom,
|
|
@@ -29208,16 +28785,7 @@ var index$8 = /*#__PURE__*/Object.freeze({
|
|
|
29208
28785
|
onRoomParticipantRemoved: onRoomParticipantRemoved,
|
|
29209
28786
|
onRoomLeft: onRoomLeft,
|
|
29210
28787
|
getRoom: getRoom,
|
|
29211
|
-
getRooms: getRooms
|
|
29212
|
-
getWatchingCount: getWatchingCount,
|
|
29213
|
-
getWatchingUsers: getWatchingUsers,
|
|
29214
|
-
getWatchingSyncEngine: getWatchingSyncEngine,
|
|
29215
|
-
destroyWatchingSyncEngine: destroyWatchingSyncEngine,
|
|
29216
|
-
getActiveWatchingRooms: getActiveWatchingRooms,
|
|
29217
|
-
hasWatchingSyncEngine: hasWatchingSyncEngine,
|
|
29218
|
-
destroyAllWatchingSyncEngines: destroyAllWatchingSyncEngines,
|
|
29219
|
-
onWatchingSyncSessionDestroyed: onWatchingSyncSessionDestroyed,
|
|
29220
|
-
onWatchingSyncTokenExpired: onWatchingSyncTokenExpired
|
|
28788
|
+
getRooms: getRooms
|
|
29221
28789
|
});
|
|
29222
28790
|
|
|
29223
28791
|
/* begin_public_function
|
|
@@ -31547,28 +31115,6 @@ const cancelInvitation = async (invitationId) => {
|
|
|
31547
31115
|
};
|
|
31548
31116
|
/* end_public_function */
|
|
31549
31117
|
|
|
31550
|
-
/* begin_public_function
|
|
31551
|
-
id: invitation.accept
|
|
31552
|
-
*/
|
|
31553
|
-
/**
|
|
31554
|
-
* ```js
|
|
31555
|
-
* import { acceptInvitation } from '@amityco/ts-sdk'
|
|
31556
|
-
* const isAccepted = await acceptInvitation(invitationId)
|
|
31557
|
-
* ```
|
|
31558
|
-
*
|
|
31559
|
-
* Accepts a {@link Amity.Invitation} object
|
|
31560
|
-
*
|
|
31561
|
-
* @param invitationId the {@link Amity.Invitation} to accept
|
|
31562
|
-
* @returns A success boolean if the {@link Amity.Invitation} was accepted
|
|
31563
|
-
*
|
|
31564
|
-
* @category Invitation API
|
|
31565
|
-
* @async
|
|
31566
|
-
*/
|
|
31567
|
-
const acceptInvitation = async (invitationId) => {
|
|
31568
|
-
return acceptInvitation$1(invitationId);
|
|
31569
|
-
};
|
|
31570
|
-
/* end_public_function */
|
|
31571
|
-
|
|
31572
31118
|
class MyInvitationsPaginationController extends PaginationController {
|
|
31573
31119
|
async getRequest(queryParams, token) {
|
|
31574
31120
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
@@ -31807,7 +31353,7 @@ const getInvitations = (params, callback) => {
|
|
|
31807
31353
|
callback(data.map(LinkedObject.invitation));
|
|
31808
31354
|
};
|
|
31809
31355
|
const realtimeRouter = (data) => {
|
|
31810
|
-
const invitations =
|
|
31356
|
+
const invitations = data.filter(({ targetId, targetType }) => targetId === params.targetId && targetType === params.targetType);
|
|
31811
31357
|
dispatcher(invitations);
|
|
31812
31358
|
};
|
|
31813
31359
|
// Only subscribe to room co-host events for now (since that's what we have implemented)
|
|
@@ -31827,7 +31373,6 @@ const getInvitations = (params, callback) => {
|
|
|
31827
31373
|
var index$2 = /*#__PURE__*/Object.freeze({
|
|
31828
31374
|
__proto__: null,
|
|
31829
31375
|
cancelInvitation: cancelInvitation,
|
|
31830
|
-
acceptInvitation: acceptInvitation,
|
|
31831
31376
|
onLocalInvitationCreated: onLocalInvitationCreated,
|
|
31832
31377
|
onLocalInvitationUpdated: onLocalInvitationUpdated,
|
|
31833
31378
|
onLocalInvitationCanceled: onLocalInvitationCanceled,
|