From 0986702177547804187581a7442ad660e1f2776d Mon Sep 17 00:00:00 2001 From: Fiyaz Bin Hasan Date: Fri, 23 Jul 2021 19:52:47 +0600 Subject: [PATCH] cutoff snippets fixed (#22826) --- aspnetcore/signalr/javascript-client.md | 4 ++-- .../samples/3.x/SignalRChat/wwwroot/chat.js | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/aspnetcore/signalr/javascript-client.md b/aspnetcore/signalr/javascript-client.md index 787fbf6c18..b95d32eb02 100644 --- a/aspnetcore/signalr/javascript-client.md +++ b/aspnetcore/signalr/javascript-client.md @@ -60,7 +60,7 @@ The client library is available on the following CDNs: The following code creates and starts a connection. The hub's name is case insensitive: -[!code-javascript[](javascript-client/samples/3.x/SignalRChat/wwwroot/chat.js?range=3-6,29-43)] +[!code-javascript[](javascript-client/samples/3.x/SignalRChat/wwwroot/chat.js?range=3-6,29-45)] ### Cross-origin connections @@ -261,7 +261,7 @@ The following code demonstrates a typical manual reconnection approach: 1. A function (in this case, the `start` function) is created to start the connection. 1. Call the `start` function in the connection's `onclose` event handler. -[!code-javascript[](javascript-client/samples/3.x/SignalRChat/wwwroot/chat.js?range=30-40)] +[!code-javascript[](javascript-client/samples/3.x/SignalRChat/wwwroot/chat.js?range=30-42)] A real-world implementation would use an exponential back-off or retry a specified number of times before giving up. diff --git a/aspnetcore/signalr/javascript-client/samples/3.x/SignalRChat/wwwroot/chat.js b/aspnetcore/signalr/javascript-client/samples/3.x/SignalRChat/wwwroot/chat.js index 1126890194..3150893609 100644 --- a/aspnetcore/signalr/javascript-client/samples/3.x/SignalRChat/wwwroot/chat.js +++ b/aspnetcore/signalr/javascript-client/samples/3.x/SignalRChat/wwwroot/chat.js @@ -37,12 +37,8 @@ document.addEventListener("DOMContentLoaded", () => { } }; - connection.onclose(function (error) { - if (error) { - console.log(`Connection closed with error: ${error}`); - } else { - console.log("Connection closed."); - } + connection.onclose(async () => { + await start(); }); // Start the connection.