softchatjs-core
Version:
Javascript client for JS based frameworks
190 lines (184 loc) • 7.26 kB
TypeScript
import { UserMeta, GroupChatMeta, ConversationListItem, Config, ConversationListMeta, Message, Conversation as Conversation$1, Prettify, SendMessageGenerics, EditedMessage, Reaction, ReadMessages, ConversationMap, WsAccessConfig, Screens, ConversationType, ParticipantListInfo, PrivateChatMeta } from './types.js';
import { Emoticon } from './emoticon.type.js';
import WebSocket from 'isomorphic-ws';
import EventEmitter from 'events';
declare class Conversation {
private static conversation;
private connection;
private participants;
private otherParticipant;
private conversationType;
private groupMeta;
constructor(connection: Connection, participantDetails: UserMeta[] | UserMeta, groupMeta: GroupChatMeta | null);
static getInstance(connection: Connection, participantDetails: UserMeta[] | UserMeta, groupMeta: GroupChatMeta | null): Conversation;
private generateConversation;
create(text?: string): ConversationListItem | undefined;
private sendMessage;
reset(): void;
}
type NotificationConfig = {
type: "expo" | "fcm" | "apns" | null;
token: string | null;
};
declare class ChatClient {
private static client_instance;
private connection;
subId: string;
projectId: string;
chatUserId: string;
constructor(subId: string, projectId: string);
static getInstance({ projectId, subId }: Config): ChatClient;
initializeUser(data: UserMeta, config?: {
notificationConfig?: NotificationConfig;
connectionConfig?: {
reset: boolean;
};
}): void;
disconnect(): void;
retryConnection(): void;
getConnectionStatus(): ConnectionState;
subscribe(event: string, func: (event: any) => void): void;
unsubscribe(event: string, func: (event: any) => void): void;
unsubscribeAll(event: string): void;
getConversations(): ConversationListMeta;
getBroadcastLists(): ConversationListMeta;
newConversation(participantDetails: UserMeta[] | UserMeta, groupMeta: GroupChatMeta | null): Conversation;
newBroadcastList(participantDetails: UserMeta[]): BroadcastList;
messageClient(conversationId: string): {
getMessages: (page?: number) => Promise<Message[]>;
getBroadcastListMessages: (page?: number) => Promise<Message[]>;
getConversation: (conversationId: string) => Promise<Conversation$1 | null>;
sendMessage: (newMessage: Prettify<SendMessageGenerics<Message>>) => void;
broadcastMessage: ({ broadcastListId, participantsIds, newMessage }: {
broadcastListId: string;
participantsIds: string[];
newMessage: Prettify<SendMessageGenerics<Message>>;
}) => void;
editMessage: (message: Omit<EditedMessage, "from">) => void;
sendTypingNotification: (uid: string) => void;
sendStoppedTypingNotification: (uid: string) => void;
reactToMessage: ({ conversationId, messageId, reactions, to, }: {
conversationId: string;
messageId: string;
reactions: Reaction[];
to: string;
}) => void;
uploadFile: (uri: string | NodeJS.ReadableStream | Buffer | File, meta: {
filename: string;
mimeType: string;
ext: string;
}) => Promise<{
link: string;
success: boolean;
fileSize: number;
} | {
link: string;
success: boolean;
fileSize: string;
}>;
setActiveConversation: () => Promise<void>;
unSetActiveConversation: () => Promise<void>;
getEmojiList: () => Promise<Emoticon[]>;
deleteMessage: (messageId: string, to: string, conversationId: string) => void;
readMessages: (conversationId: string, data: ReadMessages) => void;
};
}
declare const connectionStates: {
readonly NO_CONNECTION: {
readonly connecting: false;
readonly isConnected: false;
readonly fetchingConversations: false;
};
readonly GETTING_CONVERSATIONS: {
readonly connecting: true;
readonly isConnected: false;
readonly fetchingConversations: true;
};
readonly SOCKET_CONNECTING: {
readonly connecting: true;
readonly isConnected: false;
readonly fetchingConversations: false;
};
readonly SOCKET_CONNECTED: {
readonly connecting: false;
readonly isConnected: true;
readonly fetchingConversations: false;
};
};
type ConnectionState = typeof connectionStates[keyof typeof connectionStates];
declare class Connection extends EventEmitter {
private static connection;
connecting: boolean;
socket: WebSocket | null;
conversations: Array<Conversation$1>;
conversationMap: ConversationMap;
wsAccessConfig: WsAccessConfig;
retry_delay_ms: number;
max_retry_count: number;
health_check_interval: number;
retry_count: number;
userMeta: UserMeta;
projectConfig: Config;
activeConversationId: string;
screen: Screens;
broadcastListMeta: ConversationListMeta;
conversationListMeta: ConversationListMeta;
private healthCheckRef;
private retryRef;
shouldReconnect: boolean;
connectionState: ConnectionState;
notificationConfig: NotificationConfig;
constructor(client_instance: ChatClient);
static getInstance(client_instance: ChatClient): Connection;
updateConnectionState(state: ConnectionState): void;
private _getConversations;
private _getBroadcastLists;
_initiateConnection(user: UserMeta, config?: {
notificationConfig?: NotificationConfig;
connectionConfig?: {
reset: boolean;
};
}): Promise<null | undefined>;
private sortMesssages;
private sortConversationMessages;
private _getUreadMessageIds;
_wsDisconnect(config?: {
shouldReconnect: boolean;
}): void;
private startHealthCheck;
private retryConnection;
private setupEventHandlers;
}
declare class BroadcastList {
private static conversation;
private connection;
private participants;
constructor(connection: Connection, participants: UserMeta[]);
static getInstance(connection: Connection, participants: UserMeta[]): BroadcastList;
private generateConversation;
create(name?: string): {
[x: string]: {
conversation: {
participants: string[];
admins: string[];
conversationId: string;
messages: Message[];
conversationType: ConversationType;
participantList: ParticipantListInfo[];
meta: PrivateChatMeta | null;
groupMeta: GroupChatMeta | null;
name?: string;
} & {
createdAt: string | Date;
updatedAt: string | Date;
deletedAt?: string | Date;
} & {
name: string;
};
lastMessage: null;
unread: never[];
};
} | undefined;
reset(): void;
}
export { BroadcastList as B, ChatClient as C, type NotificationConfig as N, Connection as a, Conversation as b, connectionStates as c, type ConnectionState as d };