(stub)
| 244 | return stub; |
| 245 | } |
| 246 | function startConnection(stub) { |
| 247 | var ac = new AbortController(); |
| 248 | stub.abortController = ac; |
| 249 | var fetchOptions = { |
| 250 | method: stub.method, |
| 251 | signal: ac.signal, |
| 252 | headers: Object.assign({}, stub.headers || {}) |
| 253 | }; |
| 254 | if (stub.withCredentials) { |
| 255 | fetchOptions.credentials = "include"; |
| 256 | } |
| 257 | if (stub.lastEventId) { |
| 258 | fetchOptions.headers["Last-Event-ID"] = stub.lastEventId; |
| 259 | } |
| 260 | fetch(stub.url, fetchOptions).then(function(response) { |
| 261 | if (ac.signal.aborted) return; |
| 262 | if (!response.ok) { |
| 263 | throw new Error("SSE connection failed with status " + response.status); |
| 264 | } |
| 265 | stub.retryCount = 0; |
| 266 | dispatch(stub, "open", { type: "open" }); |
| 267 | return readStream(stub, response.body.getReader(), ac); |
| 268 | }).catch(function(err) { |
| 269 | if (ac.signal.aborted) return; |
| 270 | dispatch(stub, "error", { type: "error", error: err }); |
| 271 | scheduleReconnect(stub); |
| 272 | }); |
| 273 | } |
| 274 | async function readStream(stub, reader, ac) { |
| 275 | stub.reader = reader; |
| 276 | var baseDelay = 500; |
no test coverage detected