UNPKG

node-insim

Version:

An InSim library for NodeJS with TypeScript support

54 lines (53 loc) 2.36 kB
import { TypedEmitter } from 'tiny-typed-emitter'; import type { InSimEvents } from './InSimEvents'; import type { IS_ISI_Data, SendablePacket } from './packets'; import { MessageSound, packetTypeToClass } from './packets'; import type { InSimPacketClassInstance } from './packets/types'; type InSimConnectionOptions = { Host: string; Port: number; Protocol?: 'TCP' | 'UDP'; }; export type InSimOptions = Omit<IS_ISI_Data, 'InSimVer'> & InSimConnectionOptions; export declare class InSim extends TypedEmitter<InSimEvents> { /** Currently supported InSim version */ static INSIM_VERSION: number; private static COMMAND_PREFIX; /** A unique identifier of the InSim connection to a specific host */ id: string; private _options; /** The main connection to InSim (TCP or UDP) */ private connection; private sizeMultiplier; constructor(id?: string); /** * Connect to a server via InSim. */ connect: (options: Omit<Partial<IS_ISI_Data>, "InSimVer"> & InSimConnectionOptions) => void; disconnect: () => void; send: (packet: SendablePacket) => void; get options(): InSimOptions; /** * Send a message or command to LFS * * If the message starts with a slash (`/`), it will be treated as a command. * Otherwise, it will be treated as a message. * * The maximum length of the message is {@link MSX_MSG_MAX_LENGTH} characters. */ sendMessage: (message: string) => void; /** * Send a message which will appear on the local computer only. * * The maximum length of the message is {@link MSL_MSG_MAX_LENGTH} characters. */ sendLocalMessage: (message: string, sound?: MessageSound) => void; /** Send a message to a specific connection */ sendMessageToConnection: (ucid: number, message: string, sound?: MessageSound) => void; /** Send a message to a specific player */ sendMessageToPlayer: (plid: number, message: string, sound?: MessageSound) => void; sendAwait: <TPacketTypeToAwait extends keyof typeof packetTypeToClass>(packet: SendablePacket, packetTypeToAwait: TPacketTypeToAwait, filterPacketData?: (packet: InSimPacketClassInstance<TPacketTypeToAwait>) => boolean) => Promise<InSimPacketClassInstance<TPacketTypeToAwait>>; private handlePacket; private handleKeepAlive; } export {};