Update connection delay issue (#10359)

* Update connection delay issue

There needs to be a delay after the connection is started. The old sample code did not allow for this and caused errors in the application.

* Disabled Send Button Until Connection Established

Disabled Send Button Until Connection Established

* Moved sendButton listener outside of then function

Moved sendButton listener outside of then function
pull/10632/head^2
Luis Quintanilla 2019-01-28 21:26:59 -05:00 committed by Rick Anderson
parent 88fcd83ff6
commit 396377b921
1 changed files with 7 additions and 2 deletions

View File

@ -2,6 +2,9 @@
var connection = new signalR.HubConnectionBuilder().withUrl("/chatHub").build();
//Disable send button until connection is established
document.getElementById("sendButton").disabled = true;
connection.on("ReceiveMessage", function (user, message) {
var msg = message.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
var encodedMsg = user + " says " + msg;
@ -10,7 +13,9 @@ connection.on("ReceiveMessage", function (user, message) {
document.getElementById("messagesList").appendChild(li);
});
connection.start().catch(function (err) {
connection.start().then(function(){
document.getElementById("sendButton").disabled = false;
}).catch(function (err) {
return console.error(err.toString());
});
@ -21,4 +26,4 @@ document.getElementById("sendButton").addEventListener("click", function (event)
return console.error(err.toString());
});
event.preventDefault();
});
});