UNPKG

ps2census

Version:

Client to connect to the PS2 Event Stream websocket.

118 lines (117 loc) 4.53 kB
import { EventEmitter } from 'eventemitter3'; import { StreamManagerOptions } from './stream.manager'; import { PS2Environment } from '../types/ps2.options'; import { RestClient, RestClientOptions } from '../rest/rest.client'; import { CharacterManager, CharacterManagerOptions } from './managers'; import { AchievementEarned, BattleRankUp, ContinentLock, Death, FacilityControl, GainExperience, ItemAdded, MetagameEvent, PlayerFacilityCapture, PlayerFacilityDefend, PlayerLogin, PlayerLogout, PS2Event, SkillAdded, VehicleDestroy } from './events'; import { EventSubscribed, EventSubscription } from './types'; import { FishScan } from './events/fish-scan.event'; export interface ClientOptions { streamManager?: StreamManagerOptions; rest?: Omit<RestClientOptions, 'serviceId'>; characterManager?: CharacterManagerOptions; } export type ClientEvents = { ready: () => void; disconnected: (code?: number, reason?: string) => void; reconnecting: () => void; error: (err: Error) => void; warn: (err: Error) => void; debug: (info: string) => void; duplicate: (event: PS2Event<any>) => void; subscribed: (subscription: EventSubscribed) => void; serviceState: (worldId: string, online: boolean, detail: string) => void; ps2Event: (event: PS2Event<any>) => void; achievementEarned: (event: AchievementEarned) => void; battleRankUp: (event: BattleRankUp) => void; death: (event: Death) => void; fishScan: (event: FishScan) => void; gainExperience: (event: GainExperience) => void; itemAdded: (event: ItemAdded) => void; playerFacilityCapture: (event: PlayerFacilityCapture) => void; playerFacilityDefend: (event: PlayerFacilityDefend) => void; playerLogin: (event: PlayerLogin) => void; playerLogout: (event: PlayerLogout) => void; skillAdded: (event: SkillAdded) => void; vehicleDestroy: (event: VehicleDestroy) => void; continentLock: (event: ContinentLock) => void; facilityControl: (event: FacilityControl) => void; metagameEvent: (event: MetagameEvent) => void; }; export declare class CensusClient extends EventEmitter<ClientEvents> { readonly serviceId: string; readonly environment: PS2Environment; /** * @type{StreamManager?} the event stream manager */ private readonly streamManager; /** * @type {RestClient} Client to fetch data from the Rest API */ readonly rest: RestClient; /** * @type {CharacterManager} The character manager for Census API requests */ readonly characterManager: CharacterManager; /** * @param {string} serviceId service Id for the Census API * @param {PS2Environment} environment the environment the client is configured for * @param {ClientOptions} config */ constructor(serviceId: string, environment: PS2Environment, { streamManager, rest, characterManager }?: ClientOptions); /** * Start watching the event stream * * @return {Promise<void>} */ watch(): Promise<void>; /** * Doom and destruction, WUHAHAHAHA! */ destroy(): void; /** * Make a subscription to the stream * * @param {EventSubscription} subscription * @return {Promise<EventSubscribed | null>} */ subscribe(subscription: EventSubscription): Promise<EventSubscribed | null>; /** * Remove a subscription from the stream * * @param {EventSubscription} subscription * @return {Promise<EventSubscribed | null>} */ unsubscribe(subscription: EventSubscription): Promise<EventSubscribed | null>; /** * Purge all subscriptions * * @return {Promise<void>} */ unsubscribeAll(): Promise<void>; /** * Rerun all subscriptions * * @param {boolean} reset When true unsubscribes to all events first * @return {Promise<boolean>} whether it has been run(depends on stream being ready) */ resubscribe(reset?: boolean): Promise<boolean>; /** * Verifies if the subscription matches with what is expected * * @return {Promise<boolean>} whether the subscription is correct */ verifySubscription(): Promise<boolean>; /** * Get all the recent character ids * * @return {Promise<string[]>} the list of character ids */ recentCharacters(): Promise<string[]>; /** * Get the number of recent characters * * @return {Promise<number>} the number of recent characters */ recentCharacterCount(): Promise<number>; }