UNPKG

@runejs/common

Version:

Common logging, networking, compression, and other miscellaneous functionality for RuneJS.

37 lines (36 loc) 1.54 kB
/// <reference types="node" /> import { Server, Socket } from 'net'; import { ByteBuffer } from '../buffer'; import { ConnectionStatus } from './connection-status'; export declare class SocketServerOptions { handshakeRequired: boolean; noDelay: boolean; keepAlive: boolean; timeout: number; constructor(props?: Partial<SocketServerOptions>); } export declare abstract class SocketServer<T = undefined> { readonly socket: Socket; readonly options: SocketServerOptions; protected _connectionStatus: ConnectionStatus | T; constructor(socket: Socket); constructor(socket: Socket, options: Partial<SocketServerOptions>); constructor(socket: Socket, options: SocketServerOptions); constructor(socket: Socket, options: Partial<SocketServerOptions> | SocketServerOptions | undefined); static launch<T extends SocketServer<any>>(serverName: string, hostName: string, port: number, socketServerFactory: (socket: Socket) => T): Server; dataReceived(data: Buffer): void; closeConnection(): void; error(error: Error): void; error(error: { message?: string; }): void; error(error: string): void; error(error: any | Error | { message?: string; } | string): void; abstract initialHandshake(data: ByteBuffer): boolean; abstract decodeMessage(data: ByteBuffer): void | Promise<void>; abstract connectionDestroyed(): void; get connectionStatus(): ConnectionStatus | T; get connectionAlive(): boolean; }