forked from binaryminds/react-native-sse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
72 lines (59 loc) · 1.59 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
72
export type EventType = 'open' | 'message' | 'error' | 'close';
export interface BaseEvent {
type: string;
}
export interface MessageEvent {
type: 'message';
data: string | null;
lastEventId: string | null;
url: string;
}
export interface OpenEvent {
type: 'open';
}
export interface CloseEvent {
type: 'close';
}
export interface TimeoutEvent {
type: 'timeout';
}
export interface ErrorEvent {
type: 'error';
message: string;
xhrState: number;
xhrStatus: number;
}
export interface CustomEvent<E extends string> {
type: E;
data: string | null;
lastEventId: string | null;
url: string;
}
export interface ExceptionEvent {
type: 'exception';
message: string;
error: Error;
}
export interface EventSourceOptions {
method?: string;
timeout?: number;
headers?: Record<string, any>;
body?: any;
debug?: boolean;
pollingInterval?: number;
timeoutBeforeConnection?: number;
}
export type EventSourceEvent = MessageEvent | OpenEvent | CloseEvent | TimeoutEvent | ErrorEvent | ExceptionEvent;
export type EventSourceListener<E extends string = never> = (
event: CustomEvent<E> | EventSourceEvent
) => void;
declare class EventSource<E extends string = never> {
constructor(url: URL | string, options?: EventSourceOptions);
open(): void;
close(): void;
addEventListener(type: E | EventType, listener: EventSourceListener<E>): void;
removeEventListener(type: E | EventType, listener: EventSourceListener<E>): void;
removeAllEventListeners(type?: E | EventType): void;
dispatch(type: E | EventType, data: E | EventSourceEvent): void;
}
export default EventSource;