-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
64 lines (62 loc) · 1.91 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/// <reference types="node" />
export interface ServerOptions {
localhostOnly?: boolean;
clientRejectionMessage?: string;
logActivity?: boolean;
ipStack?: 4 | 6;
encoding?: string;
}
export declare class Server {
constructor(port: number, options?: ServerOptions);
acceptAny(callback: (data: string) => string | object): Server;
accept(directive: string, callback: () => string | object): Server;
onStart(callback: () => void): Server;
onClientRejected(callback: (port?: number, host?: string) => void): Server;
onClientConnected(callback: (port?: number, host?: string) => void): Server;
onClientClosed(callback: (port?: number, host?: string) => void): Server;
onStop(callback: () => void): Server;
start(): void;
}
export interface ClientOptions {
logActivity?: boolean;
ipStack?: 4 | 6;
outboundEncoding?: string;
inboundEncoding?: string;
}
export declare class Client {
readonly port: number;
readonly options: ClientOptions;
constructor(port: number, options?: ClientOptions);
onConnect(callback: (err?: Error) => void): Client;
onDestroy(callback: () => void): Client;
destroy(): void
request(payload: string | object): Promise<SocketResponse>;
requestString(payload: string | object): Promise<string>;
requestJson(payload: string | object): Promise<object>;
}
declare class SocketResponse {
private buffer;
constructor(buffer: StreamBuffer);
toString(): string;
toJson(): object;
}
declare class StreamBuffer {
private encoding;
private bufferString;
constructor(encoding: string);
append(buffer: Buffer): void;
toString(): string;
}
export interface ProvidedLogger {
debug(...args: any[]): void
info(...args: any[]): void
warn(...args: any[]): void
error(...args: any[]): void
}
export declare class Log {
setLogger(logger: ProvidedLogger): void
debug(...args: any[]): void
info(...args: any[]): void
warn(...args: any[]): void
error(...args: any[]): void
}