UNPKG

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