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