-
Notifications
You must be signed in to change notification settings - Fork 4
/
wsrpc.d.ts
84 lines (71 loc) · 2.26 KB
/
wsrpc.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
export namespace NWsRPC {
export module Main {
export enum States {
CONNECTING = 'CONNECTING',
OPEN = 'OPEN',
CLOSING = 'CLOSING',
CLOSED = 'CLOSED',
}
export enum StateCodes {
CONNECTING = 0,
OPEN = 1,
CLOSING = 2,
CLOSED = 3,
}
export enum Events {
onconnect = 'onconnect',
onerror = 'onerror',
onclose = 'onclose',
onchange = 'onchange',
}
export interface Deferred {
resolve(result: any): any;
reject(error: any): any;
done: boolean;
promise: Promise<any>;
}
export type eventId = number;
export type Route = string;
export interface CallInterface {
(func: Route, args: Array<any>, params: Object): Promise<any>
}
export interface ProxyInterface extends Record<string, CallInterface | ProxyInterface> {}
export interface onEventResult {
(event: Event): any;
}
export interface WSRPCPublic {
defer(): Deferred;
connect(): void;
destroy(): void;
state(): States;
stateCode(): StateCodes;
addEventListener(
event: Events,
callback: (event: Events) => void
): eventId;
removeEventListener(event: Events, index: eventId): boolean;
onEvent(): Promise<onEventResult>;
addRoute(
route: Route,
callback: (
this: Promise<any>,
arguments: any
) => boolean,
isAsync?: boolean | undefined
): void;
deleteRoute(name: Route): void;
call: CallInterface;
proxy: ProxyInterface;
addServerEventListener(
func: (this: WSRPCPublic, event: object) => any
): number;
removeServerEventListener(index: number): number;
sendRaw(data: any): any;
}
export interface WSRPC {
DEBUG: boolean;
TRACE: boolean;
new(url: string): WSRPCPublic;
}
}
}