@talkjs/core 1.2.0 → 1.4.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/README.md +10 -0
- package/dist/talkSession.cjs +1 -1
- package/dist/talkSession.d.ts +217 -11
- package/dist/talkSession.js +590 -362
- package/package.json +2 -2
package/dist/talkSession.d.ts
CHANGED
|
@@ -214,6 +214,92 @@ export declare interface ConversationActiveState {
|
|
|
214
214
|
latestSnapshot: ConversationSnapshot | null;
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
/**
|
|
218
|
+
* The state of a conversation list subscription when it is actively listening for changes
|
|
219
|
+
*
|
|
220
|
+
* @public
|
|
221
|
+
*/
|
|
222
|
+
export declare interface ConversationListActiveState {
|
|
223
|
+
type: "active";
|
|
224
|
+
/**
|
|
225
|
+
* The most recently received snapshot for the conversations
|
|
226
|
+
*/
|
|
227
|
+
latestSnapshot: ConversationSnapshot[];
|
|
228
|
+
/**
|
|
229
|
+
* True if `latestSnapshot` contains all conversations you are in.
|
|
230
|
+
* Use {@link ConversationListSubscription.loadMore} to load more.
|
|
231
|
+
*/
|
|
232
|
+
loadedAll: boolean;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* A subscription to your most recently active conversations.
|
|
237
|
+
*
|
|
238
|
+
* @remarks
|
|
239
|
+
* Get a ConversationListSubscription by calling {@link Session.subscribeConversations}.
|
|
240
|
+
*
|
|
241
|
+
* The subscription is 'windowed'. Initially, this window contains the 20 most recent conversations.
|
|
242
|
+
* Conversations are ordered by last activity. The last activity of a conversation is either `joinedAt` or `lastMessage.createdAt`, whichever is higher.
|
|
243
|
+
*
|
|
244
|
+
* The window will automatically expand to include any conversations you join, and any old conversations that receive new messages after subscribing.
|
|
245
|
+
*
|
|
246
|
+
* You can expand this window by calling {@link ConversationListSubscription.loadMore}, which extends the window further into the past.
|
|
247
|
+
*
|
|
248
|
+
* @public
|
|
249
|
+
*/
|
|
250
|
+
export declare interface ConversationListSubscription {
|
|
251
|
+
/**
|
|
252
|
+
* The current state of the subscription
|
|
253
|
+
*
|
|
254
|
+
* @remarks
|
|
255
|
+
* An object with the following fields:
|
|
256
|
+
*
|
|
257
|
+
* `type` is one of "pending", "active", "unsubscribed", or "error".
|
|
258
|
+
*
|
|
259
|
+
* When `type` is "active", includes `latestSnapshot` and `loadedAll`.
|
|
260
|
+
*
|
|
261
|
+
* - `latestSnapshot: ConversationSnapshot[]` the current state of the conversations in the window
|
|
262
|
+
*
|
|
263
|
+
* - `loadedAll: boolean` true when `latestSnapshot` contains all the conversations you are in
|
|
264
|
+
*
|
|
265
|
+
* When `type` is "error", includes the `error` field. It is a JS `Error` object explaining what caused the subscription to be terminated.
|
|
266
|
+
*/
|
|
267
|
+
state: PendingState | ConversationListActiveState | UnsubscribedState | ErrorState;
|
|
268
|
+
/**
|
|
269
|
+
* Resolves when the subscription starts receiving updates from the server.
|
|
270
|
+
*
|
|
271
|
+
* @remarks
|
|
272
|
+
* Wait for this promise if you want to perform some action as soon as the subscription is active.
|
|
273
|
+
*
|
|
274
|
+
* The promise rejects if the subscription is terminated before it connects.
|
|
275
|
+
*/
|
|
276
|
+
connected: Promise<ConversationListActiveState>;
|
|
277
|
+
/**
|
|
278
|
+
* Resolves when the subscription permanently stops receiving updates from the server.
|
|
279
|
+
*
|
|
280
|
+
* @remarks
|
|
281
|
+
* This is either because you unsubscribed or because the subscription encountered an unrecoverable error.
|
|
282
|
+
*/
|
|
283
|
+
terminated: Promise<UnsubscribedState | ErrorState>;
|
|
284
|
+
/**
|
|
285
|
+
* Expand the window to include older conversations
|
|
286
|
+
*
|
|
287
|
+
* @remarks
|
|
288
|
+
* Calling `loadMore` multiple times in parallel will still only load one page of conversations.
|
|
289
|
+
*
|
|
290
|
+
* @param count - The number of additional conversations to load. Must be between 1 and 30. Default 20.
|
|
291
|
+
* @returns A promise that resolves once the additional conversations have loaded
|
|
292
|
+
*/
|
|
293
|
+
loadMore(count?: number): Promise<void>;
|
|
294
|
+
/**
|
|
295
|
+
* Unsubscribe from this resource and stop receiving updates.
|
|
296
|
+
*
|
|
297
|
+
* @remarks
|
|
298
|
+
* If the subscription is already in the "unsubscribed" or "error" state, this is a no-op.
|
|
299
|
+
*/
|
|
300
|
+
unsubscribe(): void;
|
|
301
|
+
}
|
|
302
|
+
|
|
217
303
|
/**
|
|
218
304
|
* References the conversation with a given conversation ID, from the perspective of the current user.
|
|
219
305
|
*
|
|
@@ -375,8 +461,10 @@ export declare interface ConversationRef {
|
|
|
375
461
|
* Initially, you will be subscribed to the 30 most recent messages and any new messages.
|
|
376
462
|
* Call `loadMore` to load additional older messages.
|
|
377
463
|
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
464
|
+
* While the subscription is active, `onSnapshot` will be called whenever the message snapshots change.
|
|
465
|
+
* This includes when a message is sent, edited, deleted, and when you load more messages.
|
|
466
|
+
* It also includes when nested data changes, such as when `snapshot[0].referencedMessage.sender.name` changes.
|
|
467
|
+
* `loadedAll` is true when `snapshot` contains all the messages in the conversation, and false if you could load more.
|
|
380
468
|
*
|
|
381
469
|
* The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
|
|
382
470
|
*/
|
|
@@ -388,8 +476,10 @@ export declare interface ConversationRef {
|
|
|
388
476
|
* Initially, you will be subscribed to the 10 participants who joined most recently, and any new participants.
|
|
389
477
|
* Call `loadMore` to load additional older participants.
|
|
390
478
|
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
479
|
+
* While the subscription is active, `onSnapshot` will be called whenever the participant snapshots change.
|
|
480
|
+
* This includes when someone joins or leaves, when their participant attributes are edited, and when you load more participants.
|
|
481
|
+
* It also includes when nested data changes, such as when `snapshot[0].user.name` changes.
|
|
482
|
+
* `loadedAll` is true when `snapshot` contains all the participants in the conversation, and false if you could load more.
|
|
393
483
|
*
|
|
394
484
|
* The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
|
|
395
485
|
*/
|
|
@@ -398,7 +488,7 @@ export declare interface ConversationRef {
|
|
|
398
488
|
* Subscribes to the conversation.
|
|
399
489
|
*
|
|
400
490
|
* @remarks
|
|
401
|
-
*
|
|
491
|
+
* While the subscription is active, `onSnapshot` will be called when you join or leave the conversation, or when the snapshot changes.
|
|
402
492
|
* This includes changes to nested data. As an extreme example, `onSnapshot` would be called when `snapshot.lastMessage.referencedMessage.sender.name` changes.
|
|
403
493
|
*
|
|
404
494
|
* The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
|
|
@@ -408,13 +498,11 @@ export declare interface ConversationRef {
|
|
|
408
498
|
* Subscribes to the typing status of the conversation.
|
|
409
499
|
*
|
|
410
500
|
* @remarks
|
|
411
|
-
*
|
|
412
|
-
* This includes changes to nested
|
|
501
|
+
* While the subscription is active, `onSnapshot` will be called when you join or leave the conversation, or when the snapshot changes.
|
|
502
|
+
* This includes changes to the nested `UserSnapshot`s. If one of the people who is typing, changes their name, `onSnapshot` will be called.
|
|
503
|
+
* You will not be notified when there are already "many" people typing, and another person starts typing, because the snapshot does not change.
|
|
413
504
|
*
|
|
414
505
|
* The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
|
|
415
|
-
*
|
|
416
|
-
* Note that if there are "many" people typing and another person starts to type, `onSnapshot` will not be called.
|
|
417
|
-
* This is because your existing {@link ManyTypingSnapshot} is still valid and did not change when the new person started to type.
|
|
418
506
|
*/
|
|
419
507
|
subscribeTyping(onSnapshot?: (snapshot: TypingSnapshot | null) => void): TypingSubscription;
|
|
420
508
|
/**
|
|
@@ -1937,6 +2025,24 @@ export declare interface TalkSession {
|
|
|
1937
2025
|
* @public
|
|
1938
2026
|
*/
|
|
1939
2027
|
conversation(id: string): ConversationRef;
|
|
2028
|
+
/**
|
|
2029
|
+
* Subscribes to your most recently active conversations.
|
|
2030
|
+
*
|
|
2031
|
+
* @remarks
|
|
2032
|
+
* The subscription is 'windowed'. Initially, this window contains the 20 most recent conversations.
|
|
2033
|
+
* Conversations are ordered by last activity. The last activity of a conversation is either `joinedAt` or `lastMessage.createdAt`, whichever is higher.
|
|
2034
|
+
*
|
|
2035
|
+
* If an older conversation receives a new message, or you are added to a conversation, it will appear at the start of the list.
|
|
2036
|
+
* Call `loadMore` to load additional older conversations.
|
|
2037
|
+
*
|
|
2038
|
+
* While the subscription is active, `onSnapshot` will be called whenever the conversation snapshots change.
|
|
2039
|
+
* This includes when you join or leave a conversation, when the conversation attributes change, and when you load more conversations.
|
|
2040
|
+
* It also includes when nested data changes, such as when `snapshot[0].lastMessage.referencedMessage.sender.name` changes.
|
|
2041
|
+
* `loadedAll` is true when `snapshot` contains all your conversations, and false if you could load more.
|
|
2042
|
+
*
|
|
2043
|
+
* If the current user does not exist yet, the snapshot will be an empty list.
|
|
2044
|
+
*/
|
|
2045
|
+
subscribeConversations(onSnapshot?: (snapshot: ConversationSnapshot[], loadedAll: boolean) => void): ConversationListSubscription;
|
|
1940
2046
|
/**
|
|
1941
2047
|
* Upload a generic file without any additional metadata.
|
|
1942
2048
|
*
|
|
@@ -2210,6 +2316,97 @@ export declare interface UserActiveState {
|
|
|
2210
2316
|
latestSnapshot: UserSnapshot | null;
|
|
2211
2317
|
}
|
|
2212
2318
|
|
|
2319
|
+
/**
|
|
2320
|
+
* The state of a user online subscription when it is actively listening for changes
|
|
2321
|
+
*
|
|
2322
|
+
* @public
|
|
2323
|
+
*/
|
|
2324
|
+
export declare interface UserOnlineActiveState {
|
|
2325
|
+
type: "active";
|
|
2326
|
+
/**
|
|
2327
|
+
* The most recently received snapshot
|
|
2328
|
+
*/
|
|
2329
|
+
latestSnapshot: UserOnlineSnapshot | null;
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2332
|
+
/**
|
|
2333
|
+
* A snapshot of a user's online status at a given moment in time.
|
|
2334
|
+
*
|
|
2335
|
+
* @remarks
|
|
2336
|
+
* Snapshots are immutable and we try to reuse them when possible. You should only re-render your UI when `oldSnapshot !== newSnapshot`.
|
|
2337
|
+
*
|
|
2338
|
+
* @public
|
|
2339
|
+
*/
|
|
2340
|
+
export declare interface UserOnlineSnapshot {
|
|
2341
|
+
/**
|
|
2342
|
+
* The user this snapshot relates to
|
|
2343
|
+
*/
|
|
2344
|
+
user: UserSnapshot;
|
|
2345
|
+
/**
|
|
2346
|
+
* Whether the user is connected right now
|
|
2347
|
+
*
|
|
2348
|
+
* @remarks
|
|
2349
|
+
* Users are considered connected whenever they have an active websocket connection to the TalkJS servers.
|
|
2350
|
+
* In practice, this means:
|
|
2351
|
+
*
|
|
2352
|
+
* People using the {@link https://talkjs.com/docs/Reference/JavaScript_Data_API/ | JS Data API} are considered connected if they are subscribed to something, or if they sent a request in the last few seconds.
|
|
2353
|
+
* Creating a `TalkSession` is not enough to appear connected.
|
|
2354
|
+
*
|
|
2355
|
+
* People using {@link https://talkjs.com/docs/Reference/Components/ | Components}, are considered connected if they have a UI open.
|
|
2356
|
+
*
|
|
2357
|
+
* People using the {@link https://talkjs.com/docs/Reference/JavaScript_Chat_SDK/ | JavaScript SDK}, {@link https://talkjs.com/docs/Reference/React_SDK/Installation/ | React SDK}, {@link https://talkjs.com/docs/Reference/React_Native_SDK/Installation/ | React Native SDK}, or {@link https://talkjs.com/docs/Reference/Flutter_SDK/Installation/ | Flutter SDK} are considered connected whenever they have an active `Session` object.
|
|
2358
|
+
*/
|
|
2359
|
+
isConnected: boolean;
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
/**
|
|
2363
|
+
* A subscription to the online status of a user
|
|
2364
|
+
*
|
|
2365
|
+
* @remarks
|
|
2366
|
+
* Get a UserOnlineSubscription by calling {@link UserRef.subscribeOnline}.
|
|
2367
|
+
*
|
|
2368
|
+
* @public
|
|
2369
|
+
*/
|
|
2370
|
+
export declare interface UserOnlineSubscription {
|
|
2371
|
+
/**
|
|
2372
|
+
* The current state of the subscription
|
|
2373
|
+
*
|
|
2374
|
+
* @remarks
|
|
2375
|
+
* An object with the following fields:
|
|
2376
|
+
*
|
|
2377
|
+
* `type` is one of "pending", "active", "unsubscribed", or "error".
|
|
2378
|
+
*
|
|
2379
|
+
* When `type` is "active", includes `latestSnapshot: UserOnlineSnapshot | null`
|
|
2380
|
+
* `null` means the user does not exist.
|
|
2381
|
+
*
|
|
2382
|
+
* When `type` is "error", includes the `error` field. It is a JS `Error` object explaining what caused the subscription to be terminated.
|
|
2383
|
+
*/
|
|
2384
|
+
state: PendingState | UserOnlineActiveState | UnsubscribedState | ErrorState;
|
|
2385
|
+
/**
|
|
2386
|
+
* Resolves when the subscription starts receiving updates from the server.
|
|
2387
|
+
*
|
|
2388
|
+
* @remarks
|
|
2389
|
+
* Wait for this promise if you want to perform some action as soon as the subscription is active.
|
|
2390
|
+
*
|
|
2391
|
+
* The promise rejects if the subscription is terminated before it connects.
|
|
2392
|
+
*/
|
|
2393
|
+
connected: Promise<UserOnlineActiveState>;
|
|
2394
|
+
/**
|
|
2395
|
+
* Resolves when the subscription permanently stops receiving updates from the server.
|
|
2396
|
+
*
|
|
2397
|
+
* @remarks
|
|
2398
|
+
* This is either because you unsubscribed or because the subscription encountered an unrecoverable error.
|
|
2399
|
+
*/
|
|
2400
|
+
terminated: Promise<UnsubscribedState | ErrorState>;
|
|
2401
|
+
/**
|
|
2402
|
+
* Unsubscribe from this resource and stop receiving updates.
|
|
2403
|
+
*
|
|
2404
|
+
* @remarks
|
|
2405
|
+
* If the subscription is already in the "unsubscribed" or "error" state, this is a no-op.
|
|
2406
|
+
*/
|
|
2407
|
+
unsubscribe(): void;
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2213
2410
|
/**
|
|
2214
2411
|
* References the user with a given user ID.
|
|
2215
2412
|
*
|
|
@@ -2262,11 +2459,20 @@ export declare interface UserRef {
|
|
|
2262
2459
|
* Subscribe to this user's state.
|
|
2263
2460
|
*
|
|
2264
2461
|
* @remarks
|
|
2265
|
-
*
|
|
2462
|
+
* While the subscription is active, `onSnapshot` will be called when the user is created or the snapshot changes.
|
|
2266
2463
|
*
|
|
2267
2464
|
* @returns A subscription to the user
|
|
2268
2465
|
*/
|
|
2269
2466
|
subscribe(onSnapshot?: (event: UserSnapshot | null) => void): UserSubscription;
|
|
2467
|
+
/**
|
|
2468
|
+
* Subscribe to this user and their online status.
|
|
2469
|
+
*
|
|
2470
|
+
* @remarks
|
|
2471
|
+
* While the subscription is active, `onSnapshot` will be called when the user is created or the snapshot changes (including changes to the nested UserSnapshot).
|
|
2472
|
+
*
|
|
2473
|
+
* @returns A subscription to the user's online status
|
|
2474
|
+
*/
|
|
2475
|
+
subscribeOnline(onSnapshot?: (event: UserOnlineSnapshot | null) => void): UserOnlineSubscription;
|
|
2270
2476
|
}
|
|
2271
2477
|
|
|
2272
2478
|
/**
|