forked from peers/peerjs-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
71 lines (62 loc) · 1.99 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
/* eslint-disable @typescript-eslint/no-explicit-any */
/// <reference types="node" />
import { Server } from "net";
import { EventEmitter } from "events";
import WebSocketLib from "ws";
import Express from "express";
declare type MyWebSocket = WebSocketLib & EventEmitter;
declare type Optional<T> = {
[P in keyof T]?: (T[P] | undefined);
};
declare interface IConfig {
readonly port?: number;
readonly expire_timeout?: number;
readonly alive_timeout?: number;
readonly key?: string;
readonly path?: string;
readonly concurrent_limit?: number;
readonly allow_discovery?: boolean;
readonly proxied?: boolean | string;
readonly cleanup_out_msgs?: number;
readonly ssl?: {
key: string;
cert: string;
};
readonly generateClientId?: () => string;
}
declare interface IClient {
getId(): string;
getToken(): string;
getSocket(): MyWebSocket | null;
setSocket(socket: MyWebSocket | null): void;
getLastPing(): number;
setLastPing(lastPing: number): void;
send(data: any): void;
}
declare enum MessageType {
OPEN = "OPEN",
LEAVE = "LEAVE",
CANDIDATE = "CANDIDATE",
OFFER = "OFFER",
ANSWER = "ANSWER",
EXPIRE = "EXPIRE",
HEARTBEAT = "HEARTBEAT",
ID_TAKEN = "ID-TAKEN",
ERROR = "ERROR"
}
declare interface IMessage {
readonly type: MessageType;
readonly src: string;
readonly dst: string;
readonly payload?: any;
}
declare interface CustomExpress extends Express.Express {
on(event: string, callback: (...args: any[]) => void): this;
on(event: 'connection', callback: (client: IClient) => void): this;
on(event: 'disconnect', callback: (client: IClient) => void): this;
on(event: 'message', callback: (client: IClient, message: IMessage) => void): this;
on(event: 'error', callback: (error: Error) => void): this;
}
declare function ExpressPeerServer(server: Server, options?: IConfig): CustomExpress;
declare function PeerServer(options?: Optional<IConfig>, callback?: (server: Server) => void): CustomExpress;
export { ExpressPeerServer, PeerServer };