-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.d.ts
96 lines (96 loc) · 3.31 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
declare module "net-ipc" {
import { EventEmitter } from "events";
import { Socket as NetClient, Server as NetServer, ServerOpts, ConnectOpts, ListenOptions } from "net";
import { Server as TLSServer, TLSSocket, TlsOptions, ConnectionOptions } from "tls";
export type PromiseSettled = {
status: "fulfilled" | "rejected";
value?: any;
reason?: any;
}
export type ClientOptions = {
path?: string;
host?: string;
port?: number;
tls?: boolean;
options?: ConnectOpts | ConnectionOptions;
handshake?: boolean;
compress?: boolean;
messagepack?: boolean;
reconnect?: boolean;
retries?: number;
maxRetryTime?: number;
}
export type ClientReadyEvent = {
id: string,
compress: boolean,
messagepack: boolean
}
export const enum ClientStatus {
IDLE,
CONNECTING,
CONNECTED,
READY,
DISCONNECTED,
RECONNECTING
}
export type ServerOptions = {
path?: string;
port?: number;
tls?: boolean;
options?: ServerOpts | TlsOptions;
listenOptions?: Omit<ListenOptions, "port" | "path">;
max?: number;
retries?: number;
}
export class Client extends EventEmitter {
constructor(options?: ClientOptions);
on(event: 'ready', listener: (data: ClientReadyEvent) => void): this;
on(event: 'error', listener: (error: ErrorEvent) => void): this;
on(event: 'close', listener: (reason: any) => void): this;
on(event: 'status', listener: (status: number) => void): this;
on(event: 'message', listener: (data: any) => void): this;
on(event: 'request', listener: (request: any, response: (data: any) => Promise<void>) => void): this;
connect(payload?: any): Promise<this>;
send(data: any): Promise<void>;
request(data: any, timeout?: number): Promise<any>;
ping(data?: any, timeout?: number): Promise<number>;
close(reason?: any): Promise<boolean>;
destroy(reason?: any): boolean;
id?: string;
status: ClientStatus;
options: ClientOptions;
connection: NetClient | TLSSocket;
}
export class Server extends EventEmitter {
constructor(options?: ServerOptions);
on(event: 'ready', listener: (address: string) => void): this;
on(event: 'error', listener: (error: ErrorEvent, connection: Connection) => void): this;
on(event: 'connect', listener: (connection: Connection, payload?: any) => void): this;
on(event: 'disconnect', listener: (connection: Connection, reason?: any) => void): this;
on(event: 'close', listener: () => void): this;
on(event: 'message', listener: (message: any, connection: Connection) => void): this;
on(event: 'request', listener: (request: any, response: (data: any) => Promise<void>, connection: Connection) => void): this;
start(): Promise<this>;
close(allowReconnect?: boolean): Promise<this>;
broadcast(data: any): Promise<void>;
survey(data: any, timeout?: number): Promise<Array<PromiseSettled>>;
ping(data?: any, timeout?: number): Promise<Array<PromiseSettled>>;
pause(): void;
resume(): void;
connections: Connection[];
options: ServerOptions;
server: NetServer | TLSServer;
}
export class Connection {
send(data: any): Promise<void>;
request(data: any, timeout?: number): Promise<any>;
ping(data?: any, timeout?: number): Promise<number>;
close(reason?: any, allowReconnect?: boolean): Promise<boolean>;
destroy(reason?: any): boolean;
pause(): void;
resume(): void;
id: string;
server: Server;
connection: NetClient | TLSSocket;
}
}