MCPcopy Create free account
hub / github.com/bigskysoftware/_hyperscript / startConnection

Function startConnection

www/js/ext/eventsource.esm.js:246–273  ·  view source on GitHub ↗
(stub)

Source from the content-addressed store, hash-verified

244 return stub;
245}
246function 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}
274async function readStream(stub, reader, ac) {
275 stub.reader = reader;
276 var baseDelay = 500;

Callers 2

createStubFunction · 0.70
scheduleReconnectFunction · 0.70

Calls 4

dispatchFunction · 0.70
readStreamFunction · 0.70
scheduleReconnectFunction · 0.70
fetchFunction · 0.50

Tested by

no test coverage detected