1// Set up event handlers 2const reconnectModal = document.getElementById("components-reconnect-modal"); 3reconnectModal.addEventListener("components-reconnect-state-changed", handleReconnectStateChanged); 4 5const retryButton = document.getElementById("components-reconnect-button"); 6retryButton.addEventListener("click", retry); 7 8const resumeButton = document.getElementById("components-resume-button"); 9resumeButton.addEventListener("click", resume); 10 11function handleReconnectStateChanged(event) { 12 if (event.detail.state === "show") { 13 reconnectModal.showModal(); 14 } else if (event.detail.state === "hide") { 15 reconnectModal.close(); 16 } else if (event.detail.state === "failed") { 17 document.addEventListener("visibilitychange", retryWhenDocumentBecomesVisible); 18 } else if (event.detail.state === "rejected") { 19 location.reload(); 20 } 21} 22 23async function retry() { 24 document.removeEventListener("visibilitychange", retryWhenDocumentBecomesVisible); 25 26 try { 27 // Reconnect will asynchronously return: 28 // - true to mean success 29 // - false to mean we reached the server, but it rejected the connection (e.g., unknown circuit ID) 30 // - exception to mean we didn't reach the server (this can be sync or async) 31 const successful = await Blazor.reconnect(); 32 if (!successful) { 33 // We have been able to reach the server, but the circuit is no longer available. 34 // We'll reload the page so the user can continue using the app as quickly as possible. 35 const resumeSuccessful = await Blazor.resumeCircuit(); 36 if (!resumeSuccessful) { 37 location.reload(); 38 } else { 39 reconnectModal.close(); 40 } 41 } 42 } catch (err) { 43 // We got an exception, server is currently unavailable 44 document.addEventListener("visibilitychange", retryWhenDocumentBecomesVisible); 45 } 46} 47 48async function resume() { 49 try { 50 const successful = await Blazor.resumeCircuit(); 51 if (!successful) { 52 location.reload(); 53 } 54 } catch { 55 reconnectModal.classList.replace("components-reconnect-paused", "components-reconnect-resume-failed"); 56 } 57} 58 59async function retryWhenDocumentBecomesVisible() { 60 if (document.visibilityState === "visible") { 61 await retry(); 62 } 63}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.