message_bus 4.3.0 → 4.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.js +9 -0
- data/CHANGELOG +6 -0
- data/assets/message-bus.js +37 -22
- data/lib/message_bus/version.rb +1 -1
- data/package-lock.json +465 -266
- data/package.json +1 -1
- data/spec/assets/SpecHelper.js +10 -4
- data/spec/assets/message-bus.spec.js +70 -1
- data/vendor/assets/javascripts/message-bus.js +37 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15a820bf3ce7658e466132cbc2dd41c4f71b5c68db2e993437698192922377b9
|
4
|
+
data.tar.gz: 2c698b0e82d3d17dc3c0aa682e34ffaf32713f47fe207c1e8b1d55d2fb7cbe48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ea1a5c7a8c80bdddb487eed1442e6364b37518407c1809b0fe76bc3bf5fcba96bb66df04d02d4e491350d415abbae1cd0ecc91ef1079838d6455b6063c0459f
|
7
|
+
data.tar.gz: 981cc3d93b7ca7a3af50179c9450033f4e4566edca5d1269c73d3fd94952f5a77d5ce14b87aa58bc5845e377a2c5c6cbe64cd1dc7905dd7689dfe1295f0668cf
|
data/.eslintrc.js
CHANGED
@@ -11,4 +11,13 @@ module.exports = {
|
|
11
11
|
},
|
12
12
|
rules: {},
|
13
13
|
ignorePatterns: ['/vendor', '/doc', '/assets/jquery-1.8.2.js'],
|
14
|
+
overrides: [
|
15
|
+
{
|
16
|
+
// Enable async/await in tests only
|
17
|
+
files: ["spec/**/*"],
|
18
|
+
parserOptions: {
|
19
|
+
ecmaVersion: 2022,
|
20
|
+
},
|
21
|
+
},
|
22
|
+
],
|
14
23
|
};
|
data/CHANGELOG
CHANGED
data/assets/message-bus.js
CHANGED
@@ -40,7 +40,7 @@
|
|
40
40
|
var pollTimeout = null;
|
41
41
|
var totalAjaxFailures = 0;
|
42
42
|
var totalAjaxCalls = 0;
|
43
|
-
var
|
43
|
+
var lastAjaxStartedAt;
|
44
44
|
|
45
45
|
var isHidden = (function () {
|
46
46
|
var prefixes = ["", "webkit", "ms", "moz"];
|
@@ -156,11 +156,11 @@
|
|
156
156
|
}
|
157
157
|
|
158
158
|
var gotData = false;
|
159
|
-
var
|
159
|
+
var abortedByClient = false;
|
160
160
|
var rateLimited = false;
|
161
161
|
var rateLimitedSeconds;
|
162
162
|
|
163
|
-
|
163
|
+
lastAjaxStartedAt = new Date();
|
164
164
|
totalAjaxCalls += 1;
|
165
165
|
data.__seq = totalAjaxCalls;
|
166
166
|
|
@@ -281,7 +281,7 @@
|
|
281
281
|
rateLimitedSeconds = tryAfter;
|
282
282
|
rateLimited = true;
|
283
283
|
} else if (textStatus === "abort") {
|
284
|
-
|
284
|
+
abortedByClient = true;
|
285
285
|
} else {
|
286
286
|
failCount += 1;
|
287
287
|
totalAjaxFailures += 1;
|
@@ -290,27 +290,40 @@
|
|
290
290
|
complete: function () {
|
291
291
|
ajaxInProgress = false;
|
292
292
|
|
293
|
-
var
|
293
|
+
var inLongPollingMode = shouldLongPoll();
|
294
|
+
var startNextRequestAfter;
|
294
295
|
try {
|
295
296
|
if (rateLimited) {
|
296
|
-
|
297
|
-
|
298
|
-
|
297
|
+
// Respect `Retry-After` header
|
298
|
+
startNextRequestAfter = Math.max(
|
299
|
+
me.minPollInterval,
|
300
|
+
rateLimitedSeconds * 1000
|
301
|
+
);
|
302
|
+
} else if (abortedByClient) {
|
303
|
+
// Immediately trigger another poll
|
304
|
+
startNextRequestAfter = me.minPollInterval;
|
305
|
+
} else if (failCount > 2) {
|
306
|
+
// Linear backoff up to maxPollInterval
|
307
|
+
startNextRequestAfter = Math.min(
|
308
|
+
me.callbackInterval * failCount,
|
309
|
+
me.maxPollInterval
|
310
|
+
);
|
311
|
+
} else if (inLongPollingMode && gotData) {
|
312
|
+
// Immediately trigger another poll
|
313
|
+
startNextRequestAfter = me.minPollInterval;
|
299
314
|
} else {
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
if (interval > me.maxPollInterval) {
|
307
|
-
interval = me.maxPollInterval;
|
308
|
-
}
|
315
|
+
// Trigger next poll N seconds after the last one **started**
|
316
|
+
var targetRequestInterval = inLongPollingMode
|
317
|
+
? me.callbackInterval
|
318
|
+
: me.backgroundCallbackInterval;
|
319
|
+
|
320
|
+
var elapsedSinceLastAjaxStarted = new Date() - lastAjaxStartedAt;
|
309
321
|
|
310
|
-
|
322
|
+
startNextRequestAfter =
|
323
|
+
targetRequestInterval - elapsedSinceLastAjaxStarted;
|
311
324
|
|
312
|
-
if (
|
313
|
-
|
325
|
+
if (startNextRequestAfter < 100) {
|
326
|
+
startNextRequestAfter = 100;
|
314
327
|
}
|
315
328
|
}
|
316
329
|
} catch (e) {
|
@@ -328,7 +341,7 @@
|
|
328
341
|
pollTimeout = setTimeout(function () {
|
329
342
|
pollTimeout = null;
|
330
343
|
poll();
|
331
|
-
},
|
344
|
+
}, startNextRequestAfter);
|
332
345
|
}
|
333
346
|
|
334
347
|
me.longPoll = null;
|
@@ -367,7 +380,9 @@
|
|
367
380
|
totalAjaxFailures
|
368
381
|
);
|
369
382
|
console.log(
|
370
|
-
"Last ajax call: " +
|
383
|
+
"Last ajax call: " +
|
384
|
+
(new Date() - lastAjaxStartedAt) / 1000 +
|
385
|
+
" seconds ago"
|
371
386
|
);
|
372
387
|
},
|
373
388
|
|
data/lib/message_bus/version.rb
CHANGED