(stub)
| 11766 | return stub; |
| 11767 | } |
| 11768 | function startConnection(stub) { |
| 11769 | var ac = new AbortController(); |
| 11770 | stub.abortController = ac; |
| 11771 | var fetchOptions = { |
| 11772 | method: stub.method, |
| 11773 | signal: ac.signal, |
| 11774 | headers: Object.assign({}, stub.headers || {}) |
| 11775 | }; |
| 11776 | if (stub.withCredentials) { |
| 11777 | fetchOptions.credentials = "include"; |
| 11778 | } |
| 11779 | if (stub.lastEventId) { |
| 11780 | fetchOptions.headers["Last-Event-ID"] = stub.lastEventId; |
| 11781 | } |
| 11782 | fetch(stub.url, fetchOptions).then(function(response) { |
| 11783 | if (ac.signal.aborted) return; |
| 11784 | if (!response.ok) { |
| 11785 | throw new Error("SSE connection failed with status " + response.status); |
| 11786 | } |
| 11787 | stub.retryCount = 0; |
| 11788 | dispatch(stub, "open", { type: "open" }); |
| 11789 | return readStream(stub, response.body.getReader(), ac); |
| 11790 | }).catch(function(err) { |
| 11791 | if (ac.signal.aborted) return; |
| 11792 | dispatch(stub, "error", { type: "error", error: err }); |
| 11793 | scheduleReconnect(stub); |
| 11794 | }); |
| 11795 | } |
| 11796 | async function readStream(stub, reader, ac) { |
| 11797 | stub.reader = reader; |
| 11798 | var baseDelay = 500; |
no test coverage detected