Skip to content

Commit 40e53ec

Browse files
committed
Update abp.signalr-client.js
1 parent 30251a6 commit 40e53ec

File tree

2 files changed

+14
-40
lines changed

2 files changed

+14
-40
lines changed

Abp/Framework/scripts/libs/abp.signalr-client.js

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,53 +14,15 @@ var abp = abp || {};
1414
abp.signalr.increaseReconnectTime = abp.signalr.increaseReconnectTime || function (time) {
1515
return time * 2;
1616
};
17-
abp.signalr.withUrlOptions = abp.signalr.withUrlOptions || {};
17+
abp.signalr.withUrlOptions = abp.signalr.withUrlOptions || {};
1818

1919
// Configure the connection for abp.signalr.hubs.common
2020
function configureConnection(connection) {
2121
// Set the common hub
2222
abp.signalr.hubs.common = connection;
2323

24-
let tries = 1;
2524
let reconnectTime = abp.signalr.reconnectTime;
2625

27-
// Reconnect loop
28-
function tryReconnect() {
29-
if (tries <= abp.signalr.maxTries) {
30-
connection.start()
31-
.then(function () {
32-
reconnectTime = abp.signalr.reconnectTime;
33-
tries = 1;
34-
console.log('Reconnected to SignalR server!');
35-
abp.event.trigger('abp.signalr.reconnected');
36-
}).catch(function () {
37-
tries += 1;
38-
reconnectTime = abp.signalr.increaseReconnectTime(reconnectTime);
39-
setTimeout(function () {
40-
tryReconnect()
41-
},
42-
reconnectTime
43-
);
44-
});
45-
}
46-
}
47-
48-
// Reconnect if hub disconnects
49-
connection.onclose(function (e) {
50-
if (e) {
51-
abp.log.debug('Connection closed with error: ' + e);
52-
} else {
53-
abp.log.debug('Disconnected');
54-
}
55-
56-
if (!abp.signalr.autoReconnect) {
57-
return;
58-
}
59-
60-
abp.event.trigger('abp.signalr.disconnected');
61-
tryReconnect();
62-
});
63-
6426
// Register to get notifications
6527
connection.on('getNotification', function (notification) {
6628
abp.event.trigger('abp.notifications.received', notification);
@@ -104,6 +66,18 @@ var abp = abp || {};
10466
abp.log.debug('Starting connection using ' + signalR.HttpTransportType[transport] + ' transport');
10567
abp.signalr.withUrlOptions.transport = transport;
10668
var connection = new signalR.HubConnectionBuilder()
69+
.withAutomaticReconnect({
70+
nextRetryDelayInMilliseconds: retryContext => {
71+
abp.log.debug('Retry to connect to SignalR');
72+
if (retryContext.previousRetryCount > maxTries) {
73+
abp.log.debug('Max retries reached');
74+
return null;
75+
}
76+
reconnectTime *= 2;
77+
abp.log.debug('Waiting ' + reconnectTime + 'ms before retrying');
78+
return reconnectTime;
79+
}
80+
})
10781
.withUrl(url, abp.signalr.withUrlOptions)
10882
.build();
10983

Abp/Framework/scripts/libs/abp.signalr-client.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)