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 functionpull/10632/head^2
parent
88fcd83ff6
commit
396377b921
|
@ -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, "&").replace(/</g, "<").replace(/>/g, ">");
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue