1 | import { MessageEvent, ErrorEvent } from './websocket'
|
---|
2 | import Dispatcher from './dispatcher'
|
---|
3 |
|
---|
4 | import {
|
---|
5 | EventListenerOptions,
|
---|
6 | AddEventListenerOptions,
|
---|
7 | EventListenerOrEventListenerObject
|
---|
8 | } from './patch'
|
---|
9 |
|
---|
10 | interface EventSourceEventMap {
|
---|
11 | error: ErrorEvent
|
---|
12 | message: MessageEvent
|
---|
13 | open: Event
|
---|
14 | }
|
---|
15 |
|
---|
16 | interface EventSource extends EventTarget {
|
---|
17 | close(): void
|
---|
18 | readonly CLOSED: 2
|
---|
19 | readonly CONNECTING: 0
|
---|
20 | readonly OPEN: 1
|
---|
21 | onerror: (this: EventSource, ev: ErrorEvent) => any
|
---|
22 | onmessage: (this: EventSource, ev: MessageEvent) => any
|
---|
23 | onopen: (this: EventSource, ev: Event) => any
|
---|
24 | readonly readyState: 0 | 1 | 2
|
---|
25 | readonly url: string
|
---|
26 | readonly withCredentials: boolean
|
---|
27 |
|
---|
28 | addEventListener<K extends keyof EventSourceEventMap>(
|
---|
29 | type: K,
|
---|
30 | listener: (this: EventSource, ev: EventSourceEventMap[K]) => any,
|
---|
31 | options?: boolean | AddEventListenerOptions
|
---|
32 | ): void
|
---|
33 | addEventListener(
|
---|
34 | type: string,
|
---|
35 | listener: EventListenerOrEventListenerObject,
|
---|
36 | options?: boolean | AddEventListenerOptions
|
---|
37 | ): void
|
---|
38 | removeEventListener<K extends keyof EventSourceEventMap>(
|
---|
39 | type: K,
|
---|
40 | listener: (this: EventSource, ev: EventSourceEventMap[K]) => any,
|
---|
41 | options?: boolean | EventListenerOptions
|
---|
42 | ): void
|
---|
43 | removeEventListener(
|
---|
44 | type: string,
|
---|
45 | listener: EventListenerOrEventListenerObject,
|
---|
46 | options?: boolean | EventListenerOptions
|
---|
47 | ): void
|
---|
48 | }
|
---|
49 |
|
---|
50 | export declare const EventSource: {
|
---|
51 | prototype: EventSource
|
---|
52 | new (url: string | URL, init?: EventSourceInit): EventSource
|
---|
53 | readonly CLOSED: 2
|
---|
54 | readonly CONNECTING: 0
|
---|
55 | readonly OPEN: 1
|
---|
56 | }
|
---|
57 |
|
---|
58 | interface EventSourceInit {
|
---|
59 | withCredentials?: boolean,
|
---|
60 | dispatcher?: Dispatcher
|
---|
61 | }
|
---|