@only-chat/client
Version:
Client for only-chat
84 lines (83 loc) • 2.56 kB
TypeScript
import type { UserStore } from '@only-chat/types/userStore.js';
import type { MessageStore } from '@only-chat/types/store.js';
import type { Log } from '@only-chat/types/log.js';
import type { Message as QueueMessage, MessageQueue } from '@only-chat/types/queue.js';
import type { Transport } from '@only-chat/types/transport.js';
export declare enum TransportState {
/** The connection is not yet open. */
CONNECTING = 0,
/** The connection is open and ready to communicate. */
OPEN = 1,
/** The connection is in the process of closing. */
CLOSING = 2,
/** The connection is closed. */
CLOSED = 3
}
export interface Config {
queue?: MessageQueue;
store: MessageStore;
userStore: UserStore;
instanceId: string;
}
export interface LoadRequest {
from?: number;
size?: number;
ids?: string[];
excludeIds?: string[];
before?: Date;
}
interface ConversationInfo {
participants: Set<string>;
clients: WsClient[];
}
export declare enum WsClientState {
None = 0,
Authenticated = 1,
Connected = 2,
Session = 3,
WatchSession = 4,
Disconnected = 255
}
export declare class WsClient {
static readonly connectedClients: Set<string>;
static readonly watchers: Map<string, WsClient>;
static readonly conversations: Map<string, ConversationInfo>;
static readonly joinedParticipants: Map<string, Set<string>>;
private static readonly conversationsCache;
connectionId?: string;
id?: string;
state: WsClientState;
private readonly transport;
private conversation?;
private lastError?;
constructor(t: Transport);
private static addClient;
private static removeClient;
private static addWatchClient;
private static removeWatchClient;
private static publishToWatchList;
private static getConversationParticipants;
private static publishToWsList;
private static syncConversation;
static translateQueueMessage(qm: QueueMessage): Promise<void>;
private publishMessage;
private send;
private stop;
private watch;
private join;
private onMessage;
private onClose;
private deleteMessage;
private updateMessage;
private updateConversation;
private closeDeleteConversation;
private processRequest;
private processConversationRequest;
private connect;
private getConversations;
private findMessages;
private loadMessages;
private loadConversations;
}
export declare function initialize(config: Config, log?: Log): void;
export {};