///
import { LocationSubscribeFunctionType } from "../location";
export declare type SocketOptions = {
url: string;
onError?: (error: Error) => void;
token?: string;
};
export declare type SocketStateType = {
connecting: boolean;
connected: boolean;
error: string;
data: T;
};
declare type SubscribeFunctionType = (state: SocketStateType, socket: BaseSocket) => void;
declare type StateUpdateFunctionType = (prevState: SocketStateType) => Partial>;
declare type SetStateType = (nextState: Partial> | StateUpdateFunctionType) => void;
declare class BaseSocket {
requestFrom: string;
url: string;
token?: string;
socket?: SocketIOClient.Socket;
onError?: (error: Error) => void;
state: SocketStateType;
_listeners: Map>;
_subscribers: Set>;
_unsubscribeLocation?: () => void;
constructor({ requestFrom, ...opts }: SocketOptions & {
requestFrom: string;
});
update: ({ url, onError, token }: SocketOptions) => void;
on: (event: string, listener: Function) => () => void;
emit: (event: string, ...args: any[]) => SocketIOClient.Socket;
removeListener: (event: string, listener: Function) => void;
connect: () => void;
onLocationUpdate: LocationSubscribeFunctionType;
disconnect: () => void;
setState: SetStateType;
subscribe: (subscriber: SubscribeFunctionType) => () => void;
throw: (message: string) => never;
}
export default BaseSocket;