diff --git a/lib/web/eventsource/eventsource-stream.js b/lib/web/eventsource/eventsource-stream.js index 754934568d0..59cf7468800 100644 --- a/lib/web/eventsource/eventsource-stream.js +++ b/lib/web/eventsource/eventsource-stream.js @@ -35,16 +35,16 @@ const SPACE = 0x20 /** * @typedef eventSourceSettings * @type {object} - * @property {string} lastEventId The last event ID received from the server. - * @property {string} origin The origin of the event source. - * @property {number} reconnectionTime The reconnection time, in milliseconds. + * @property {string} [lastEventId] The last event ID received from the server. + * @property {string} [origin] The origin of the event source. + * @property {number} [reconnectionTime] The reconnection time, in milliseconds. */ class EventSourceStream extends Transform { /** * @type {eventSourceSettings} */ - state = null + state /** * Leading byte-order-mark check. @@ -63,7 +63,7 @@ class EventSourceStream extends Transform { eventEndCheck = false /** - * @type {Buffer} + * @type {Buffer|null} */ buffer = null @@ -78,8 +78,9 @@ class EventSourceStream extends Transform { /** * @param {object} options - * @param {eventSourceSettings} options.eventSourceSettings - * @param {Function} [options.push] + * @param {boolean} [options.readableObjectMode] + * @param {eventSourceSettings} [options.eventSourceSettings] + * @param {(chunk: any, encoding?: BufferEncoding | undefined) => boolean} [options.push] */ constructor (options = {}) { // Enable object mode as EventSourceStream emits objects of shape @@ -280,7 +281,7 @@ class EventSourceStream extends Transform { /** * @param {Buffer} line - * @param {EventStreamEvent} event + * @param {EventSourceStreamEvent} event */ parseLine (line, event) { // If the line is empty (a blank line) diff --git a/lib/web/eventsource/eventsource.js b/lib/web/eventsource/eventsource.js index 60b4d842951..257b9573ef9 100644 --- a/lib/web/eventsource/eventsource.js +++ b/lib/web/eventsource/eventsource.js @@ -28,7 +28,8 @@ const defaultReconnectionTime = 3000 /** * The readyState attribute represents the state of the connection. - * @enum + * @typedef ReadyState + * @type {0|1|2} * @readonly * @see https://html.spec.whatwg.org/multipage/server-sent-events.html#dom-eventsource-readystate-dev */ @@ -80,9 +81,12 @@ class EventSource extends EventTarget { message: null } - #url = null + #url #withCredentials = false + /** + * @type {ReadyState} + */ #readyState = CONNECTING #request = null @@ -98,7 +102,7 @@ class EventSource extends EventTarget { /** * Creates a new EventSource object. * @param {string} url - * @param {EventSourceInit} [eventSourceInitDict] + * @param {EventSourceInit} [eventSourceInitDict={}] * @see https://html.spec.whatwg.org/multipage/server-sent-events.html#the-eventsource-interface */ constructor (url, eventSourceInitDict = {}) { @@ -148,7 +152,7 @@ class EventSource extends EventTarget { // 7. If the value of eventSourceInitDict's withCredentials member is true, // then set corsAttributeState to Use Credentials and set ev's // withCredentials attribute to true. - if (eventSourceInitDict.withCredentials) { + if (eventSourceInitDict.withCredentials === true) { corsAttributeState = USE_CREDENTIALS this.#withCredentials = true } @@ -189,7 +193,7 @@ class EventSource extends EventTarget { /** * Returns the state of this EventSource object's connection. It can have the * values described below. - * @returns {0|1|2} + * @returns {ReadyState} * @readonly */ get readyState () {