* The EventSource interface is used to receive server-sent events. It * connects to a server over HTTP and receives events in text/event-stream * format without closing the connection. * @extends {EventTarget} * @see https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-even
| 74 | * @api public |
| 75 | */ |
| 76 | class EventSource extends EventTarget { |
| 77 | #events = { |
| 78 | open: null, |
| 79 | error: null, |
| 80 | message: null |
| 81 | } |
| 82 | |
| 83 | #url |
| 84 | #withCredentials = false |
| 85 | |
| 86 | /** |
| 87 | * @type {ReadyState} |
| 88 | */ |
| 89 | #readyState = CONNECTING |
| 90 | |
| 91 | #request = null |
| 92 | #controller = null |
| 93 | |
| 94 | #dispatcher |
| 95 | |
| 96 | /** |
| 97 | * @type {import('./eventsource-stream').eventSourceSettings} |
| 98 | */ |
| 99 | #state |
| 100 | |
| 101 | /** |
| 102 | * Creates a new EventSource object. |
| 103 | * @param {string} url |
| 104 | * @param {EventSourceInit} [eventSourceInitDict={}] |
| 105 | * @see https://html.spec.whatwg.org/multipage/server-sent-events.html#the-eventsource-interface |
| 106 | */ |
| 107 | constructor (url, eventSourceInitDict = {}) { |
| 108 | // 1. Let ev be a new EventSource object. |
| 109 | super() |
| 110 | |
| 111 | webidl.util.markAsUncloneable(this) |
| 112 | |
| 113 | const prefix = 'EventSource constructor' |
| 114 | webidl.argumentLengthCheck(arguments, 1, prefix) |
| 115 | |
| 116 | if (!experimentalWarned) { |
| 117 | experimentalWarned = true |
| 118 | process.emitWarning('EventSource is experimental, expect them to change at any time.', { |
| 119 | code: 'UNDICI-ES' |
| 120 | }) |
| 121 | } |
| 122 | |
| 123 | url = webidl.converters.USVString(url) |
| 124 | eventSourceInitDict = webidl.converters.EventSourceInitDict(eventSourceInitDict, prefix, 'eventSourceInitDict') |
| 125 | |
| 126 | this.#dispatcher = eventSourceInitDict.node.dispatcher || eventSourceInitDict.dispatcher |
| 127 | this.#state = { |
| 128 | lastEventId: '', |
| 129 | reconnectionTime: eventSourceInitDict.node.reconnectionTime |
| 130 | } |
| 131 | |
| 132 | // 2. Let settings be ev's relevant settings object. |
| 133 | // https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…