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

Function startConnection

www/js/ext/eventsource.js:247–274  ·  view source on GitHub ↗
(stub)

Source from the content-addressed store, hash-verified

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;

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