Merge pull request #595 from ShayBox/patch-1

Updated typings
This commit is contained in:
Romain Beaumont 2018-10-04 13:18:38 +02:00 committed by GitHub
commit ed25865f21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

203
src/index.d.ts vendored
View File

@ -1,113 +1,117 @@
import {Socket} from 'net' import { EventEmitter } from 'events';
import { Socket } from 'net'
import * as Stream from 'stream' import * as Stream from 'stream'
import EventEmitter = NodeJS.EventEmitter import { on } from 'cluster';
declare enum EnumStates { declare module 'minecraft-protocol' {
HANDSHAKING = 'handshaking', export class Client extends EventEmitter {
STATUS = 'status',
LOGIN = 'login',
PLAY = 'play',
}
export interface IPacketMeta {
name: string
state: EnumStates
}
export declare class Client extends EventEmitter {
constructor(isServer: boolean, version: string, customPackets?: any) constructor(isServer: boolean, version: string, customPackets?: any)
write(name: string, params: any)
end(reason: string)
state: EnumStates
isServer: boolean isServer: boolean
socket: Socket
uuid: string
username: string
session: any
profile: any
latency: number latency: number
on(event: 'packet', handler: (data: any, packetMeta: IPacketMeta) => any) profile: any
on(event: 'raw', handler: (data: any, packetMeta: IPacketMeta) => any) session: any
on(event: 'state', handler: (newState: EnumStates, oldState: EnumStates) => any) socket: Socket
on(event: 'session', handler: (session: any) => any) state: States
writeChannel(channel: any, params: any) username: string
registerChannel(name: string, typeDefinition: any, custom?: boolean) uuid: string
unregisterChannel(name: string) end(reason: string): void
} registerChannel(name: string, typeDefinition: any, custom?: boolean): void
unregisterChannel(name: string): void
write(name: string, params: any): void
writeChannel(channel: any, params: any): void
on(event: 'error', listener: (error: Error) => void): this
on(event: 'packet', handler: (data: any, packetMeta: PacketMeta) => void): this
on(event: 'raw', handler: (data: any, packetMeta: PacketMeta) => void): this
on(event: 'session', handler: (session: any) => void): this
on(event: 'state', handler: (newState: States, oldState: States) => void): this
}
interface IClientsMap { export interface ClientOptions {
[key: string]: Client accessToken?: string
} checkTimeoutInterval?: number
clientToken?: string
customPackets?: any
hideErrors?: boolean
host?: string
keepAlive?: boolean
password?: string
port?: number
username: string
version?: string
}
export declare class Server extends EventEmitter { export class Server extends EventEmitter {
constructor(version: string, customPackets?: any) constructor(version: string, customPackets?: any)
onlineModeExceptions: object clients: ClientsMap
clients: IClientsMap favicon: string
playerCount: number
maxPlayers: number maxPlayers: number
motd: string motd: string
favicon: string onlineModeExceptions: object
on(event: 'connection', handler: (client: Client) => any) playerCount: number
on(event: 'login', handler: (client: Client) => any) on(event: 'connection', handler: (client: Client) => void): this
} on(event: 'error', listener: (error: Error) => void): this
on(event: 'login', handler: (client: Client) => void): this
}
export interface ICreateServerOptions { export interface ServerOptions {
host?: string
port?: number
kickTimeout?: number
checkTimeoutInterval?: number
'online-mode'?: boolean 'online-mode'?: boolean
motd?: string
maxPlayers?: number
keepAlive?: boolean
version?: string
customPackets?: any
stream?: Stream
beforePing?: (response: any, client: Client, callback?: (result: any) => any) => any
errorHandler?: (client: Client, error: Error) => any
connect?: (client: Client) => any
hideErrors?: boolean
}
export interface ICreateClientOptions {
username: string
port?: number
password?: string
host?: string
clientToken?: string
accessToken?: string
keepAlive?: boolean
checkTimeoutInterval?: number checkTimeoutInterval?: number
version?: string
customPackets?: any customPackets?: any
hideErrors?: boolean hideErrors?: boolean
}
export interface ICreateSerializerOptions {
state?: EnumStates
isServer?: boolean
version: string
customPackets: any
}
export interface IPingOptions {
host?: string host?: string
keepAlive?: boolean
kickTimeout?: number
maxPlayers?: number
motd?: string
port?: number port?: number
stream?: Stream
version?: string version?: string
majorVersion?: string beforePing?: (response: any, client: Client, callback?: (result: any) => any) => any
protocolVersion?: string connect?: (client: Client) => void
} errorHandler?: (client: Client, error: Error) => void
}
export interface IPingOldResult { export interface SerializerOptions {
customPackets: any
isServer?: boolean
state?: States
version: string
}
enum States {
HANDSHAKING = 'handshaking',
LOGIN = 'login',
PLAY = 'play',
STATUS = 'status',
}
export interface PacketMeta {
name: string
state: States
}
interface ClientsMap {
[key: string]: Client
}
export interface PingOptions {
host?: string
majorVersion?: string
port?: number
protocolVersion?: string
version?: string
}
export interface OldPingResult {
maxPlayers: number,
motd: string
playerCount: number
prefix: string prefix: string
protocol: string protocol: string
version: string version: string
motd: string }
playerCount: number
maxPlayers: number,
}
export interface IPingNewResult { export interface NewPingResult {
description: string description: string
players: { players: {
max: number max: number
@ -123,16 +127,17 @@ export interface IPingNewResult {
} }
favicon: string favicon: string
latency: number latency: number
}
export const state: States
export const supportedVersions: ['1.7', '1.8', '1.9', '1.10', '1.11.2', '1.12.2', '1.13.1']
export function createServer(options: ServerOptions): Server
export function createClient(options: ClientOptions): Client
// TODO: Create typings on protodef to define here
export function createSerializer({ state, isServer, version, customPackets }: SerializerOptions): any
export function createDeserializer({ state, isServer, version, customPackets }: SerializerOptions): any
export function ping(options: PingOptions, callback: (error: Error, result: OldPingResult | NewPingResult) => void): void
} }
export declare function createServer(options: ICreateServerOptions): Server
export declare function createClient(options: ICreateClientOptions): Client
export const state: EnumStates
export declare function createSerializer({state, isServer, version, customPackets}: ICreateSerializerOptions)
export declare function createDeserializer({state, isServer, version, customPackets}: ICreateSerializerOptions)
export declare function ping(options: IPingOptions, callback: (err: Error, result: IPingOldResult | IPingNewResult) => any);
export const supportedVersions: string[]