forked from pluralsh/absinthe-socket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphoenix_vx.x.x.js
69 lines (64 loc) · 2.13 KB
/
phoenix_vx.x.x.js
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
declare module "phoenix" {
declare export type Message<Payload = any> = {
topic: string,
event: string,
payload: Payload,
ref: null | number,
join_ref: null | number
};
declare export type SocketOpts = {
decode: (json: string, callback: (data: Object) => any) => any,
encode: (data: Object, callback: (json: string) => any) => any,
heartbeatIntervalMs: number,
logger: (kind: string, msg: string, data: Object) => any,
longpollerTimeout: number,
params: number,
reconnectAfterMs: number,
timeout: number,
transport: string
};
// This is not implemented in flow <= 0.55.0
declare class CloseEvent extends Event {
reason: string,
wasClean: boolean
}
declare export class Socket {
constructor(endPoint: string, opts?: $Shape<SocketOpts>): Socket,
protocol(): string,
endPointURL(): string,
disconnect(callback?: () => any, code?: number, reason?: string): void,
connect(params?: Object): void,
isConnected(): boolean,
log(kind: string, msg: string, data: Object): void,
onOpen(callback: () => any): void,
onClose(callback: (event: CloseEvent) => any): void,
onError(callback: (error: Event) => any): void,
onMessage(callback: (event: Message<>) => any): void,
channel(topic: string, params?: Object): Channel,
remove(channel: Channel): void,
push(data: mixed): void,
makeRef(): string
}
declare export class Push {
constructor(
channel: Channel,
event: string,
payload?: mixed,
timeout: number
): Push,
resend(timeout: number): void,
send(): void,
receive(status, callback: (response: any) => any): Push
}
declare export class Channel {
constructor(topic: string, params: Object, socket: Socket): Channel,
join(timeout?: number): Push,
on(event: string, callback: Function): number,
off(event: string, ref: number): void,
onClose(callback: Function): void,
onError(callback: (reason: string) => any): number,
onMessage(event: string, payload: mixed, ref: number): mixed,
push(event: string, payload: mixed): Push,
leave(timeout: number): Push
}
}