import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; import { StableWSConnection } from './connection'; import { TokenManager } from './token_manager'; import { AllClientEvents, AllClientEventTypes, ClientEventListener, ConnectAPIResponse, StreamClientOptions, StreamVideoEvent, TokenOrProvider, User, UserWithId } from './types'; import { ConnectedEvent, CreateGuestResponse } from '../../gen/coordinator'; import { ScopedLogger } from '../../logger'; export declare class StreamClient { _user?: UserWithId; anonymous: boolean; persistUserOnConnectionFailure?: boolean; axiosInstance: AxiosInstance; baseURL?: string; browser: boolean; clientID?: string; key: string; listeners: Partial[] | undefined>>; logger: ScopedLogger; private locationHint; node: boolean; options: StreamClientOptions; secret?: string; connectUserTask: ConnectAPIResponse | null; tokenManager: TokenManager; user?: UserWithId; private cachedUserAgent?; userID?: string; wsBaseURL?: string; wsConnection: StableWSConnection | null; private wsPromiseSafe; consecutiveFailures: number; defaultWSTimeout: number; resolveConnectionId?: Function; rejectConnectionId?: Function; private connectionIdPromiseSafe?; guestUserCreatePromise?: Promise; /** * Initialize a client. * * @param {string} key - the api key * @param {StreamClientOptions} [options] - additional options, here you can pass custom options to axios instance * @param {string} [options.secret] - the api secret * @param {boolean} [options.browser] - enforce the client to be in browser mode * @param {boolean} [options.warmUp] - default to false, if true, client will open a connection as soon as possible to speed up following requests * @param {Logger} [options.Logger] - custom logger * @param {number} [options.timeout] - default to 3000 * @param {httpsAgent} [options.httpsAgent] - custom httpsAgent, in node it's default to https.agent() */ constructor(key: string, options?: StreamClientOptions); getAuthType: () => "anonymous" | "jwt"; setBaseURL: (baseURL: string) => void; getLocationHint: (hintUrl?: string, timeout?: number) => Promise; _getConnectionID: () => string | undefined; _hasConnectionID: () => boolean; /** * connectUser - Set the current user and open a WebSocket connection * * @param user Data about this user. IE {name: "john"} * @param {TokenOrProvider} tokenOrProvider Token or provider * * @return {ConnectAPIResponse} Returns a promise that resolves when the connection is setup */ connectUser: (user: UserWithId, tokenOrProvider: TokenOrProvider) => ConnectAPIResponse; _setUser: (user: UserWithId) => void; /** * Disconnects the websocket connection, without removing the user set on client. * client.closeConnection will not trigger default auto-retry mechanism for reconnection. You need * to call client.openConnection to reconnect to websocket. * * This is mainly useful on mobile side. You can only receive push notifications * if you don't have active websocket connection. * So when your app goes to background, you can call `client.closeConnection`. * And when app comes back to foreground, call `client.openConnection`. * * @param timeout Max number of ms, to wait for close event of websocket, before forcefully assuming succesful disconnection. * https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent */ closeConnection: (timeout?: number) => Promise; /** * Creates a new WebSocket connection with the current user. Returns empty promise, if there is an active connection */ openConnection: () => Promise; /** * Disconnects the websocket and removes the user from client. * * @param timeout Max number of ms, to wait for close event of websocket, before forcefully assuming successful disconnection. * https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent */ disconnectUser: (timeout?: number) => Promise; connectGuestUser: (user: User & { type: "guest"; }) => Promise; /** * connectAnonymousUser - Set an anonymous user and open a WebSocket connection */ connectAnonymousUser: (user: UserWithId, tokenOrProvider: TokenOrProvider) => Promise; /** * on - Listen to events on all channels and users your watching * * client.on('message.new', event => {console.log("my new message", event, channel.state.messages)}) * * @param eventName The event type to listen for (optional) * @param callback The callback to call * * @return Returns a function which, when called, unsubscribes the event handler. */ on: (eventName: E, callback: ClientEventListener) => () => void; /** * off - Remove the event handler */ off: (eventName: E, callback: ClientEventListener) => void; /** * sets up the this.connectionIdPromise */ _setupConnectionIdPromise: () => void; get connectionIdPromise(): Promise | undefined; get isConnectionIsPromisePending(): boolean; get wsPromise(): Promise | undefined; _logApiRequest: (type: string, url: string, data: unknown, config: AxiosRequestConfig & { config?: AxiosRequestConfig & { maxBodyLength?: number; }; }) => void; _logApiResponse: (type: string, url: string, response: AxiosResponse) => void; doAxiosRequest: (type: string, url: string, data?: D, options?: AxiosRequestConfig & { config?: AxiosRequestConfig & { maxBodyLength?: number; }; publicEndpoint?: boolean; }) => Promise; get: (url: string, params?: AxiosRequestConfig["params"]) => Promise; put: (url: string, data?: D, params?: AxiosRequestConfig["params"]) => Promise; post: (url: string, data?: D, params?: AxiosRequestConfig["params"]) => Promise; patch: (url: string, data?: D, params?: AxiosRequestConfig["params"]) => Promise; delete: (url: string, params?: AxiosRequestConfig["params"]) => Promise; dispatchEvent: (event: StreamVideoEvent) => void; /** * @private */ connect: () => Promise; getUserAgent: () => string; _enrichAxiosOptions: (options?: AxiosRequestConfig & { config?: AxiosRequestConfig; } & { publicEndpoint?: boolean; }) => AxiosRequestConfig; _getToken: () => string | null | undefined; updateNetworkConnectionStatus: (event: { type: "online" | "offline"; } | Event) => void; }