move signalr start to function, restart if failure after 2 secs
This commit is contained in:
parent
e9222c1ee2
commit
b1a5d24d6c
@ -1,11 +1,14 @@
|
||||
let connection = new signalR.HubConnectionBuilder().withUrl("/noteHub").build();
|
||||
|
||||
let start = function () {
|
||||
|
||||
connection.start().then(function () {
|
||||
console.log('Started websocket listener');
|
||||
}).catch(function (err) {
|
||||
console.error(err.toString());
|
||||
return alert('Connection error. Reload page.');
|
||||
});
|
||||
}
|
||||
|
||||
let showToast = function (selector) {
|
||||
|
||||
@ -26,10 +29,14 @@ let saveContent = function ($textarea) {
|
||||
connection.invoke('SaveNote', content).then(function () {
|
||||
showToast('#saved-indicator');
|
||||
}).catch(function (err) {
|
||||
return alert('Connection error. Reload page.');
|
||||
console.error(err.toString());
|
||||
setTimeout(start, 2000);
|
||||
});
|
||||
};
|
||||
|
||||
// start the signalr connection
|
||||
start();
|
||||
|
||||
$(function () {
|
||||
|
||||
let $textarea = $('textarea');
|
||||
|
Loading…
x
Reference in New Issue
Block a user