|
37 | 37 | } |
38 | 38 | }); |
39 | 39 |
|
| 40 | + notifier.notify('SignalREvent', 'SignalR starting'); |
| 41 | + connectToSignalR(connection); |
| 42 | + } |
| 43 | + |
| 44 | + var firstConnect = true; |
| 45 | + function connectToSignalR (connection) { |
40 | 46 | 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."); |
65 | 52 | }); |
66 | 53 |
|
67 | | - notifier.notify('SignalREvent', 'SignalR starting'); |
68 | | - } |
| 54 | + connection.reconnected(function () { |
| 55 | + notifier.notify('SignalREvent', 'Reconnected'); |
| 56 | + }); |
69 | 57 |
|
| 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 | + }; |
70 | 80 |
|
71 | 81 | return { |
72 | 82 | subscribe: function (scope, callback, eventName) { |
|
0 commit comments