import { ChatRoomListenerMap } from './events.js'; import { ChatLogger, ChatLogLevel } from './logging.js'; import { DeleteMessageRequest } from './requests/DeleteMessageRequest.js'; import { DisconnectUserRequest } from './requests/DisconnectUserRequest.js'; import { SendMessageRequest } from './requests/SendMessageRequest.js'; import { ChatMessage, ChatTokenProvider, ConnectionState, DeleteMessageEvent, DisconnectUserEvent } from './types.js'; /** Configuration options accepted by {@link ChatRoom} constructor. */ export interface ChatRoomConfig { /** AWS region name (e.g. `us-west-2`) or WebSocket URL starting with `wss://` or `ws://`. */ regionOrUrl: string; /** Callback method called when {@link ChatRoom} requires a fresh IVS chat token. */ tokenProvider: ChatTokenProvider; /** Number of times the room will automatically retry WebSocket connection in case of connection failures. */ maxReconnectAttempts?: number; /** * Local room identifier, defaults to randomly generated UUID string. * * @remarks * The parameter is useful in case you want to differentiate between various room instances, e.g. for logging * purposes, when you have more than one {@link ChatRoom | room} connection at the same time. */ id?: string; } /** * Represents IVS chat room connection. * * This is a high-level object representing connection to the IVS Chat room. It is responsible for managing chat * connection, sending chat requests and receiving chat events. */ export declare class ChatRoom { private _state; private socketUrl; private tokenProvider; private currentConnection; private nextConnection; private eventEmitter; private disconnectReason; private pendingRequests; private nextConnectionScheduleHandle; private receivedEntityIds; /** * Local room identifier, defaults to randomly generated UUID string. * * @remarks * The parameter is useful in case you want to differentiate between various room instances, e.g. for logging * purposes, when you have more than one {@link ChatRoom | room} connection at the same time. */ id: string; /** * Number of times the {@link ChatRoom | room} will automatically retry WebSocket connection in case of connection * failures. */ maxReconnectAttempts: number; /** {@link ChatLogger | Logger } used by the {@link ChatRoom | room}. Defaults to {@link ConsoleLogger }. */ logger: ChatLogger; /** * Minimal log severity {@link ChatLogLevel | level } for messages to be logged to {@link ChatRoom#logger | logger}. * * Defaults to {@link ChatLogLevel | `debug` }. */ logLevel: ChatLogLevel; /** * Constructs a new {@link ChatRoom} instance. * * @param config - {@link ChatRoomConfig | Constructor configuration object} */ constructor({ regionOrUrl, tokenProvider, maxReconnectAttempts, id }: ChatRoomConfig); /** Returns the {@link ConnectionState | connection state} of the {@link ChatRoom | room}. */ get state(): ConnectionState; private set state(value); /** * Sets up a function that will be called whenever the {@link ChatRoomListenerMap | specified event} is delivered. * * @typeParam EventName - One of supported {@link ChatRoomListenerMap | event types} * @param eventName - Name of the {@link ChatRoomListenerMap | event} * @param listener - Function called whenever the {@link ChatRoomListenerMap | specified event} is delivered * @returns A function that removes the event listener */ addListener(eventName: EventName, listener: ChatRoomListenerMap[EventName]): () => void; /** * Removes the event listener for the {@link ChatRoomListenerMap | specified event}. * * @typeParam Event - One of supported {@link ChatRoomListenerMap | event types}. */ removeListener(eventName: EventName, listener: ChatRoomListenerMap[EventName]): void; private dispatchEvent; /** * Initiates the process of connecting to the socket, using {@link ChatTokenProvider | token provider} passed to * constructor. In case of failure, it will try to reconnect the number of times specified in * {@link ChatRoom#maxReconnectAttempts }, defaulting to 3 attempts. */ connect(): void; /** * Initiates a graceful disconnection of the Web Socket. Results in calling the * {@link ChatRoomListenerMap | `disconnect` event} with `disconnectReason` parameter set to * {@link DisconnectReason | `'clientDisconnect'` }. */ disconnect(): void; private clearConnection; private disposeAllConnections; /** * Sends a {@link SendMessageRequest | message request } to the {@link ChatRoom | room} to the room. * * @param request - Contains a message and related metadata to be sent * @returns Promise that resolves to a {@link ChatMessage} or rejects with a {@link ChatError} * @throws {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error | Error} * Thrown if the request cannot be serialized. * @throws {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error | Error} * Thrown if the {@link ChatRoom | room} is not connected. * @throws {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error | Error} * Thrown if a request with the same {@link SendMessageRequest#requestId} is already submitted. */ sendMessage(request: SendMessageRequest): Promise; /** * Sends a {@link DeleteMessageRequest | delete message request } to the room. * * @param request - Identifies a message to be deleted along with an optional reason for deletion. * @returns Promise that resolves to a {@link DeleteMessageEvent} or rejects with a {@link ChatError} * @throws {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error | Error} * Thrown if the request cannot be serialized. * @throws {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error | Error} * Thrown if the {@link ChatRoom | room} is not connected. * @throws {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error | Error} * Thrown if a request with the same {@link DeleteMessageRequest#requestId} is already submitted. */ deleteMessage(request: DeleteMessageRequest): Promise; /** * Sends a {@link DisconnectUserRequest | disconnect user request } to the room. * * @param request - Identifies the user to be disconnected along with an optional reason for disconnection. * @returns Promise that resolves to a {@link DisconnectUserEvent | disconnect user event} or rejects with a * {@link ChatError | chat error} * @throws {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error | Error} * Throws if the request cannot be serialized. * @throws {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error | Error} * Throws if the {@link ChatRoom | room} is not connected. * @throws {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error | Error} * Thrown if a request with the same {@link DisconnectUserRequest#requestId} is already submitted. */ disconnectUser(request: DisconnectUserRequest): Promise; private onOpen; private onClose; private onMessage; private scheduleReconnect; private createConnection; private reconnect; private receiveMessageJson; private receiveEventJson; private handleDeleteMessageEvent; private handleDisconnectUserEvent; private receiveErrorJson; private logDebug; private logInfo; private logError; } //# sourceMappingURL=ChatRoom.d.ts.map