* Creates a new EventSource object. * @param {string} url * @param {EventSourceInit} [eventSourceInitDict={}] * @see https://html.spec.whatwg.org/multipage/server-sent-events.html#the-eventsource-interface
(url, eventSourceInitDict = {})
| 16770 | * @see https://html.spec.whatwg.org/multipage/server-sent-events.html#the-eventsource-interface |
| 16771 | */ |
| 16772 | constructor(url, eventSourceInitDict = {}) { |
| 16773 | super(); |
| 16774 | webidl.util.markAsUncloneable(this); |
| 16775 | const prefix = "EventSource constructor"; |
| 16776 | webidl.argumentLengthCheck(arguments, 1, prefix); |
| 16777 | if (!experimentalWarned) { |
| 16778 | experimentalWarned = true; |
| 16779 | process.emitWarning("EventSource is experimental, expect them to change at any time.", { |
| 16780 | code: "UNDICI-ES" |
| 16781 | }); |
| 16782 | } |
| 16783 | url = webidl.converters.USVString(url); |
| 16784 | eventSourceInitDict = webidl.converters.EventSourceInitDict(eventSourceInitDict, prefix, "eventSourceInitDict"); |
| 16785 | this.#dispatcher = eventSourceInitDict.node.dispatcher || eventSourceInitDict.dispatcher; |
| 16786 | this.#state = { |
| 16787 | lastEventId: "", |
| 16788 | reconnectionTime: eventSourceInitDict.node.reconnectionTime |
| 16789 | }; |
| 16790 | const settings = environmentSettingsObject; |
| 16791 | let urlRecord; |
| 16792 | try { |
| 16793 | urlRecord = new URL(url, settings.settingsObject.baseUrl); |
| 16794 | this.#state.origin = urlRecord.origin; |
| 16795 | } catch (e) { |
| 16796 | throw new DOMException(e, "SyntaxError"); |
| 16797 | } |
| 16798 | this.#url = urlRecord.href; |
| 16799 | let corsAttributeState = ANONYMOUS; |
| 16800 | if (eventSourceInitDict.withCredentials === true) { |
| 16801 | corsAttributeState = USE_CREDENTIALS; |
| 16802 | this.#withCredentials = true; |
| 16803 | } |
| 16804 | const request = createPotentialCORSRequest(urlRecord, "", corsAttributeState); |
| 16805 | request.client = environmentSettingsObject.settingsObject; |
| 16806 | request.headersList.set("Accept", "text/event-stream"); |
| 16807 | request.cache = "no-store"; |
| 16808 | request.initiator = "other"; |
| 16809 | this.#request = request; |
| 16810 | this.#connect(); |
| 16811 | } |
| 16812 | /** |
| 16813 | * Returns the state of this EventSource object's connection. It can have the |
| 16814 | * values described below. |
nothing calls this directly
no test coverage detected