message_bus 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of message_bus might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG +8 -0
- data/README.md +3 -0
- data/assets/message-bus.js +39 -3
- data/lib/message_bus/version.rb +1 -1
- data/spec/assets/message-bus.spec.js +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d2bee95bc6938bb37f780cf48bccd6481f2bca144c6672acac69e6d3e1ef176b
|
4
|
+
data.tar.gz: 387450399296441956030b46054a48b2f996c02e51eeb32e5bc181fa03d8b6d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a87dd71aba2740acd7dd326b9f9d2d8cf3b51c33f2c498bbb128346ed52fc2483f52b9135d5320c8ce3d025d2cb7357260d78b8d5963600256cb62704bfb173
|
7
|
+
data.tar.gz: db86f4a8d2b3949ced575612eac992d9d878abe836ee818340ef2045486a0debc816600db95ffb19a497acf3371e673473fe7bcf5d54f48cbd7b1505db8bc791
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
09-01-2018
|
2
|
+
|
3
|
+
- Version 2.1.2
|
4
|
+
|
5
|
+
- FEATURE: minHiddenPollInterval set to 1500ms out of the box, ensures we never do hidden tab
|
6
|
+
polls at a high rate if tons of tabs are open
|
7
|
+
- FEATURE: added random 500ms to delayed polls to increase tab entropy
|
8
|
+
|
1
9
|
18-12-2017
|
2
10
|
|
3
11
|
- Version 2.1.1
|
data/README.md
CHANGED
@@ -239,6 +239,9 @@ alwaysLongPoll|false|For debugging you may want to disable the "is browser in ba
|
|
239
239
|
baseUrl|/|If message bus is mounted in a subdirectory of different domain, you may configure it to perform requests there
|
240
240
|
ajax|$.ajax or XMLHttpRequest|MessageBus will first attempt to use jQuery and then fallback to a plain XMLHttpRequest version that's contained in the `message-bus-ajax.js` file. `message-bus-ajax.js` must be loaded after `message-bus.js` for it to be used.
|
241
241
|
headers|{}|Extra headers to be include with request. Properties and values of object must be valid values for HTTP Headers, i.e. no spaces and control characters.
|
242
|
+
minHiddenPollInterval|1500|Time to wait between poll requests performed by background or hidden tabs and windows, shared state via localStorage
|
243
|
+
enableChunkedEncoding|true|Allow streaming of message bus data over the HTTP channel
|
244
|
+
|
242
245
|
**API**:
|
243
246
|
|
244
247
|
`MessageBus.diagnostics()` : Returns a log that may be used for diagnostics on the status of message bus
|
data/assets/message-bus.js
CHANGED
@@ -48,6 +48,32 @@
|
|
48
48
|
}
|
49
49
|
};
|
50
50
|
|
51
|
+
var hasLocalStorage = (function() {
|
52
|
+
try {
|
53
|
+
localStorage.setItem("mbTestLocalStorage", Date.now());
|
54
|
+
localStorage.removeItem("mbTestLocalStorage");
|
55
|
+
return true;
|
56
|
+
} catch(e) {
|
57
|
+
return false;
|
58
|
+
}
|
59
|
+
})();
|
60
|
+
|
61
|
+
var updateLastAjax = function() {
|
62
|
+
if (hasLocalStorage) {
|
63
|
+
localStorage.setItem("__mbLastAjax", Date.now());
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
var hiddenTabShouldWait = function() {
|
68
|
+
if (hasLocalStorage && isHidden()) {
|
69
|
+
var lastAjaxCall = parseInt(localStorage.getItem("__mbLastAjax"), 10);
|
70
|
+
var deltaAjax = Date.now() - lastAjaxCall;
|
71
|
+
|
72
|
+
return deltaAjax >= 0 && deltaAjax < me.minHiddenPollInterval;
|
73
|
+
}
|
74
|
+
return false;
|
75
|
+
}
|
76
|
+
|
51
77
|
var hasonprogress = (new XMLHttpRequest()).onprogress === null;
|
52
78
|
var allowChunked = function(){
|
53
79
|
return me.enableChunkedEncoding && hasonprogress;
|
@@ -182,6 +208,9 @@
|
|
182
208
|
if (!me.ajax){
|
183
209
|
throw new Error("Either jQuery or the ajax adapter must be loaded");
|
184
210
|
}
|
211
|
+
|
212
|
+
updateLastAjax();
|
213
|
+
|
185
214
|
var req = me.ajax({
|
186
215
|
url: me.baseUrl + "message-bus/" + me.clientId + "/poll" + (!longPoll ? "?dlp=t" : ""),
|
187
216
|
data: data,
|
@@ -260,7 +289,10 @@
|
|
260
289
|
}
|
261
290
|
}
|
262
291
|
|
263
|
-
pollTimeout = setTimeout(function(){
|
292
|
+
pollTimeout = setTimeout(function(){
|
293
|
+
pollTimeout = null;
|
294
|
+
poll();
|
295
|
+
}, interval);
|
264
296
|
me.longPoll = null;
|
265
297
|
}
|
266
298
|
});
|
@@ -269,6 +301,8 @@
|
|
269
301
|
};
|
270
302
|
|
271
303
|
me = {
|
304
|
+
/* shared between all tabs */
|
305
|
+
minHiddenPollInterval: 1500,
|
272
306
|
enableChunkedEncoding: true,
|
273
307
|
enableLongPolling: true,
|
274
308
|
callbackInterval: 15000,
|
@@ -322,9 +356,11 @@
|
|
322
356
|
return;
|
323
357
|
}
|
324
358
|
|
325
|
-
if (callbacks.length === 0) {
|
359
|
+
if (callbacks.length === 0 || hiddenTabShouldWait()) {
|
326
360
|
if(!delayPollTimeout) {
|
327
|
-
delayPollTimeout = setTimeout(function(){
|
361
|
+
delayPollTimeout = setTimeout(function() {
|
362
|
+
delayPollTimeout = null; poll();
|
363
|
+
}, parseInt(500 + Math.random() * 500));
|
328
364
|
}
|
329
365
|
return;
|
330
366
|
}
|
data/lib/message_bus/version.rb
CHANGED
@@ -40,11 +40,11 @@ describe("Messagebus", function() {
|
|
40
40
|
expect(spec.MockedXMLHttpRequest.prototype.send).toHaveBeenCalled()
|
41
41
|
expect(onMessageSpy).not.toHaveBeenCalled()
|
42
42
|
MessageBus.resume()
|
43
|
-
},
|
43
|
+
}, 1010) // greater than delayPollTimeout of 500 + 500 random
|
44
44
|
setTimeout(function(){
|
45
45
|
expect(onMessageSpy).toHaveBeenCalled()
|
46
46
|
done()
|
47
|
-
},
|
47
|
+
}, 1050) // greater than first timeout above
|
48
48
|
});
|
49
49
|
|
50
50
|
it('can unsubscribe from callbacks', function(done){
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: message_bus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
142
|
version: '0'
|
143
143
|
requirements: []
|
144
144
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.
|
145
|
+
rubygems_version: 2.7.3
|
146
146
|
signing_key:
|
147
147
|
specification_version: 4
|
148
148
|
summary: ''
|