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 connection = new signalR.HubConnectionBuilder().withUrl("/noteHub").build();
|
||||||
|
|
||||||
connection.start().then(function () {
|
let start = function () {
|
||||||
console.log('Started websocket listener');
|
|
||||||
}).catch(function (err) {
|
connection.start().then(function () {
|
||||||
console.error(err.toString());
|
console.log('Started websocket listener');
|
||||||
return alert('Connection error. Reload page.');
|
}).catch(function (err) {
|
||||||
});
|
console.error(err.toString());
|
||||||
|
return alert('Connection error. Reload page.');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let showToast = function (selector) {
|
let showToast = function (selector) {
|
||||||
|
|
||||||
@ -26,10 +29,14 @@ let saveContent = function ($textarea) {
|
|||||||
connection.invoke('SaveNote', content).then(function () {
|
connection.invoke('SaveNote', content).then(function () {
|
||||||
showToast('#saved-indicator');
|
showToast('#saved-indicator');
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
return alert('Connection error. Reload page.');
|
console.error(err.toString());
|
||||||
|
setTimeout(start, 2000);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// start the signalr connection
|
||||||
|
start();
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
|
|
||||||
let $textarea = $('textarea');
|
let $textarea = $('textarea');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user