UNPKG

1.51 kBTypeScriptView Raw
1// eventsource uses DOM dependencies which are absent in a browserless environment like node.js.
2// to avoid compiler errors this monkey patch is used. See more details in:
3// - sinon: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11351
4// - rxjs: https://github.com/ReactiveX/rxjs/issues/1986
5/// <reference path="./dom-monkeypatch.d.ts" />
6
7declare class EventSource {
8 static readonly CLOSED: number;
9 static readonly CONNECTING: number;
10 static readonly OPEN: number;
11
12 constructor(url: string, eventSourceInitDict?: EventSource.EventSourceInitDict);
13
14 readonly CLOSED: number;
15 readonly CONNECTING: number;
16 readonly OPEN: number;
17 readonly url: string;
18 readonly readyState: number;
19 readonly withCredentials: boolean;
20 onopen: (evt: MessageEvent) => any;
21 onmessage: (evt: MessageEvent) => any;
22 onerror: (evt: MessageEvent) => any;
23 addEventListener(type: string, listener: (evt: MessageEvent) => void): void;
24 dispatchEvent(evt: Event): boolean;
25 removeEventListener(type: string, listener: (evt: MessageEvent) => void): void;
26 close(): void;
27}
28
29declare namespace EventSource {
30 enum ReadyState {
31 CONNECTING = 0,
32 OPEN = 1,
33 CLOSED = 2,
34 }
35
36 interface EventSourceInitDict {
37 withCredentials?: boolean | undefined;
38 headers?: object | undefined;
39 proxy?: string | undefined;
40 https?: object | undefined;
41 rejectUnauthorized?: boolean | undefined;
42 }
43}
44
45export = EventSource;