message_bus 2.0.0.beta.10 → 2.0.0.beta.11

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of message_bus might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee67b1dcfb1b1f1afce37ad50c8bb2242576e3fd
4
- data.tar.gz: f7c70f3a069c9ab56797864ab3955fed281db541
3
+ metadata.gz: bba5fb421894dd1df061a833b867704fd65f78f7
4
+ data.tar.gz: 535463d41c2f848a9ee25fa35ae31ff37aa2daa9
5
5
  SHA512:
6
- metadata.gz: 751fafbfae6c1f9238f6a3ce1493ad5b507ae0ad2298a70d7bd6419cd72900b8a43418ec74f66ec4bdc0348112b5cb51f92aa133ad94f3a44cfddf1008c0d900
7
- data.tar.gz: ee216ed5d53ad8cd1282bf3f5548aadde126774e4a92f071e5c96a9939b5f546eeb0cc3c694c603585a0b46ffc7f841b8faafe1af2d428d9e077dbd21c52b850
6
+ metadata.gz: 05fef4c57f69fee9b0b9b122fb2127bc844004cb2f82f6130c72221b86e643df03d5a5b2a7e14b2447bc00a4917c9bca4984358ca42e5f8692baff07ca8770c4
7
+ data.tar.gz: ee07091a7cb445e829a03af5811c79b40023f3b208bfa7004a35fd4c5f3234713908734e582a91eea24f37bbd3c33853ca8989d714036b8f2420001f92b07157
data/CHANGELOG CHANGED
@@ -1,5 +1,10 @@
1
1
  11-05-2016
2
2
 
3
+ - Version 2.0.0.beta.11
4
+ - Fix: for https://github.com/rubygems/rubygems/issues/1448 which is still broken, build under Ruby 2.0
5
+
6
+ 11-05-2016
7
+
3
8
  - Version 2.0.0.beta.10
4
9
  - Fix: for https://github.com/rubygems/rubygems/issues/1448
5
10
 
@@ -1,3 +1,3 @@
1
1
  module MessageBus
2
- VERSION = "2.0.0.beta.10"
2
+ VERSION = "2.0.0.beta.11"
3
3
  end
@@ -0,0 +1,44 @@
1
+ // A bare-bones implementation of $.ajax that MessageBus will use
2
+ // as a fallback if jQuery is not present
3
+ //
4
+ // Only implements methods & options used by MessageBus
5
+ (function(global, undefined) {
6
+ 'use strict';
7
+ if (!global.MessageBus){
8
+ throw new Error("MessageBus must be loaded before the ajax adapter");
9
+ }
10
+
11
+ var cacheBuster = Math.random() * 10000 | 0;
12
+
13
+ global.MessageBus.ajax = function(options){
14
+ var XHRImpl = (global.MessageBus && global.MessageBus.xhrImplementation) || global.XMLHttpRequest;
15
+ var xhr = new XHRImpl();
16
+ xhr.dataType = options.dataType;
17
+ var url = options.url;
18
+ if (!options.cache){
19
+ url += ((-1 == url.indexOf('?')) ? '?' : '&') + '_=' + (cacheBuster++)
20
+ }
21
+ xhr.open('POST', url);
22
+ for (var name in options.headers){
23
+ xhr.setRequestHeader(name, options.headers[name]);
24
+ }
25
+ xhr.setRequestHeader('Content-Type', 'application/json');
26
+ if (options.messageBus.chunked){
27
+ options.messageBus.onProgressListener(xhr);
28
+ }
29
+ xhr.onreadystatechange = function(){
30
+ if (xhr.readyState === 4){
31
+ var status = xhr.status;
32
+ if (status >= 200 && status < 300 || status === 304){
33
+ options.success(xhr.responseText);
34
+ } else {
35
+ options.error(xhr, xhr.statusText);
36
+ }
37
+ options.complete();
38
+ }
39
+ }
40
+ xhr.send(JSON.stringify(options.data));
41
+ return xhr;
42
+ };
43
+
44
+ })(window);
@@ -0,0 +1,418 @@
1
+ /*jshint bitwise: false*/
2
+ (function(global, document, undefined) {
3
+ 'use strict';
4
+ var previousMessageBus = global.MessageBus;
5
+
6
+ // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
7
+ var callbacks, clientId, failCount, shouldLongPoll, queue, responseCallbacks, uniqueId, baseUrl;
8
+ var me, started, stopped, longPoller, pollTimeout, paused, later, jQuery, interval, chunkedBackoff;
9
+
10
+ uniqueId = function() {
11
+ return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
12
+ var r, v;
13
+ r = Math.random() * 16 | 0;
14
+ v = c === 'x' ? r : (r & 0x3 | 0x8);
15
+ return v.toString(16);
16
+ });
17
+ };
18
+
19
+ clientId = uniqueId();
20
+ responseCallbacks = {};
21
+ callbacks = [];
22
+ queue = [];
23
+ interval = null;
24
+ failCount = 0;
25
+ baseUrl = "/";
26
+ paused = false;
27
+ later = [];
28
+ chunkedBackoff = 0;
29
+ jQuery = global.jQuery;
30
+ var hiddenProperty;
31
+
32
+ (function(){
33
+ var prefixes = ["","webkit","ms","moz"];
34
+ for(var i=0; i<prefixes.length; i++) {
35
+ var prefix = prefixes[i];
36
+ var check = prefix + (prefix === "" ? "hidden" : "Hidden");
37
+ if(document[check] !== undefined ){
38
+ hiddenProperty = check;
39
+ }
40
+ }
41
+ })();
42
+
43
+ var isHidden = function() {
44
+ if (hiddenProperty !== undefined){
45
+ return document[hiddenProperty];
46
+ } else {
47
+ return !document.hasFocus;
48
+ }
49
+ };
50
+
51
+ var hasonprogress = (new XMLHttpRequest()).onprogress === null;
52
+ var allowChunked = function(){
53
+ return me.enableChunkedEncoding && hasonprogress;
54
+ };
55
+
56
+ shouldLongPoll = function() {
57
+ return me.alwaysLongPoll || !isHidden();
58
+ };
59
+
60
+ var totalAjaxFailures = 0;
61
+ var totalAjaxCalls = 0;
62
+ var lastAjax;
63
+
64
+ var processMessages = function(messages) {
65
+ var gotData = false;
66
+ if (!messages) return false; // server unexpectedly closed connection
67
+
68
+ for (var i=0; i<messages.length; i++) {
69
+ var message = messages[i];
70
+ gotData = true;
71
+ for (var j=0; j<callbacks.length; j++) {
72
+ var callback = callbacks[j];
73
+ if (callback.channel === message.channel) {
74
+ callback.last_id = message.message_id;
75
+ try {
76
+ callback.func(message.data);
77
+ }
78
+ catch(e){
79
+ if(console.log) {
80
+ console.log("MESSAGE BUS FAIL: callback " + callback.channel + " caused exception " + e.message);
81
+ }
82
+ }
83
+ }
84
+ if (message.channel === "/__status") {
85
+ if (message.data[callback.channel] !== undefined) {
86
+ callback.last_id = message.data[callback.channel];
87
+ }
88
+ }
89
+ }
90
+ }
91
+
92
+ return gotData;
93
+ };
94
+
95
+ var reqSuccess = function(messages) {
96
+ failCount = 0;
97
+ if (paused) {
98
+ if (messages) {
99
+ for (var i=0; i<messages.length; i++) {
100
+ later.push(messages[i]);
101
+ }
102
+ }
103
+ } else {
104
+ return processMessages(messages);
105
+ }
106
+ return false;
107
+ };
108
+
109
+ longPoller = function(poll,data){
110
+ var gotData = false;
111
+ var aborted = false;
112
+ lastAjax = new Date();
113
+ totalAjaxCalls += 1;
114
+ data.__seq = totalAjaxCalls;
115
+
116
+ var longPoll = shouldLongPoll() && me.enableLongPolling;
117
+ var chunked = longPoll && allowChunked();
118
+ if (chunkedBackoff > 0) {
119
+ chunkedBackoff--;
120
+ chunked = false;
121
+ }
122
+
123
+ var headers = {
124
+ 'X-SILENCE-LOGGER': 'true'
125
+ };
126
+ for (var name in me.headers){
127
+ headers[name] = me.headers[name];
128
+ }
129
+
130
+ if (!chunked){
131
+ headers["Dont-Chunk"] = 'true';
132
+ }
133
+
134
+ var dataType = chunked ? "text" : "json";
135
+
136
+ var handle_progress = function(payload, position) {
137
+
138
+ var separator = "\r\n|\r\n";
139
+ var endChunk = payload.indexOf(separator, position);
140
+
141
+ if (endChunk === -1) {
142
+ return position;
143
+ }
144
+
145
+ var chunk = payload.substring(position, endChunk);
146
+ chunk = chunk.replace(/\r\n\|\|\r\n/g, separator);
147
+
148
+ try {
149
+ reqSuccess(JSON.parse(chunk));
150
+ } catch(e) {
151
+ if (console.log) {
152
+ console.log("FAILED TO PARSE CHUNKED REPLY");
153
+ console.log(data);
154
+ }
155
+ }
156
+
157
+ return handle_progress(payload, endChunk + separator.length);
158
+ }
159
+
160
+ var disableChunked = function(){
161
+ if (me.longPoll) {
162
+ me.longPoll.abort();
163
+ chunkedBackoff = 30;
164
+ }
165
+ };
166
+
167
+ var setOnProgressListener = function(xhr) {
168
+ var position = 0;
169
+ // if it takes longer than 3000 ms to get first chunk, we have some proxy
170
+ // this is messing with us, so just backoff from using chunked for now
171
+ var chunkedTimeout = setTimeout(disableChunked,3000);
172
+ xhr.onprogress = function () {
173
+ clearTimeout(chunkedTimeout);
174
+ if(xhr.getResponseHeader('Content-Type') === 'application/json; charset=utf-8') {
175
+ // not chunked we are sending json back
176
+ chunked = false;
177
+ return;
178
+ }
179
+ position = handle_progress(xhr.responseText, position);
180
+ }
181
+ };
182
+ if (!me.ajax){
183
+ throw new Error("Either jQuery or the ajax adapter must be loaded");
184
+ }
185
+ var req = me.ajax({
186
+ url: me.baseUrl + "message-bus/" + me.clientId + "/poll" + (!longPoll ? "?dlp=t" : ""),
187
+ data: data,
188
+ cache: false,
189
+ dataType: dataType,
190
+ type: 'POST',
191
+ headers: headers,
192
+ messageBus: {
193
+ chunked: chunked,
194
+ onProgressListener: function(xhr) {
195
+ var position = 0;
196
+ // if it takes longer than 3000 ms to get first chunk, we have some proxy
197
+ // this is messing with us, so just backoff from using chunked for now
198
+ var chunkedTimeout = setTimeout(disableChunked,3000);
199
+ return xhr.onprogress = function () {
200
+ clearTimeout(chunkedTimeout);
201
+ if(xhr.getResponseHeader('Content-Type') === 'application/json; charset=utf-8') {
202
+ chunked = false; // not chunked, we are sending json back
203
+ } else {
204
+ position = handle_progress(xhr.responseText, position);
205
+ }
206
+ }
207
+ }
208
+ },
209
+ xhr: function() {
210
+ var xhr = jQuery.ajaxSettings.xhr();
211
+ if (!chunked) {
212
+ return xhr;
213
+ }
214
+ this.messageBus.onProgressListener(xhr);
215
+ return xhr;
216
+ },
217
+ success: function(messages) {
218
+ if (!chunked) {
219
+ // we may have requested text so jQuery will not parse
220
+ if (typeof(messages) === "string") {
221
+ messages = JSON.parse(messages);
222
+ }
223
+ gotData = reqSuccess(messages);
224
+ }
225
+ },
226
+ error: function(xhr, textStatus, err) {
227
+ if(textStatus === "abort") {
228
+ aborted = true;
229
+ } else {
230
+ failCount += 1;
231
+ totalAjaxFailures += 1;
232
+ }
233
+ },
234
+ complete: function() {
235
+ var interval;
236
+ try {
237
+ if (gotData || aborted) {
238
+ interval = 100;
239
+ } else {
240
+ interval = me.callbackInterval;
241
+ if (failCount > 2) {
242
+ interval = interval * failCount;
243
+ } else if (!shouldLongPoll()) {
244
+ interval = me.backgroundCallbackInterval;
245
+ }
246
+ if (interval > me.maxPollInterval) {
247
+ interval = me.maxPollInterval;
248
+ }
249
+
250
+ interval -= (new Date() - lastAjax);
251
+
252
+ if (interval < 100) {
253
+ interval = 100;
254
+ }
255
+ }
256
+ } catch(e) {
257
+ if(console.log && e.message) {
258
+ console.log("MESSAGE BUS FAIL: " + e.message);
259
+ }
260
+ }
261
+
262
+ pollTimeout = setTimeout(function(){pollTimeout=null; poll();}, interval);
263
+ me.longPoll = null;
264
+ }
265
+ });
266
+
267
+ return req;
268
+ };
269
+
270
+ me = {
271
+ enableChunkedEncoding: true,
272
+ enableLongPolling: true,
273
+ callbackInterval: 15000,
274
+ backgroundCallbackInterval: 60000,
275
+ maxPollInterval: 3 * 60 * 1000,
276
+ callbacks: callbacks,
277
+ clientId: clientId,
278
+ alwaysLongPoll: false,
279
+ baseUrl: baseUrl,
280
+ headers: {},
281
+ ajax: (jQuery && jQuery.ajax),
282
+ noConflict: function(){
283
+ global.MessageBus = global.MessageBus.previousMessageBus;
284
+ return this;
285
+ },
286
+ diagnostics: function(){
287
+ console.log("Stopped: " + stopped + " Started: " + started);
288
+ console.log("Current callbacks");
289
+ console.log(callbacks);
290
+ console.log("Total ajax calls: " + totalAjaxCalls + " Recent failure count: " + failCount + " Total failures: " + totalAjaxFailures);
291
+ console.log("Last ajax call: " + (new Date() - lastAjax) / 1000 + " seconds ago") ;
292
+ },
293
+
294
+ pause: function() {
295
+ paused = true;
296
+ },
297
+
298
+ resume: function() {
299
+ paused = false;
300
+ processMessages(later);
301
+ later = [];
302
+ },
303
+
304
+ stop: function() {
305
+ stopped = true;
306
+ started = false;
307
+ },
308
+
309
+ // Start polling
310
+ start: function() {
311
+ var poll, delayPollTimeout;
312
+
313
+ if (started) return;
314
+ started = true;
315
+ stopped = false;
316
+
317
+ poll = function() {
318
+ var data;
319
+
320
+ if(stopped) {
321
+ return;
322
+ }
323
+
324
+ if (callbacks.length === 0) {
325
+ if(!delayPollTimeout) {
326
+ delayPollTimeout = setTimeout(function(){ delayPollTimeout = null; poll();}, 500);
327
+ }
328
+ return;
329
+ }
330
+
331
+ data = {};
332
+ for (var i=0;i<callbacks.length;i++) {
333
+ data[callbacks[i].channel] = callbacks[i].last_id;
334
+ }
335
+
336
+ me.longPoll = longPoller(poll,data);
337
+ };
338
+
339
+
340
+ // monitor visibility, issue a new long poll when the page shows
341
+ if(document.addEventListener && 'hidden' in document){
342
+ me.visibilityEvent = global.document.addEventListener('visibilitychange', function(){
343
+ if(!document.hidden && !me.longPoll && pollTimeout){
344
+ clearTimeout(pollTimeout);
345
+ pollTimeout = null;
346
+ poll();
347
+ }
348
+ });
349
+ }
350
+
351
+ poll();
352
+ },
353
+
354
+ // Subscribe to a channel
355
+ subscribe: function(channel, func, lastId) {
356
+
357
+ if(!started && !stopped){
358
+ me.start();
359
+ }
360
+
361
+ if (typeof(lastId) !== "number" || lastId < -1){
362
+ lastId = -1;
363
+ }
364
+ callbacks.push({
365
+ channel: channel,
366
+ func: func,
367
+ last_id: lastId
368
+ });
369
+ if (me.longPoll) {
370
+ me.longPoll.abort();
371
+ }
372
+
373
+ return func;
374
+ },
375
+
376
+ // Unsubscribe from a channel
377
+ unsubscribe: function(channel, func) {
378
+ // TODO allow for globbing in the middle of a channel name
379
+ // like /something/*/something
380
+ // at the moment we only support globbing /something/*
381
+ var glob;
382
+ if (channel.indexOf("*", channel.length - 1) !== -1) {
383
+ channel = channel.substr(0, channel.length - 1);
384
+ glob = true;
385
+ }
386
+
387
+ var removed = false;
388
+
389
+ for (var i=callbacks.length-1; i>=0; i--) {
390
+
391
+ var callback = callbacks[i];
392
+ var keep;
393
+
394
+ if (glob) {
395
+ keep = callback.channel.substr(0, channel.length) !== channel;
396
+ } else {
397
+ keep = callback.channel !== channel;
398
+ }
399
+
400
+ if(!keep && func && callback.func !== func){
401
+ keep = true;
402
+ }
403
+
404
+ if (!keep) {
405
+ callbacks.splice(i,1);
406
+ removed = true;
407
+ }
408
+ }
409
+
410
+ if (removed && me.longPoll) {
411
+ me.longPoll.abort();
412
+ }
413
+
414
+ return removed;
415
+ }
416
+ };
417
+ global.MessageBus = me;
418
+ })(window, document);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: message_bus
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta.10
4
+ version: 2.0.0.beta.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
@@ -14,42 +14,42 @@ dependencies:
14
14
  name: rack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.1.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.1.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: redis
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pg
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: A message bus for rack
@@ -59,8 +59,8 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - ".gitignore"
63
- - ".travis.yml"
62
+ - .gitignore
63
+ - .travis.yml
64
64
  - CHANGELOG
65
65
  - Gemfile
66
66
  - Guardfile
@@ -130,17 +130,17 @@ require_paths:
130
130
  - lib
131
131
  required_ruby_version: !ruby/object:Gem::Requirement
132
132
  requirements:
133
- - - ">="
133
+ - - '>='
134
134
  - !ruby/object:Gem::Version
135
135
  version: 1.9.3
136
136
  required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  requirements:
138
- - - ">"
138
+ - - '>'
139
139
  - !ruby/object:Gem::Version
140
140
  version: 1.3.1
141
141
  requirements: []
142
142
  rubyforge_project:
143
- rubygems_version: 2.6.4
143
+ rubygems_version: 2.0.14
144
144
  signing_key:
145
145
  specification_version: 4
146
146
  summary: ''
@@ -1 +0,0 @@
1
- ../../../assets/message-bus-ajax.js
@@ -1 +0,0 @@
1
- ../../../assets/message-bus.js