forked from pladaria/reconnecting-websocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.ts
42 lines (39 loc) · 1.18 KB
/
events.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
export class Event {
public target: any;
public type: string;
constructor(type: string, target: any) {
this.target = target;
this.type = type;
}
}
export class ErrorEvent extends Event {
public message: string;
public error: Error;
constructor(error: Error, target: any) {
super('error', target);
this.message = error.message;
this.error = error;
}
}
export class CloseEvent extends Event {
public code: number;
public reason: string;
public wasClean = true;
constructor(code = 1000, reason = '', target: any) {
super('close', target);
this.code = code;
this.reason = reason;
}
}
export interface WebSocketEventMap {
close: CloseEvent;
error: ErrorEvent;
message: MessageEvent;
open: Event;
}
export interface WebSocketEventListenerMap {
close: (event: CloseEvent) => void | {handleEvent: (event: CloseEvent) => void};
error: (event: ErrorEvent) => void | {handleEvent: (event: ErrorEvent) => void};
message: (event: MessageEvent) => void | {handleEvent: (event: MessageEvent) => void};
open: (event: Event) => void | {handleEvent: (event: Event) => void};
}