-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
59 lines (54 loc) · 1.41 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
declare module 'democracy' {
import {Socket} from 'dgram';
import Timeout = NodeJS.Timeout;
export default class Democracy {
protected options: InternalOptions;
protected socket: Socket;
protected _nodes: {[key: string]: Node};
protected _id: string;
protected _weight: number;
protected _state: 'leader' | 'citizen' | 'removed';
constructor(opts?: Options);
protected addNodeToList(node: Node): void;
protected checkBallots(candidate: string): this;
hello(): this;
nodes(): { [key: string]: Node };
leader(): Node | undefined;
resign(): this;
isLeader(): boolean;
send(customEvent: string, extraData?: any, id?: string): this;
subscribe(channel: string): this;
publish(channel: string, msg: any): this;
on(event: string, func: (data: any) => void);
}
export class Options {
interval?: number;
timeout?: number;
maxPacketSize?: number;
source?: string;
peers?: string[];
weight?: number;
id?: string;
channels?: string[];
}
class InternalOptions {
interval: number;
timeout: number;
maxPacketSize: number;
source: string[];
peers: string[][];
weight: number;
id: string;
channels: string[];
}
export class Node {
id: string;
source: string;
weight: number;
state: string;
last: Date;
voters: string[];
channels: string[];
disconnected?: Timeout;
}
}