@ermis-network/ermis-chat-sdk 1.0.8 → 2.0.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/index.d.mts CHANGED
@@ -267,11 +267,13 @@ type FormatMessageResponse<ErmisChatGenerics extends ExtendableGenerics = Defaul
267
267
  status: string;
268
268
  updated_at: Date;
269
269
  };
270
+ type MessageDisplayType = 'normal' | 'deleted';
270
271
  type MessageResponse<ErmisChatGenerics extends ExtendableGenerics = DefaultGenerics> = MessageResponseBase<ErmisChatGenerics> & {
271
272
  quoted_message?: MessageResponseBase<ErmisChatGenerics>;
272
273
  };
273
274
  type MessageResponseBase<ErmisChatGenerics extends ExtendableGenerics = DefaultGenerics> = MessageBase<ErmisChatGenerics> & {
274
275
  type: MessageLabel;
276
+ display_type?: MessageDisplayType;
275
277
  channel?: ChannelResponse<ErmisChatGenerics>;
276
278
  cid?: string;
277
279
  created_at?: string;
@@ -351,6 +353,7 @@ type ChannelQueryOptions = {
351
353
  id_lt?: string;
352
354
  id_gt?: string;
353
355
  id_around?: string;
356
+ include_hidden_messages?: boolean;
354
357
  };
355
358
  };
356
359
  type ChannelStateOptions = {
@@ -383,6 +386,13 @@ type ErmisChatOptions = AxiosRequestConfig & {
383
386
  recoverStateOnReconnect?: boolean;
384
387
  warmUp?: boolean;
385
388
  wsConnection?: StableWSConnection;
389
+ recoveryConfig?: {
390
+ filter?: ChannelFilters;
391
+ sort?: ChannelSort;
392
+ options?: {
393
+ message_limit?: number;
394
+ };
395
+ };
386
396
  };
387
397
  /**
388
398
  * Event Types
@@ -429,6 +439,8 @@ type ChannelFilters = {
429
439
  parent_cid?: string;
430
440
  parent_id?: string;
431
441
  include_parent?: boolean;
442
+ include_hidden_messages?: boolean;
443
+ include_quoted_messages?: boolean;
432
444
  };
433
445
  type CreateTopicData = {
434
446
  name: string;
@@ -596,6 +608,7 @@ declare enum CallAction {
596
608
  UPGRADE_CALL = "upgrade-call"
597
609
  }
598
610
  declare enum CallStatus {
611
+ PREPARING = "preparing",
599
612
  RINGING = "ringing",
600
613
  ENDED = "ended",
601
614
  CONNECTED = "connected",
@@ -664,7 +677,8 @@ declare enum FRAME_TYPE {
664
677
  TRANSCEIVER_STATE = 7,
665
678
  REQUEST_CONFIG = 8,
666
679
  REQUEST_KEY_FRAME = 9,
667
- END_CALL = 10
680
+ END_CALL = 10,
681
+ HEALTH_CALL = 11
668
682
  }
669
683
 
670
684
  type ChannelReadStatus<ErmisChatGenerics extends ExtendableGenerics = DefaultGenerics> = Record<string, {
@@ -1321,34 +1335,67 @@ declare class ErmisChat<ErmisChatGenerics extends ExtendableGenerics = DefaultGe
1321
1335
  _buildWSPayload: (client_request_id?: string) => string;
1322
1336
  }
1323
1337
 
1324
- declare class ErmisCall {
1325
- free(): void;
1326
- [Symbol.dispose](): void;
1327
- constructor();
1328
- spawn(relay_urls: any, secret_key?: Uint8Array | null): Promise<void>;
1329
- getLocalEndpointAddr(): Promise<string>;
1330
- connect(addr: string): Promise<void>;
1331
- closeEndpoint(): Promise<void>;
1332
- closeConnection(): void;
1333
- acceptConnection(): Promise<void>;
1334
- sendControlFrame(data: Uint8Array): void;
1335
- sendAudioFrame(data: Uint8Array): void;
1336
- sendFrame(data: Uint8Array): void;
1337
- notifyNewGop(): void;
1338
- recv(): Uint8Array;
1339
- asyncRecv(): Promise<Uint8Array>;
1340
- beginWithGop(data: Uint8Array): void;
1341
- connectionType(): string | undefined;
1342
- roundTripTime(): number | undefined;
1343
- currentPacketLoss(): number | undefined;
1344
- networkChange(): void;
1345
- getStats(): any;
1338
+ /**
1339
+ * WasmWorkerProxy — Proxy class chạy trên Main Thread.
1340
+ *
1341
+ * Implement interface INodeCall, nhưng mọi method call đều được forward
1342
+ * tới Web Worker qua postMessage. Main Thread KHÔNG BAO GIỜ gọi WASM trực tiếp.
1343
+ *
1344
+ * Data transfer dùng Transferable buffers (zero-copy).
1345
+ */
1346
+
1347
+ declare class WasmWorkerProxy implements INodeCall {
1348
+ private worker;
1349
+ private nextId;
1350
+ private pendingCalls;
1351
+ /** Queue cho asyncRecv — Worker gửi data về, Main Thread consume từng cái */
1352
+ private recvResolveQueue;
1353
+ private recvDataQueue;
1354
+ private recvErrorQueue;
1355
+ /** Static cache — persist across Worker instances */
1356
+ private static cachedBlobUrl;
1357
+ private static cachedWasmBytes;
1358
+ constructor(workerUrl: string | URL);
1359
+ /** Initialize WASM trong Worker — fetch bytes 1 lần, gửi cached bytes cho Worker */
1360
+ init(wasmPath?: string): Promise<void>;
1361
+ /** Spawn WASM node */
1362
+ spawn(relayUrls: string[]): Promise<void>;
1363
+ /** Lấy local endpoint address */
1364
+ getLocalEndpointAddr(): Promise<string>;
1365
+ connect(address: string): Promise<void>;
1366
+ acceptConnection(): Promise<void>;
1367
+ sendFrame(data: Uint8Array): Promise<void>;
1368
+ beginWithGop(data: Uint8Array): Promise<void>;
1369
+ sendAudioFrame(data: Uint8Array): Promise<void>;
1370
+ sendControlFrame(data: Uint8Array): Promise<void>;
1371
+ /**
1372
+ * asyncRecv — nhận data từ Worker recv loop.
1373
+ *
1374
+ * Worker chạy recv loop nội bộ, gửi data về qua postMessage.
1375
+ * Method này trả về Promise resolve khi có data mới.
1376
+ * KHÔNG BAO GIỜ block Main Thread — chỉ chờ postMessage event.
1377
+ */
1378
+ asyncRecv(): Promise<Uint8Array>;
1379
+ /** Bắt đầu recv loop trong Worker */
1380
+ startRecvLoop(): Promise<void>;
1381
+ /** Dừng recv loop trong Worker */
1382
+ stopRecvLoop(): Promise<void>;
1383
+ closeEndpoint(): Promise<void>;
1384
+ closeConnection(): void;
1385
+ networkChange(): void;
1386
+ getStats(): Promise<any>;
1387
+ /** Terminate Worker — gọi khi call kết thúc */
1388
+ terminate(): Promise<void>;
1389
+ private handleMessage;
1390
+ /** Send RPC call to Worker and wait for response */
1391
+ private call;
1346
1392
  }
1347
1393
 
1348
1394
  declare class MediaStreamSender {
1349
1395
  private videoEncoder;
1350
1396
  private audioEncoder;
1351
1397
  private videoReader;
1398
+ private audioReader;
1352
1399
  private localStream;
1353
1400
  private videoConfig;
1354
1401
  private audioConfig;
@@ -1357,7 +1404,10 @@ declare class MediaStreamSender {
1357
1404
  private hasVideo;
1358
1405
  private hasAudio;
1359
1406
  private forceKeyFrame;
1407
+ private isSendingVideo;
1408
+ private isSendingAudio;
1360
1409
  private nodeCall;
1410
+ private healthCallInterval;
1361
1411
  constructor(nodeCall: INodeCall);
1362
1412
  /**
1363
1413
  * Bắt đầu xử lý MediaStream
@@ -1384,6 +1434,8 @@ declare class MediaStreamSender {
1384
1434
  private sendVideoConfig;
1385
1435
  private sendAudioConfig;
1386
1436
  sendConnected: () => Promise<void>;
1437
+ private startHealthCallInterval;
1438
+ private sendHealthCall;
1387
1439
  private sendPacketOrQueue;
1388
1440
  }
1389
1441
 
@@ -1393,9 +1445,12 @@ declare class MediaStreamReceiver {
1393
1445
  private videoWriter;
1394
1446
  private audioContext;
1395
1447
  private mediaDestination;
1448
+ private scheduledAudioNodes;
1396
1449
  private isWaitingForKeyFrame;
1397
1450
  private nextStartTime;
1398
1451
  private lastVideoConfig;
1452
+ private lastVideoConfigStr;
1453
+ private lastAudioConfigStr;
1399
1454
  private nodeCall;
1400
1455
  private events;
1401
1456
  private generatedStream;
@@ -1417,6 +1472,7 @@ declare class MediaStreamReceiver {
1417
1472
 
1418
1473
  declare class ErmisCallNode<ErmisChatGenerics extends ExtendableGenerics = DefaultGenerics> {
1419
1474
  wasmPath: string;
1475
+ workerPath: string;
1420
1476
  relayUrl: string;
1421
1477
  /** Reference to the Ermis Chat client instance */
1422
1478
  _client: ErmisChat<ErmisChatGenerics>;
@@ -1426,12 +1482,12 @@ declare class ErmisCallNode<ErmisChatGenerics extends ExtendableGenerics = Defau
1426
1482
  cid?: string;
1427
1483
  /** Type of call: 'audio' or 'video' */
1428
1484
  callType?: string;
1429
- /** ID of the current user */
1430
- userID?: string | undefined;
1485
+ /** ID of the current user — always reads live value from client */
1486
+ get userID(): string | undefined;
1431
1487
  /** Current status of the call */
1432
1488
  callStatus?: string | undefined;
1433
1489
  metadata?: Metadata;
1434
- callNode: ErmisCall | null;
1490
+ callNode: WasmWorkerProxy | null;
1435
1491
  /** Local media stream from user's camera/microphone */
1436
1492
  localStream?: MediaStream | null;
1437
1493
  /** Remote media stream from the other participant */
@@ -1493,7 +1549,7 @@ declare class ErmisCallNode<ErmisChatGenerics extends ExtendableGenerics = Defau
1493
1549
  private isDestroyed;
1494
1550
  mediaSender: MediaStreamSender | null;
1495
1551
  mediaReceiver: MediaStreamReceiver | null;
1496
- constructor(client: ErmisChat<ErmisChatGenerics>, sessionID: string, wasmPath: string, relayUrl: string);
1552
+ constructor(client: ErmisChat<ErmisChatGenerics>, sessionID: string, wasmPath: string, relayUrl: string, workerPath?: string);
1497
1553
  private loadWasm;
1498
1554
  private initialize;
1499
1555
  getLocalEndpointAddr(): Promise<string | null>;
@@ -1508,7 +1564,7 @@ declare class ErmisCallNode<ErmisChatGenerics extends ExtendableGenerics = Defau
1508
1564
  private setUserInfo;
1509
1565
  private listenSocketEvents;
1510
1566
  private cleanupCall;
1511
- private destroy;
1567
+ destroy(): Promise<void>;
1512
1568
  getDevices(): Promise<{
1513
1569
  audioDevices: MediaDeviceInfo[];
1514
1570
  videoDevices: MediaDeviceInfo[];
@@ -1521,6 +1577,7 @@ declare class ErmisCallNode<ErmisChatGenerics extends ExtendableGenerics = Defau
1521
1577
  audioDevice?: MediaDeviceInfo;
1522
1578
  videoDevice?: MediaDeviceInfo;
1523
1579
  };
1580
+ prefillUserInfo(cid: string): void;
1524
1581
  createCall(callType: string, cid: string): Promise<void>;
1525
1582
  acceptCall(): Promise<void>;
1526
1583
  endCall(): Promise<void>;
@@ -1667,15 +1724,70 @@ declare function formatMessage<ErmisChatGenerics extends ExtendableGenerics = De
1667
1724
  declare const createForwardMessagePayload: <ErmisChatGenerics extends ExtendableGenerics = DefaultGenerics>(message: FormatMessageResponse<ErmisChatGenerics>, targetCid: string, activeCid: string) => ForwardMessage<ErmisChatGenerics>;
1668
1725
 
1669
1726
  /**
1670
- * Parse a raw system message string into a human-readable English sentence.
1727
+ * Translation templates for system messages.
1728
+ * Placeholders: {{user}}, {{channel}}, {{type}}, {{duration}}, {{targetUser}}, {{admin}}
1729
+ */
1730
+ interface SystemMessageTranslations {
1731
+ '1'?: string;
1732
+ '2'?: string;
1733
+ '3'?: string;
1734
+ '4'?: string;
1735
+ '5'?: string;
1736
+ '6'?: string;
1737
+ '7'?: string;
1738
+ '8'?: string;
1739
+ '9'?: string;
1740
+ '10'?: string;
1741
+ '11'?: string;
1742
+ '12'?: string;
1743
+ '13'?: string;
1744
+ '14'?: string;
1745
+ '15_on'?: string;
1746
+ '15_off'?: string;
1747
+ '16'?: string;
1748
+ '17'?: string;
1749
+ '18'?: string;
1750
+ '19'?: string;
1751
+ '20'?: string;
1752
+ changeName?: string;
1753
+ changeAvatar?: string;
1754
+ changeDescription?: string;
1755
+ removed?: string;
1756
+ banned?: string;
1757
+ unbanned?: string;
1758
+ promoted?: string;
1759
+ demoted?: string;
1760
+ permissionsUpdated?: string;
1761
+ joined?: string;
1762
+ declined?: string;
1763
+ left?: string;
1764
+ clearedHistory?: string;
1765
+ changeType?: string;
1766
+ cooldownOn?: string;
1767
+ cooldownOff?: string;
1768
+ bannedWordsUpdated?: string;
1769
+ added?: string;
1770
+ adminTransfer?: string;
1771
+ pinned?: string;
1772
+ unpinned?: string;
1773
+ public?: string;
1774
+ private?: string;
1775
+ userFallback?: string;
1776
+ adminFallback?: string;
1777
+ durationUnitMin?: string;
1778
+ durationUnitSec?: string;
1779
+ }
1780
+ /**
1781
+ * Parse a raw system message string into a human-readable sentence.
1671
1782
  *
1672
1783
  * The raw format is: `"<formatId> <userID> [<param1> <param2> ...]"`
1673
1784
  *
1674
- * @param value - Raw system message string from the server
1675
- * @param userMap - Mapping of user IDs → display names
1676
- * @returns Parsed English text, or the original string if the format is unknown
1785
+ * @param value - Raw system message string from the server
1786
+ * @param userMap - Mapping of user IDs → display names
1787
+ * @param translations - Optional translation templates
1788
+ * @returns Parsed text, or the original string if the format is unknown
1677
1789
  */
1678
- declare function parseSystemMessage(value: string, userMap: Record<string, string>): string;
1790
+ declare function parseSystemMessage(value: string, userMap: Record<string, string>, translations?: SystemMessageTranslations): string;
1679
1791
 
1680
1792
  /**
1681
1793
  * Call type constants for signal messages.
@@ -1695,16 +1807,37 @@ interface SignalMessageResult {
1695
1807
  color: string;
1696
1808
  }
1697
1809
  /**
1698
- * Parse a raw signal message string into a structured object
1699
- * containing text, duration, call type, and color.
1810
+ * Translation templates for signal messages.
1811
+ */
1812
+ interface SignalMessageTranslations {
1813
+ calling?: string;
1814
+ incomingAudioCall?: string;
1815
+ incomingVideoCall?: string;
1816
+ outgoingAudioCall?: string;
1817
+ outgoingVideoCall?: string;
1818
+ missedAudioCall?: string;
1819
+ missedVideoCall?: string;
1820
+ cancelAudioCall?: string;
1821
+ cancelVideoCall?: string;
1822
+ rejectedAudioCallRecipient?: string;
1823
+ rejectedAudioCallYou?: string;
1824
+ rejectedVideoCallRecipient?: string;
1825
+ rejectedVideoCallYou?: string;
1826
+ busyRecipient?: string;
1827
+ durationUnitMin?: string;
1828
+ durationUnitSec?: string;
1829
+ }
1830
+ /**
1831
+ * Parse a raw signal message string into a structured object.
1700
1832
  *
1701
1833
  * Signal messages represent call events. The raw format is:
1702
1834
  * `"<formatId> <callerId> [<enderId> <duration>]"`
1703
1835
  *
1704
- * @param value - Raw signal message string from the server
1705
- * @param myUserId - The current user's ID (from client.userID)
1706
- * @returns Parsed signal message object, or null if input is empty
1836
+ * @param value - Raw signal message string from the server
1837
+ * @param myUserId - The current user's ID
1838
+ * @param translations - Optional translation templates
1839
+ * @returns Parsed signal message object, or null if input is empty
1707
1840
  */
1708
- declare function parseSignalMessage(value: string, myUserId: string): SignalMessageResult | null;
1841
+ declare function parseSignalMessage(value: string, myUserId: string, translations?: SignalMessageTranslations): SignalMessageResult | null;
1709
1842
 
1710
- export { type APIErrorResponse, type APIResponse, type AscDesc, type Attachment, type AttachmentResponse, type AudioConfig, CallAction, type CallEventData, type CallEventType, CallStatus, CallType, type CallTypeValue, Channel, type ChannelAPIResponse, type ChannelData, type ChannelFilters, type ChannelMemberResponse, type ChannelMembership, type ChannelQueryOptions, type ChannelResponse, type ChannelSort, ChannelState, type ChannelStateOptions, ClientState, type ConnectAPIResponse, type ConnectionOpen, type Contact, type ContactResponse, type ContactResult, type CreateTopicData, type DefaultGenerics, EVENT_MAP, type EditMessage, type EditTopicData, ErmisAuthProvider, ErmisCallNode, ErmisChat, type ErmisChatOptions, ErrorFromResponse, type Event$1 as Event, type EventHandler, type EventTypes, type ExtendableGenerics, FRAME_TYPE, type FormatMessageResponse, type ForwardMessage, type IMediaReceiverEvents, type INodeCall, type LiteralStringForUnion, type LogLevel, type Logger, type Message, type MessageBase, type MessageLabel, type MessageResponse, type MessageResponseBase, type MessageSetType, type Metadata, type PollMessage, type QueryChannelAPIResponse, type QueryChannelsAPIResponse, type Reaction, type ReactionAPIResponse, type ReactionResponse, type ReadResponse, type Role, type SendFileAPIResponse, type SendMessageAPIResponse, type SignalData, type SignalMessageResult, StableWSConnection, TokenManager, type TransceiverState, type UR, type UpdateChannelAPIResponse, type UserCallInfo, type UserResponse, type UsersResponse, type VideoConfig, type VoiceRecordingMeta, buildAttachmentPayload, chatCodes, createForwardMessagePayload, formatMessage, getAttachmentCategory, isHeicFile, isVideoFile, logChatPromiseExecution, normalizeFileName, parseSignalMessage, parseSystemMessage };
1843
+ export { type APIErrorResponse, type APIResponse, type AscDesc, type Attachment, type AttachmentResponse, type AudioConfig, CallAction, type CallEventData, type CallEventType, CallStatus, CallType, type CallTypeValue, Channel, type ChannelAPIResponse, type ChannelData, type ChannelFilters, type ChannelMemberResponse, type ChannelMembership, type ChannelQueryOptions, type ChannelResponse, type ChannelSort, ChannelState, type ChannelStateOptions, ClientState, type ConnectAPIResponse, type ConnectionOpen, type Contact, type ContactResponse, type ContactResult, type CreateTopicData, type DefaultGenerics, EVENT_MAP, type EditMessage, type EditTopicData, ErmisAuthProvider, ErmisCallNode, ErmisChat, type ErmisChatOptions, ErrorFromResponse, type Event$1 as Event, type EventHandler, type EventTypes, type ExtendableGenerics, FRAME_TYPE, type FormatMessageResponse, type ForwardMessage, type IMediaReceiverEvents, type INodeCall, type LiteralStringForUnion, type LogLevel, type Logger, type Message, type MessageBase, type MessageDisplayType, type MessageLabel, type MessageResponse, type MessageResponseBase, type MessageSetType, type Metadata, type PollMessage, type QueryChannelAPIResponse, type QueryChannelsAPIResponse, type Reaction, type ReactionAPIResponse, type ReactionResponse, type ReadResponse, type Role, type SendFileAPIResponse, type SendMessageAPIResponse, type SignalData, type SignalMessageResult, type SignalMessageTranslations, StableWSConnection, type SystemMessageTranslations, TokenManager, type TransceiverState, type UR, type UpdateChannelAPIResponse, type UserCallInfo, type UserResponse, type UsersResponse, type VideoConfig, type VoiceRecordingMeta, buildAttachmentPayload, chatCodes, createForwardMessagePayload, formatMessage, getAttachmentCategory, isHeicFile, isVideoFile, logChatPromiseExecution, normalizeFileName, parseSignalMessage, parseSystemMessage };