Skip to content

Commit 2d6294e

Browse files
committed
Retry to connect if first connection fails
1 parent f43008b commit 2d6294e

File tree

1 file changed

+36
-26
lines changed

1 file changed

+36
-26
lines changed

src/ServicePulse.Host/app/js/services/factory.listener.js

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,36 +37,46 @@
3737
}
3838
});
3939

40+
notifier.notify('SignalREvent', 'SignalR starting');
41+
connectToSignalR(connection);
42+
}
43+
44+
var firstConnect = true;
45+
function connectToSignalR (connection) {
4046
connection.start()
41-
.done(function () {
42-
notifier.notify('SignalREvent', 'SignalR started');
43-
44-
connection.error(function (error) {
45-
notifier.notify('SignalRError', "There was a problem communicating with ServiceControl.");
46-
});
47-
48-
connection.reconnected(function () {
49-
notifier.notify('SignalREvent', 'Reconnected');
50-
});
51-
52-
connection.stateChanged(function (change) {
53-
if (change.newState === $jquery.signalR.connectionState.disconnected) {
54-
notifier.notify('SignalRError', 'The server is offline');
55-
}
56-
});
57-
})
58-
.fail(function () {
59-
//notification is needed for other part of Pulse that depend on the notifier to get connectivity status.
60-
notifier.notify('SignalRError');
61-
if ($window.location.hash.indexOf('/configuration/connections') < 0) {
62-
// Uses the toastService directly to avoid breaking the notifier class. The previous notifier calls should all be removed at some point too.
63-
toastService.showError('Could not connect to ServiceControl. <a class="btn btn-default" href="#/configuration/connections">View connection settings</a>', true, false);
64-
}
47+
.done(function () {
48+
notifier.notify('SignalREvent', 'SignalR started');
49+
50+
connection.error(function (error) {
51+
notifier.notify('SignalRError', "There was a problem communicating with ServiceControl.");
6552
});
6653

67-
notifier.notify('SignalREvent', 'SignalR starting');
68-
}
54+
connection.reconnected(function () {
55+
notifier.notify('SignalREvent', 'Reconnected');
56+
});
6957

58+
connection.stateChanged(function (change) {
59+
if (change.newState === $jquery.signalR.connectionState.disconnected) {
60+
notifier.notify('SignalRError', 'The server is offline');
61+
}
62+
});
63+
})
64+
.fail(function (error) {
65+
console.warn('Could not connect to signalR: ' + error);
66+
67+
//notification is needed for other part of Pulse that depend on the notifier to get connectivity status.
68+
notifier.notify('SignalRError');
69+
if (firstConnect && $window.location.hash.indexOf('/configuration/connections') < 0) {
70+
// Uses the toastService directly to avoid breaking the notifier class. The previous notifier calls should all be removed at some point too.
71+
toastService.showError('Could not connect to ServiceControl. <a class="btn btn-default" href="#/configuration/connections">View connection settings</a>', true, false);
72+
firstConnect = false;
73+
}
74+
75+
setTimeout(function() {
76+
connectToSignalR(connection);
77+
}, 2000);
78+
});
79+
};
7080

7181
return {
7282
subscribe: function (scope, callback, eventName) {

0 commit comments

Comments
 (0)