message_bus 0.9.6 → 1.0.0
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 +4 -4
- data/CHANGELOG +5 -0
- data/assets/message-bus.js +24 -57
- data/lib/message_bus.rb +1 -1
- data/lib/message_bus/version.rb +1 -1
- data/vendor/assets/javascripts/message-bus.js +24 -57
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 540d941673f27bbce348815bdc0e76b5dda46f54
|
4
|
+
data.tar.gz: 7497c9ff05c2c0752f40dd4e11fe892fecaef57e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d139e29977062c4072488a6b3d49dbf3795aa7d0a2ffedb51d80f6b7f5a0b73d432a7d2d467a1a0e70fc57accd1d8214cb5245e8864c7eadb846d298257c1f7
|
7
|
+
data.tar.gz: 29913ebc677903bc51f89e94b01ae1c357b349ba154615131dfd682ee26007bcf59f7cf2bca22fae54ec766822913b4c5391118397fb8f5dec8e4bdf433f32e0
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
22-09-2014
|
2
|
+
- Version 1.0.0
|
3
|
+
- Feature: add backgroundCallbackInterval - interval to send polls when page is in the background
|
4
|
+
- Feature: issue a long poll as soon as page moves into the foreground
|
5
|
+
|
1
6
|
11-08-2014
|
2
7
|
- Version 0.9.5
|
3
8
|
- Fix: release db connection a lot earlier for long polling (rails defer closes)
|
data/assets/message-bus.js
CHANGED
@@ -29,55 +29,6 @@ window.MessageBus = (function() {
|
|
29
29
|
failCount = 0;
|
30
30
|
baseUrl = "/";
|
31
31
|
|
32
|
-
/* TODO: The plan is to force a long poll as soon as page becomes visible
|
33
|
-
// MIT based off https://github.com/mathiasbynens/jquery-visibility/blob/master/jquery-visibility.js
|
34
|
-
initVisibilityTracking = function(window, document, $, undefined) {
|
35
|
-
var prefix;
|
36
|
-
var property;
|
37
|
-
// In Opera, `'onfocusin' in document == true`, hence the extra `hasFocus` check to detect IE-like behavior
|
38
|
-
var eventName = 'onfocusin' in document && 'hasFocus' in document ? 'focusin focusout' : 'focus blur';
|
39
|
-
var prefixes = ['webkit', 'o', 'ms', 'moz', ''];
|
40
|
-
var $event = $.event;
|
41
|
-
|
42
|
-
while ((prefix = prefixes.pop()) !== undefined) {
|
43
|
-
property = (prefix ? prefix + 'H': 'h') + 'idden';
|
44
|
-
var supportsVisibility = typeof document[property] === 'boolean';
|
45
|
-
if (supportsVisibility) {
|
46
|
-
eventName = prefix + 'visibilitychange';
|
47
|
-
break;
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
$(/blur$/.test(eventName) ? window : document).on(eventName, function(event) {
|
52
|
-
var type = event.type;
|
53
|
-
var originalEvent = event.originalEvent;
|
54
|
-
|
55
|
-
// Avoid errors from triggered native events for which `originalEvent` is
|
56
|
-
// not available.
|
57
|
-
if (!originalEvent) {
|
58
|
-
return;
|
59
|
-
}
|
60
|
-
|
61
|
-
var toElement = originalEvent.toElement;
|
62
|
-
|
63
|
-
// If it's a `{focusin,focusout}` event (IE), `fromElement` and `toElement`
|
64
|
-
// should both be `null` or `undefined`; else, the page visibility hasn't
|
65
|
-
// changed, but the user just clicked somewhere in the doc. In IE9, we need
|
66
|
-
// to check the `relatedTarget` property instead.
|
67
|
-
if (
|
68
|
-
!/^focus./.test(type) || (
|
69
|
-
toElement === undefined &&
|
70
|
-
originalEvent.fromElement === undefined &&
|
71
|
-
originalEvent.relatedTarget === undefined
|
72
|
-
)
|
73
|
-
) {
|
74
|
-
visibilityChanged(property && document[property] || /^(?:blur|focusout)$/.test(type) ? 'hide' : 'show');
|
75
|
-
}
|
76
|
-
});
|
77
|
-
|
78
|
-
};
|
79
|
-
*/
|
80
|
-
|
81
32
|
var hiddenProperty;
|
82
33
|
|
83
34
|
$.each(["","webkit","ms","moz","ms"], function(index, prefix){
|
@@ -108,8 +59,9 @@ window.MessageBus = (function() {
|
|
108
59
|
var aborted = false;
|
109
60
|
lastAjax = new Date();
|
110
61
|
totalAjaxCalls += 1;
|
111
|
-
|
112
|
-
return $.ajax(
|
62
|
+
|
63
|
+
return $.ajax({
|
64
|
+
url: me.baseUrl + "message-bus/" + me.clientId + "/poll?" + (!shouldLongPoll() || !me.enableLongPolling ? "dlp=t" : ""),
|
113
65
|
data: data,
|
114
66
|
cache: false,
|
115
67
|
dataType: 'json',
|
@@ -160,9 +112,7 @@ window.MessageBus = (function() {
|
|
160
112
|
if (failCount > 2) {
|
161
113
|
interval = interval * failCount;
|
162
114
|
} else if (!shouldLongPoll()) {
|
163
|
-
|
164
|
-
// we will need to fine tune this
|
165
|
-
interval = interval * 4;
|
115
|
+
interval = me.backgroundCallbackInterval;
|
166
116
|
}
|
167
117
|
if (interval > me.maxPollInterval) {
|
168
118
|
interval = me.maxPollInterval;
|
@@ -180,7 +130,7 @@ window.MessageBus = (function() {
|
|
180
130
|
}
|
181
131
|
}
|
182
132
|
|
183
|
-
pollTimeout = setTimeout(poll, interval);
|
133
|
+
pollTimeout = setTimeout(function(){pollTimeout=null; poll();}, interval);
|
184
134
|
me.longPoll = null;
|
185
135
|
}
|
186
136
|
});
|
@@ -189,6 +139,7 @@ window.MessageBus = (function() {
|
|
189
139
|
me = {
|
190
140
|
enableLongPolling: true,
|
191
141
|
callbackInterval: 15000,
|
142
|
+
backgroundCallbackInterval: 60000,
|
192
143
|
maxPollInterval: 3 * 60 * 1000,
|
193
144
|
callbacks: callbacks,
|
194
145
|
clientId: clientId,
|
@@ -210,7 +161,7 @@ window.MessageBus = (function() {
|
|
210
161
|
|
211
162
|
// Start polling
|
212
163
|
start: function(opts) {
|
213
|
-
var poll;
|
164
|
+
var poll, delayPollTimeout;
|
214
165
|
|
215
166
|
if (started) return;
|
216
167
|
started = true;
|
@@ -226,7 +177,9 @@ window.MessageBus = (function() {
|
|
226
177
|
}
|
227
178
|
|
228
179
|
if (callbacks.length === 0) {
|
229
|
-
|
180
|
+
if(!delayPollTimeout) {
|
181
|
+
delayPollTimeout = setTimeout(function(){ delayPollTimeout = null; poll();}, 500);
|
182
|
+
}
|
230
183
|
return;
|
231
184
|
}
|
232
185
|
|
@@ -234,8 +187,22 @@ window.MessageBus = (function() {
|
|
234
187
|
$.each(callbacks, function(_,callback) {
|
235
188
|
data[callback.channel] = callback.last_id;
|
236
189
|
});
|
190
|
+
|
237
191
|
me.longPoll = longPoller(poll,data);
|
238
192
|
};
|
193
|
+
|
194
|
+
|
195
|
+
// monitor visibility, issue a new long poll when the page shows
|
196
|
+
if(document.addEventListener && 'hidden' in document){
|
197
|
+
me.visibilityEvent = document.addEventListener('visibilitychange', function(){
|
198
|
+
if(!document.hidden && !me.longPoll && pollTimeout){
|
199
|
+
clearTimeout(pollTimeout);
|
200
|
+
pollTimeout = null;
|
201
|
+
poll();
|
202
|
+
}
|
203
|
+
});
|
204
|
+
}
|
205
|
+
|
239
206
|
poll();
|
240
207
|
},
|
241
208
|
|
data/lib/message_bus.rb
CHANGED
data/lib/message_bus/version.rb
CHANGED
@@ -29,55 +29,6 @@ window.MessageBus = (function() {
|
|
29
29
|
failCount = 0;
|
30
30
|
baseUrl = "/";
|
31
31
|
|
32
|
-
/* TODO: The plan is to force a long poll as soon as page becomes visible
|
33
|
-
// MIT based off https://github.com/mathiasbynens/jquery-visibility/blob/master/jquery-visibility.js
|
34
|
-
initVisibilityTracking = function(window, document, $, undefined) {
|
35
|
-
var prefix;
|
36
|
-
var property;
|
37
|
-
// In Opera, `'onfocusin' in document == true`, hence the extra `hasFocus` check to detect IE-like behavior
|
38
|
-
var eventName = 'onfocusin' in document && 'hasFocus' in document ? 'focusin focusout' : 'focus blur';
|
39
|
-
var prefixes = ['webkit', 'o', 'ms', 'moz', ''];
|
40
|
-
var $event = $.event;
|
41
|
-
|
42
|
-
while ((prefix = prefixes.pop()) !== undefined) {
|
43
|
-
property = (prefix ? prefix + 'H': 'h') + 'idden';
|
44
|
-
var supportsVisibility = typeof document[property] === 'boolean';
|
45
|
-
if (supportsVisibility) {
|
46
|
-
eventName = prefix + 'visibilitychange';
|
47
|
-
break;
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
$(/blur$/.test(eventName) ? window : document).on(eventName, function(event) {
|
52
|
-
var type = event.type;
|
53
|
-
var originalEvent = event.originalEvent;
|
54
|
-
|
55
|
-
// Avoid errors from triggered native events for which `originalEvent` is
|
56
|
-
// not available.
|
57
|
-
if (!originalEvent) {
|
58
|
-
return;
|
59
|
-
}
|
60
|
-
|
61
|
-
var toElement = originalEvent.toElement;
|
62
|
-
|
63
|
-
// If it's a `{focusin,focusout}` event (IE), `fromElement` and `toElement`
|
64
|
-
// should both be `null` or `undefined`; else, the page visibility hasn't
|
65
|
-
// changed, but the user just clicked somewhere in the doc. In IE9, we need
|
66
|
-
// to check the `relatedTarget` property instead.
|
67
|
-
if (
|
68
|
-
!/^focus./.test(type) || (
|
69
|
-
toElement === undefined &&
|
70
|
-
originalEvent.fromElement === undefined &&
|
71
|
-
originalEvent.relatedTarget === undefined
|
72
|
-
)
|
73
|
-
) {
|
74
|
-
visibilityChanged(property && document[property] || /^(?:blur|focusout)$/.test(type) ? 'hide' : 'show');
|
75
|
-
}
|
76
|
-
});
|
77
|
-
|
78
|
-
};
|
79
|
-
*/
|
80
|
-
|
81
32
|
var hiddenProperty;
|
82
33
|
|
83
34
|
$.each(["","webkit","ms","moz","ms"], function(index, prefix){
|
@@ -108,8 +59,9 @@ window.MessageBus = (function() {
|
|
108
59
|
var aborted = false;
|
109
60
|
lastAjax = new Date();
|
110
61
|
totalAjaxCalls += 1;
|
111
|
-
|
112
|
-
return $.ajax(
|
62
|
+
|
63
|
+
return $.ajax({
|
64
|
+
url: me.baseUrl + "message-bus/" + me.clientId + "/poll?" + (!shouldLongPoll() || !me.enableLongPolling ? "dlp=t" : ""),
|
113
65
|
data: data,
|
114
66
|
cache: false,
|
115
67
|
dataType: 'json',
|
@@ -160,9 +112,7 @@ window.MessageBus = (function() {
|
|
160
112
|
if (failCount > 2) {
|
161
113
|
interval = interval * failCount;
|
162
114
|
} else if (!shouldLongPoll()) {
|
163
|
-
|
164
|
-
// we will need to fine tune this
|
165
|
-
interval = interval * 4;
|
115
|
+
interval = me.backgroundCallbackInterval;
|
166
116
|
}
|
167
117
|
if (interval > me.maxPollInterval) {
|
168
118
|
interval = me.maxPollInterval;
|
@@ -180,7 +130,7 @@ window.MessageBus = (function() {
|
|
180
130
|
}
|
181
131
|
}
|
182
132
|
|
183
|
-
pollTimeout = setTimeout(poll, interval);
|
133
|
+
pollTimeout = setTimeout(function(){pollTimeout=null; poll();}, interval);
|
184
134
|
me.longPoll = null;
|
185
135
|
}
|
186
136
|
});
|
@@ -189,6 +139,7 @@ window.MessageBus = (function() {
|
|
189
139
|
me = {
|
190
140
|
enableLongPolling: true,
|
191
141
|
callbackInterval: 15000,
|
142
|
+
backgroundCallbackInterval: 60000,
|
192
143
|
maxPollInterval: 3 * 60 * 1000,
|
193
144
|
callbacks: callbacks,
|
194
145
|
clientId: clientId,
|
@@ -210,7 +161,7 @@ window.MessageBus = (function() {
|
|
210
161
|
|
211
162
|
// Start polling
|
212
163
|
start: function(opts) {
|
213
|
-
var poll;
|
164
|
+
var poll, delayPollTimeout;
|
214
165
|
|
215
166
|
if (started) return;
|
216
167
|
started = true;
|
@@ -226,7 +177,9 @@ window.MessageBus = (function() {
|
|
226
177
|
}
|
227
178
|
|
228
179
|
if (callbacks.length === 0) {
|
229
|
-
|
180
|
+
if(!delayPollTimeout) {
|
181
|
+
delayPollTimeout = setTimeout(function(){ delayPollTimeout = null; poll();}, 500);
|
182
|
+
}
|
230
183
|
return;
|
231
184
|
}
|
232
185
|
|
@@ -234,8 +187,22 @@ window.MessageBus = (function() {
|
|
234
187
|
$.each(callbacks, function(_,callback) {
|
235
188
|
data[callback.channel] = callback.last_id;
|
236
189
|
});
|
190
|
+
|
237
191
|
me.longPoll = longPoller(poll,data);
|
238
192
|
};
|
193
|
+
|
194
|
+
|
195
|
+
// monitor visibility, issue a new long poll when the page shows
|
196
|
+
if(document.addEventListener && 'hidden' in document){
|
197
|
+
me.visibilityEvent = document.addEventListener('visibilitychange', function(){
|
198
|
+
if(!document.hidden && !me.longPoll && pollTimeout){
|
199
|
+
clearTimeout(pollTimeout);
|
200
|
+
pollTimeout = null;
|
201
|
+
poll();
|
202
|
+
}
|
203
|
+
});
|
204
|
+
}
|
205
|
+
|
239
206
|
poll();
|
240
207
|
},
|
241
208
|
|
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: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|