forked from subins2000/p2pt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
p2pt.d.ts
43 lines (41 loc) · 1.31 KB
/
p2pt.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
import type { EventEmitter } from "events";
export default class P2PT<SendableMessage = any> extends EventEmitter {
_peerId: string;
constructor(announceURLs?: Array<string>, identifierString?: string);
setIdentifier(identifierString: string): Promise<void>;
start(): Promise<void>;
requestMorePeers(): Promise<object>;
send(
peer: Peer,
msg: SendableMessage,
msgID?: number
): Promise<[peer: Peer, msg: object]>;
addTracker(announceURL: string): void;
removeTracker(announceURL: string): void;
requestMorePeers(): void;
getTrackerStats(): TrackerStats;
destroy(): void;
on(event: "peerconnect", callback: (peer: Peer) => void): void;
on(event: "data", callback: (peer: Peer, data: any) => void): void;
on(event: "msg", callback: (peer: Peer, msg: any) => void): void;
on(event: "peerclose", callback: (peer: Peer) => void): void;
on(
event: "trackerconnect",
callback: (tracker: Tracker, stats: TrackerStats) => void
): void;
on(
event: "trackerwarning",
callback: (error: object, stats: TrackerStats) => void
): any;
}
export interface Peer<SendableMessage = any> {
id: string;
respond(msg: SendableMessage): Promise<[peer: Peer, msg: any]>;
}
export interface Tracker {
announceUrl: string;
}
export interface TrackerStats {
connected: number;
total: number;
}