import BaseClientWithStore, { BaseClientWithStoreOptions } from './base-with-store'; import ApplozicSocket from './socket'; import LoginResult from './models/LoginResult'; import { SocketEventListener } from './socket/socket-events'; export interface ApplozicClientOptions extends BaseClientWithStoreOptions { useSocket?: boolean; events?: SocketEventListener; } /** * This is the main class for interacting with the Applozic API. * This class incorporates the [BaseClientWithStore](./base-with-store.ts) class * * Sample usage: * * ```TypeScript * import ApplozicClient from '@applozic/core-sdk'; * * const applozicClient = new ApplozicClient('YOUR-APPLOZIC-APP-ID', { * events: { * onMessageReceived: ({ message }) => { * console.log('onMessageReceived', { message }); * }, * onMessageDelivered: (contactId, messageKey) => { * console.log('onMessageDelivered', { message }); * }, * onMessageRead: (contactId, messageKey) => { * console.log('onMessageRead', { contactId, messageKey }); * }, * onMessageSent: ({ message }) => { * console.log('onMessageSent', { message }); * }, * onMessageDeleted: (contactId, messageKey) => { * console.log('onMessageDeleted', { contactId, messageKey }); * }, * onConversationRead: userId => { * console.log('onConversationRead', { userId }); * }, * onConversationDeleted: contactId => { * console.log('onConversationDeleted', { contactId }); * }, * onUserActivated: message => { * console.log('onUserActivated', { onUserActivated: message }); * }, * onUserConnect: message => { * console.log('onUserConnect', { userConnected: message }); * }, * onUserOnlineStatus: (userId, isOnline, timestamp) => { * console.log('onUserOnlineStatus', { userId, isOnline, timestamp}); * }, * onTypingStatus: (userId, status) => { * console.log('onTypingStatus', { userId, status}); * } * } * }); * ``` * * ## HTML * * ```html * * * * Development * * * * * * *

My First Heading

*

My first paragraph.

* * * ``` * * ## Available APIs * * - {@link ContactsApi} * - {@link FilesApi} * - {@link GroupsApi} * - {@link MessagesApi} * - sendTypingStatus - {@link ApplozicClient.sendTypingStatus} */ export default class ApplozicClient extends BaseClientWithStore { /** Internal Applozic Socket manager */ applozicSocket: ApplozicSocket | undefined; /** Event handlers like on message sent etc */ private events; /** Use sockets or not, default is true */ private useSocket; /** * Create a new ApplozicClient instance * @param applicationId Applozic application id * @param options Client options */ constructor(applicationId: string, options?: ApplozicClientOptions); postLogin(loginRes: LoginResult): Promise; /** * Check if user was logged in previously and restart the socket connection * if user is logged in * * Sample usage: * * ```TypeScript * const login = async (userId, password) => { * await applozicClient.init(); * let loginResult = applozicClient.loginResult; * if (!loginResult) { * loginResult = await applozicClient.login(userId, password); * } * } * * await login(userId, password) * ``` * * @param userId User ID * @param password Password for the user */ init(): Promise; /** * Login to the Applozic SDK * Logs out previous user if any logged in already * * Sample usage: * * ```TypeScript * await applozicClient.login('user-id', 'password'); * ``` * For client initialization, see {@link ApplozicClient.init} * * @param userId User ID * @param password Password for the user */ login(userId: string, password: string): Promise; /** * Log out current user * * Sample usage: * * ```TypeScript * await applozicClient.logout(); * ``` */ logout(): Promise; /** * Send typing status to a particular user * * Sample usage: * * ```typescript * applozicClient.sendTypingStatus('contact-id', true); * ``` * * @param userId User ID of the user to send typing status to * @param isTyping True if the user is typing, false otherwise */ sendTypingStatus: (userId: string, isTyping: boolean) => void; private subscribeToTypingStatus; /** * Add a new event listener * * Sample usage: * * ```typescript * applozicClient.addEventListener({ * onMessageReceived: ({ message }) => { * console.log('onMessageReceived 2', { message }); * }, * onMessageSent: ({ message }) => { * console.log('onMessageSent 2', { message }); * }, * }); * ``` * @param handler Event listener */ addEventListener: (handler: SocketEventListener) => void; removeEventListener: (handler: SocketEventListener) => void; }