UNPKG

1.23 kBPlain TextView Raw
1export class Event {
2 public target: any;
3 public type: string;
4 constructor(type: string, target: any) {
5 this.target = target;
6 this.type = type;
7 }
8}
9
10export class ErrorEvent extends Event {
11 public message: string;
12 public error: Error;
13 constructor(error: Error, target: any) {
14 super('error', target);
15 this.message = error.message;
16 this.error = error;
17 }
18}
19
20export class CloseEvent extends Event {
21 public code: number;
22 public reason: string;
23 public wasClean = true;
24 constructor(code: number = 1000, reason: string = '', target: any) {
25 super('close', target);
26 this.code = code;
27 this.reason = reason;
28 }
29}
30export interface WebSocketEventMap {
31 close: CloseEvent;
32 error: ErrorEvent;
33 message: MessageEvent;
34 open: Event;
35}
36
37export interface WebSocketEventListenerMap {
38 close: (event: CloseEvent) => void | {handleEvent: (event: CloseEvent) => void};
39 error: (event: ErrorEvent) => void | {handleEvent: (event: ErrorEvent) => void};
40 message: (event: MessageEvent) => void | {handleEvent: (event: MessageEvent) => void};
41 open: (event: Event) => void | {handleEvent: (event: Event) => void};
42}