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 return; 34 } 35 36 // We have been able to reach the server, but the circuit is no longer available. 37 // We'll reload the page so the user can continue using the app as quickly as possible. 38 const resumeSuccessful = await Blazor.resumeCircuit(); 39 if (resumeSuccessful) { 40 reconnectModal.close(); 41 return; 42 } 43 44 location.reload(); 45 } catch (err) { 46 // We got an exception, server is currently unavailable 47 console.error("Blazor reconnect failed.", err); 48 document.addEventListener("visibilitychange", retryWhenDocumentBecomesVisible); 49 } 50} 51 52async function resume() { 53 try { 54 const successful = await Blazor.resumeCircuit(); 55 if (!successful) { 56 location.reload(); 57 } 58 } catch (err) { 59 console.error("Blazor resume failed.", err); 60 location.reload(); 61 } 62} 63 64async function retryWhenDocumentBecomesVisible() { 65 if (document.visibilityState === "visible") { 66 await retry(); 67 } 68}
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.