forked from primus/primus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimus.d.ts
82 lines (76 loc) · 2.52 KB
/
primus.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
import * as http from 'http';
import { Socket } from 'net';
export interface IPrimusParser {
encoder: (data: any, fn: (error: Error, response: any) => void) => void;
decoder: (data: any, fn: (error: Error, response: any) => void) => void;
}
export declare class Primus {
constructor(server: http.Server, options?: IPrimusOptions);
authorize(req: http.ClientRequest, done: () => void): void;
before(event: string, cb: () => void): void;
before(event: string, cb: (req: http.ClientRequest, res: http.ServerResponse, next: any) => void): void;
before(event: string, cb: (req: http.ClientRequest, res: http.ServerResponse) => void): void;
destroy(): void;
disable(name: string): void;
emits(event: string, parser: (next: any, parser: any) => void): void; // might be better tied to a TSD for https://github.com/primus/emits
enable(name: string): void;
end(): void;
forEach(cb: (spark: ISpark, id: string, connections: any) => void): void;
id(cb: (id: any) => void): void;
library(): void;
on(event: string, cb: (spark: ISpark) => void): void;
open(): void;
remove(name: string): void;
socket: Socket;
static createSocket(options?: IPrimusOptions): Socket;
transform(event: string, cb: (packet: any) => void): void;
transforms(event: string, parser: (packet: any, next: any) => void): void; // might be better tied to a TSD for https://github.com/primus/emits
use(name: string, plugin: Object): void;
write(data: any): void;
}
export interface IPrimusOptions {
authorization?: Function;
compression?: boolean;
credentials?: boolean;
exposed?: boolean;
global?: string;
headers?: boolean;
maxAge?: string;
methods?: string;
origins?: string;
parser?: string | IPrimusParser;
pathname?: string;
plugin?: Object;
strategy?: any;
timeout?: number;
transformer?: string;
[key: string]: any;
}
export interface IPrimusConnectOptions {
timeout?: number;
ping?: number;
pong?: number;
strategy?: string;
manual?: boolean;
websockets?: boolean;
network?: boolean;
transport?: any;
queueSize?: any;
reconnect?: {
max?: any;
min?: number;
retries?: number;
factor?: number;
};
}
export interface ISpark {
headers: any[];
address: string;
query: string;
id: string;
request: http.ClientRequest;
write(data: any): void;
end(data?: any, options?: Object): void;
emits(event: string, parser: (next: any, parser: any) => void): void; // might be better tied to a TSD for https://github.com/primus/emits
on(event: string, cb: (data: any) => void): void;
}