UNPKG

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