@cometchat/chat-sdk-javascript 4.1.12 → 4.1.14

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/CometChat.d.ts CHANGED
@@ -469,11 +469,6 @@ export class CometChat {
469
469
  WEBRTC_HTTPS_BIND_PORT: string;
470
470
  EXTENSION_LIST: string;
471
471
  EXTENSION_KEYS: {
472
- /**
473
- * This method removes data from the session storage.
474
- * @internal
475
- * @memberof CometChat
476
- */
477
472
  ID: string;
478
473
  NAME: string;
479
474
  };
@@ -510,6 +505,8 @@ export class CometChat {
510
505
  CORE_CONVERSATIONS_UPDATE_ON_CUSTOM_MESSAGES: string;
511
506
  CORE_CONVERSATIONS_UPDATE_ON_REPLIES: string;
512
507
  FLAG_REASONS: string;
508
+ FILE_SIZE_MAX: string;
509
+ FILE_COUNT_MAX: string;
513
510
  };
514
511
  };
515
512
  static GroupConstants: {
@@ -555,11 +552,6 @@ export class CometChat {
555
552
  };
556
553
  };
557
554
  static PresenceConstants: {
558
- /**
559
- * This method checks if Analytics Ping has started.
560
- * @internal
561
- * @returns {boolean}
562
- */
563
555
  STATUS: {
564
556
  ONLINE: string;
565
557
  AVAILABLE: string;
@@ -649,7 +641,7 @@ export class CometChat {
649
641
  code: string;
650
642
  name: string;
651
643
  message: string;
652
- /** @internal */ details: {};
644
+ details: {};
653
645
  };
654
646
  MUST_BE_A_POSITIVE_NUMBER: {
655
647
  code: string;
@@ -824,11 +816,7 @@ export class CometChat {
824
816
  details: {};
825
817
  };
826
818
  FEATURE_NOT_FOUND: {
827
- code: string; /**
828
- * This method triggers before a page unloads.
829
- * @internal
830
- * @memberof CometChat
831
- */
819
+ code: string;
832
820
  name: string;
833
821
  message: string;
834
822
  details: {};
@@ -1161,6 +1149,9 @@ export class CometChat {
1161
1149
  static CallListener: typeof CallListener;
1162
1150
  static ConnectionListener: typeof ConnectionListener;
1163
1151
  static LoginListener: typeof LoginListener;
1152
+ static UploadFileListener: typeof UploadFileListener;
1153
+ static UploadFileRequest: typeof UploadFileRequest;
1154
+ static UploadStatus: typeof UploadStatus;
1164
1155
  static AIAssistantListener: typeof AIAssistantListener;
1165
1156
  static CallController: typeof CallController;
1166
1157
  static CometChatHelper: typeof CometChatHelper;
@@ -1422,6 +1413,46 @@ export class CometChat {
1422
1413
  * @memberof CometChat
1423
1414
  */
1424
1415
  static sendMediaMessage(message: Object): Promise<TextMessage | BaseMessage | MediaMessage | CustomMessage>;
1416
+ /**
1417
+ * Creates an {@link UploadFileRequest} scoped to one destination and one upload batch. This is
1418
+ * the entry point for the multi-attachment upload flow: configure the request
1419
+ * (`setParentMessageId`/`setBatchId`/`setConcurrency`), upload files through it
1420
+ * (`uploadAttachment`/`uploadAttachments`), read the batch (`getAttachments`/`getStatus`/…),
1421
+ * then build a `MediaMessage` from its attachments and call {@link CometChat.sendMediaMessage}.
1422
+ *
1423
+ * @param {string} receiverId Intended recipient id (uid or guid). Sent in the presign call for role-based access control.
1424
+ * @param {string} receiverType Recipient type (`user` or `group`). Sent in the presign call for role-based access control.
1425
+ * @returns {UploadFileRequest} A request object scoped to this destination + one batch.
1426
+ * @memberof CometChat
1427
+ *
1428
+ * @example
1429
+ * // 1) Upload files through the request.
1430
+ * const request = CometChat.createUploadFileRequest(receiverId, receiverType);
1431
+ * request.uploadAttachments(files.map(f => ({ fileId: f.id, file: f })), new CometChat.UploadFileListener({
1432
+ * onFileUploaded: (fileId, attachment) => { ... },
1433
+ * onComplete: (result) => { ... }, // fires when the batch settles
1434
+ * }));
1435
+ *
1436
+ * // 2) When ready, build the MediaMessage and send it.
1437
+ * // IMPORTANT: pass `null` as the file argument and attach the uploaded attachments with
1438
+ * // setAttachments(). Do NOT pass request.getAttachments() as the constructor's file argument —
1439
+ * // that sets the raw-file field and the message silently falls back to the legacy upload path.
1440
+ * const message = new CometChat.MediaMessage(receiverId, null, CometChat.MESSAGE_TYPE.IMAGE, receiverType);
1441
+ * message.setAttachments(request.getAttachments()); // pre-uploaded attachments
1442
+ * message.setCaption("Optional caption");
1443
+ * CometChat.sendMediaMessage(message).then(sent => { ... });
1444
+ * request.clearAll(); // release the batch after sending
1445
+ */
1446
+ static createUploadFileRequest(receiverId: string, receiverType: string): UploadFileRequest;
1447
+ /**
1448
+ * Returns the maximum number of attachments allowed per message, as configured
1449
+ * in app settings (`file.count.max`). Falls back to `UPLOAD_CONSTANTS.DEFAULT_FILE_COUNT_MAX`
1450
+ * if the setting is not available.
1451
+ *
1452
+ * @returns {Promise<number>}
1453
+ * @memberof CometChat
1454
+ */
1455
+ static getMaxAttachmentCount(): Promise<number>;
1425
1456
  /**
1426
1457
  *
1427
1458
  * Function to send a custom message.
@@ -2424,6 +2455,286 @@ export interface CometChatSettings {
2424
2455
  uiKit?: Record<string, unknown>;
2425
2456
  }
2426
2457
 
2458
+ /**
2459
+ *
2460
+ * @module UploadFileListener
2461
+ */
2462
+ /**
2463
+ * Callback bundle for an upload batch. Passed per call to
2464
+ * {@link UploadFileRequest.uploadAttachment}/{@link UploadFileRequest.uploadAttachments}, and also
2465
+ * registered as the batch-wide global listener via {@link UploadFileRequest.addUploadListener}.
2466
+ * Every callback is optional; override only the ones you need. Unlike `MessageListener`/
2467
+ * `CallListener`, this is not registered globally with a string id — it lives for the duration of
2468
+ * the upload batch.
2469
+ *
2470
+ * @example
2471
+ * const request = CometChat.createUploadFileRequest(receiverId, receiverType);
2472
+ * // Each item pairs a file with a required, caller-supplied fileId (echoed back on every event).
2473
+ * request.uploadAttachments(files.map(f => ({ fileId: f.id, file: f })), new CometChat.UploadFileListener({
2474
+ * onFileProgress: (fileId, loaded, total, percent) => {},
2475
+ * onFileUploaded: (fileId, attachment) => {},
2476
+ * onFileError: (fileId, error) => {},
2477
+ * onFileFailure: (fileId, error) => {},
2478
+ * onComplete: (result) => {}
2479
+ * }));
2480
+ */
2481
+ export class UploadFileListener {
2482
+ /** Per-file upload progress. */
2483
+ onFileProgress?: (fileId: string, loaded: number, total: number, percent: number) => void;
2484
+ /** Per-file success. */
2485
+ onFileUploaded?: (fileId: string, attachment: Attachment) => void;
2486
+ /** Per-file rejected — not retryable (fix input / permission). */
2487
+ onFileError?: (fileId: string, error: CometChatException) => void;
2488
+ /** Per-file transfer failure — retryable via `retryAttachment`. */
2489
+ onFileFailure?: (fileId: string, error: CometChatException) => void;
2490
+ /** Fires once each time the batch drains (no files in-flight). */
2491
+ onComplete?: (result: UploadResult) => void;
2492
+ constructor(callbacks?: {
2493
+ onFileProgress?: (fileId: string, loaded: number, total: number, percent: number) => void;
2494
+ onFileUploaded?: (fileId: string, attachment: Attachment) => void;
2495
+ onFileError?: (fileId: string, error: CometChatException) => void;
2496
+ onFileFailure?: (fileId: string, error: CometChatException) => void;
2497
+ onComplete?: (result: UploadResult) => void;
2498
+ });
2499
+ }
2500
+
2501
+ /**
2502
+ *
2503
+ * @module UploadFileRequest
2504
+ */
2505
+ /**
2506
+ * A request object scoped to one destination (`receiverId`/`receiverType`) and one upload **batch**.
2507
+ * The request owns the batch id (auto-generated as a UUID unless the app sets one) and forwards all
2508
+ * operations to the {@link UploadManager}. Obtain one via {@link CometChat.createUploadFileRequest}.
2509
+ *
2510
+ * Upload is decoupled from sending: upload files through the request, then build a `MediaMessage`
2511
+ * with the request's attachments (`getAttachments()` / `getAttachmentsByType()`) and call
2512
+ * {@link CometChat.sendMediaMessage}.
2513
+ */
2514
+ export class UploadFileRequest {
2515
+ /**
2516
+ * @param {string} receiverId Recipient id (uid/guid). Sent in the presign call for RBAC/SBAC.
2517
+ * @param {string} receiverType Recipient type (`user`/`group`). Sent in the presign call.
2518
+ */
2519
+ constructor(receiverId: string, receiverType: string);
2520
+ /**
2521
+ * Mark this batch as belonging to a thread. The id is sent with `receiverId`/`receiverType` in
2522
+ * the presign call. Omit for a top-level (non-thread) message.
2523
+ * @param {string | number} messageId
2524
+ * @returns {UploadFileRequest}
2525
+ */
2526
+ setParentMessageId(messageId: string | number): UploadFileRequest;
2527
+ /**
2528
+ * Set the batch id all files in this request share. If never called, the SDK keeps the
2529
+ * auto-generated UUID. Has no effect once files have been uploaded through the request.
2530
+ * @param {string} batchId
2531
+ * @returns {UploadFileRequest}
2532
+ */
2533
+ setBatchId(batchId: string): UploadFileRequest;
2534
+ /**
2535
+ * @returns {string} The effective batch id (app-set or auto-generated UUID).
2536
+ */
2537
+ getBatchId(): string;
2538
+ /**
2539
+ * Set how many files upload concurrently for this batch. Default 1 (sequential). Applies from
2540
+ * the next drain onward.
2541
+ * @param {number} count
2542
+ * @returns {UploadFileRequest}
2543
+ */
2544
+ setConcurrency(count: number): UploadFileRequest;
2545
+ /**
2546
+ * Upload multiple files into this batch. Each entry pairs the file with a **required**
2547
+ * caller-supplied `fileId` (echoed back on every event). A `fileId` already present in the batch
2548
+ * is skipped (deduped).
2549
+ * @param {UploadItem[]} files `{ fileId, file }[]`
2550
+ * @param {UploadFileListener} [listener] Per-call events for these files.
2551
+ */
2552
+ uploadAttachments(files: UploadItem[], listener?: UploadFileListener): void;
2553
+ /**
2554
+ * Upload a single file into this batch under a **required** caller-supplied `fileId`.
2555
+ * @param {string} fileId Caller-supplied id (required; echoed back on every event).
2556
+ * @param {UploadFileInput} file Platform-native file (`File`/`Blob`).
2557
+ * @param {UploadFileListener} [listener] Per-call events for this file.
2558
+ */
2559
+ uploadAttachment(fileId: string, file: UploadFileInput, listener?: UploadFileListener): void;
2560
+ /**
2561
+ * @param {string} fileId
2562
+ * @returns {Attachment | null} The uploaded attachment for `fileId`, or null if unknown / not yet uploaded.
2563
+ */
2564
+ getAttachment(fileId: string): Attachment | null;
2565
+ /**
2566
+ * @returns {Attachment[]} All uploaded attachments in the batch.
2567
+ */
2568
+ getAttachments(): Attachment[];
2569
+ /**
2570
+ * @param {string} type One of `image`/`video`/`audio`/`file`.
2571
+ * @returns {Attachment[]} Uploaded attachments of that kind — always an array (empty when none).
2572
+ */
2573
+ getAttachmentsByType(type: string): Attachment[];
2574
+ /**
2575
+ * @returns {number} Total files in the batch, any state (in-progress/failed/succeeded).
2576
+ */
2577
+ getAttachmentCount(): number;
2578
+ /**
2579
+ * @returns {UploadStatus} `IN_PROGRESS` while any upload is running, else `IDLE`.
2580
+ */
2581
+ getStatus(): UploadStatus;
2582
+ /**
2583
+ * Add a batch-wide global listener that fires for every file across all upload calls on this
2584
+ * request. A later call overrides the previous global listener (single slot).
2585
+ * @param {UploadFileListener} listener
2586
+ */
2587
+ addUploadListener(listener: UploadFileListener): void;
2588
+ /**
2589
+ * Remove the batch-wide global listener.
2590
+ */
2591
+ removeUploadListener(): void;
2592
+ /**
2593
+ * Re-upload one FAILED file (`onFileFailure`) using its retained bytes, re-presigning if the
2594
+ * prior presign expired. No-op for rejected/uploaded files.
2595
+ * @param {string} fileId
2596
+ */
2597
+ retryAttachment(fileId: string): void;
2598
+ /**
2599
+ * Remove one file from the batch. Aborts its in-flight upload (silently) if still uploading, or
2600
+ * drops it from the set if already uploaded.
2601
+ * @param {string} fileId
2602
+ */
2603
+ removeAttachment(fileId: string): void;
2604
+ /**
2605
+ * Clear all files and release this batch from SDK memory, aborting any in-flight uploads. Call
2606
+ * after a successful send, or to abandon a composer.
2607
+ */
2608
+ clearAll(): void;
2609
+ }
2610
+
2611
+ /**
2612
+ *
2613
+ * @module UploadTypes
2614
+ */
2615
+ /**
2616
+ * Per-file upload lifecycle status (internal).
2617
+ * @private
2618
+ */
2619
+ export enum UploadFileStatus {
2620
+ QUEUED = "queued",
2621
+ REQUESTING_URL = "requesting_url",
2622
+ UPLOADING = "uploading",
2623
+ UPLOADED = "uploaded",
2624
+ FAILED = "failed",
2625
+ REJECTED = "rejected",
2626
+ CANCELLED = "cancelled"
2627
+ }
2628
+ /**
2629
+ * Public batch-level status returned by {@link UploadFileRequest.getStatus}.
2630
+ * `IN_PROGRESS` while any file is still non-terminal; `IDLE` when nothing is in flight — i.e. the
2631
+ * batch is empty or every file has settled.
2632
+ */
2633
+ export enum UploadStatus {
2634
+ IN_PROGRESS = "in_progress",
2635
+ IDLE = "idle"
2636
+ }
2637
+ /**
2638
+ * Platform-native file input accepted by the upload pipeline. The pipeline needs a numeric
2639
+ * `size`, so inputs must be web `File`/`Blob` objects.
2640
+ */
2641
+ export type UploadFileInput = File | Blob;
2642
+ /**
2643
+ * A single file to upload. `fileId` is **caller-supplied and required** — the SDK does not generate
2644
+ * one; it is echoed back unchanged on every per-file event and used to dedupe within the batch.
2645
+ */
2646
+ export interface UploadItem {
2647
+ file: UploadFileInput;
2648
+ fileId: string;
2649
+ }
2650
+ /**
2651
+ * Options accepted internally by the upload manager, supplied by {@link UploadFileRequest}.
2652
+ * @private
2653
+ */
2654
+ export interface UploadOptions {
2655
+ /** Number of simultaneous uploads. Defaults to 1 (sequential). */
2656
+ concurrency?: number;
2657
+ /** The batch id all files share (request-owned; auto-generated when the app omits one). */
2658
+ batchId?: string;
2659
+ /** Recipient id, forwarded to the presign endpoint. */
2660
+ receiverId?: string;
2661
+ /** Recipient type (`user`/`group`), forwarded to the presign endpoint. */
2662
+ receiverType?: string;
2663
+ /** Thread parent message id, forwarded to the presign endpoint for thread batches. */
2664
+ parentMessageId?: string | number;
2665
+ }
2666
+ /**
2667
+ * Recipient context forwarded to the presign endpoint so it can apply role-based access control.
2668
+ * @private
2669
+ */
2670
+ export interface PresignContext {
2671
+ receiverId?: string;
2672
+ receiverType?: string;
2673
+ parentMessageId?: string | number;
2674
+ }
2675
+ /** A successfully uploaded file entry in {@link UploadResult}. */
2676
+ export interface UploadResultSuccessItem {
2677
+ fileId: string;
2678
+ attachment: Attachment;
2679
+ }
2680
+ /** A non-successful file entry in {@link UploadResult}. */
2681
+ export interface UploadResultErrorItem {
2682
+ fileId: string;
2683
+ error: CometChatException;
2684
+ }
2685
+ /**
2686
+ * Aggregate result for an upload group, delivered through `onComplete`.
2687
+ * Reflects the whole group's current settled state.
2688
+ */
2689
+ export interface UploadResult {
2690
+ batchId: string;
2691
+ successful: UploadResultSuccessItem[];
2692
+ /** Files reported via `onFileError` — not retryable. */
2693
+ rejected: UploadResultErrorItem[];
2694
+ /** Files reported via `onFileFailure` — retryable. */
2695
+ failed: UploadResultErrorItem[];
2696
+ }
2697
+ /**
2698
+ * Pre-signed upload form for a single file, returned by the presign endpoint.
2699
+ */
2700
+ export interface PresignForm {
2701
+ request: {
2702
+ url: string;
2703
+ method: string;
2704
+ body: {
2705
+ [key: string]: any;
2706
+ };
2707
+ };
2708
+ attachment: {
2709
+ [key: string]: any;
2710
+ };
2711
+ expiresAt?: number;
2712
+ }
2713
+ /**
2714
+ * Internal per-file state tracked by the upload manager.
2715
+ * @private
2716
+ */
2717
+ export interface UploadFileState {
2718
+ fileId: string;
2719
+ file: any;
2720
+ name: string;
2721
+ size: number;
2722
+ mimeType: string;
2723
+ status: UploadFileStatus;
2724
+ attachment?: Attachment;
2725
+ error?: CometChatException;
2726
+ presign?: PresignForm;
2727
+ presignedAt?: number;
2728
+ lastPercent?: number;
2729
+ request?: {
2730
+ abort: () => void;
2731
+ } | null;
2732
+ stallTimer?: any;
2733
+ settled?: boolean;
2734
+ /** Per-call listener supplied for the upload call that added this file (may be undefined). */
2735
+ listener?: any;
2736
+ }
2737
+
2427
2738
  /**
2428
2739
  *
2429
2740
  * @module CometChatException
@@ -4136,8 +4447,18 @@ export const APP_SETTINGS: {
4136
4447
  CORE_CONVERSATIONS_UPDATE_ON_CUSTOM_MESSAGES: string;
4137
4448
  CORE_CONVERSATIONS_UPDATE_ON_REPLIES: string;
4138
4449
  FLAG_REASONS: string;
4450
+ FILE_SIZE_MAX: string;
4451
+ FILE_COUNT_MAX: string;
4139
4452
  };
4140
4453
  };
4454
+ export const UPLOAD_CONSTANTS: {
4455
+ DEFAULT_FILE_SIZE_MAX: number;
4456
+ DEFAULT_FILE_COUNT_MAX: number;
4457
+ DEFAULT_CONCURRENCY: number;
4458
+ STALL_TIMEOUT_MS: number;
4459
+ PROGRESS_THROTTLE_PERCENT: number;
4460
+ PRESIGN_TTL_MS: number;
4461
+ };
4141
4462
  export const COMMON_UTILITY_CONSTANTS: {
4142
4463
  TYPE_CONSTANTS: {
4143
4464
  BOOLEAN: string;