pusher-fake 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4567bf9d8226e1d07e7f93382ae2f414a62888e
4
- data.tar.gz: 8524195e9f243534d9a85b3d7c0a09c61c4fc252
3
+ metadata.gz: 5aa94db2edd0797091dc88becfdb8ae831846e76
4
+ data.tar.gz: 5ab407e3e83ea0755b36a3548d226e40f957979e
5
5
  SHA512:
6
- metadata.gz: 90f3394b3891466ed3dd2b5c4dab7a6fba6d437608a7d8b4bf96702584b829a14fdb2d84ab614cf23dd74fb3fb118789f616326e259bae52ba07bff3302dfb6e
7
- data.tar.gz: e67ed85fd2a1bec93104ab4102ca148b8d295f51056babd2a8b5c13e4396b80ab53663ad66567b21f2a83d2136e8709d44142a3b7e5df86f5d6d773f110fdb11
6
+ metadata.gz: 8fd3d7eae0e62bd30d631da88088720dbaff65c689b24bdd9016d2029841922e78706f83f68860b9488818a15e51965fff72bd4af0b3c85bd44c2efa29f878cd
7
+ data.tar.gz: 05ce0a03d04b78d02a0da9ae9a9ceee8766b3b67ae1833f58c6d0e8499f3780868cd89698237d4a9288c1fa582e0927f2a5db7e7c22939464af48a90499dccc1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Pusher JavaScript Library v2.1.3
2
+ * Pusher JavaScript Library v2.1.5
3
3
  * http://pusherapp.com/
4
4
  *
5
5
  * Copyright 2013, Pusher
@@ -86,6 +86,7 @@
86
86
  });
87
87
 
88
88
  Pusher.instances.push(this);
89
+ this.timeline.info({ instances: Pusher.instances.length });
89
90
 
90
91
  if (Pusher.isReady) self.connect();
91
92
  }
@@ -128,6 +129,10 @@
128
129
  return this.channels.find(name);
129
130
  };
130
131
 
132
+ prototype.allChannels = function() {
133
+ return this.channels.all();
134
+ };
135
+
131
136
  prototype.connect = function() {
132
137
  this.connection.connect();
133
138
 
@@ -208,6 +213,79 @@
208
213
  this.Pusher = Pusher;
209
214
  }).call(this);
210
215
 
216
+ ;(function() {
217
+ /** Cross-browser compatible timer abstraction.
218
+ *
219
+ * @param {Number} delay
220
+ * @param {Function} callback
221
+ */
222
+ function Timer(delay, callback) {
223
+ var self = this;
224
+
225
+ this.timeout = setTimeout(function() {
226
+ if (self.timeout !== null) {
227
+ callback();
228
+ self.timeout = null;
229
+ }
230
+ }, delay);
231
+ }
232
+ var prototype = Timer.prototype;
233
+
234
+ /** Returns whether the timer is still running.
235
+ *
236
+ * @return {Boolean}
237
+ */
238
+ prototype.isRunning = function() {
239
+ return this.timeout !== null;
240
+ };
241
+
242
+ /** Aborts a timer when it's running. */
243
+ prototype.ensureAborted = function() {
244
+ if (this.timeout) {
245
+ clearTimeout(this.timeout);
246
+ this.timeout = null;
247
+ }
248
+ };
249
+
250
+ Pusher.Timer = Timer;
251
+ }).call(this);
252
+
253
+ ;(function() {
254
+ /** Cross-browser compatible periodic timer abstraction.
255
+ *
256
+ * @param {Number} interval
257
+ * @param {Function} callback
258
+ */
259
+ function PeriodicTimer(interval, callback) {
260
+ var self = this;
261
+
262
+ this.interval = setInterval(function() {
263
+ if (self.interval !== null) {
264
+ callback();
265
+ }
266
+ }, interval);
267
+ }
268
+ var prototype = PeriodicTimer.prototype;
269
+
270
+ /** Returns whether the timer is still running.
271
+ *
272
+ * @return {Boolean}
273
+ */
274
+ prototype.isRunning = function() {
275
+ return this.interval !== null;
276
+ };
277
+
278
+ /** Aborts a timer when it's running. */
279
+ prototype.ensureAborted = function() {
280
+ if (this.interval) {
281
+ clearInterval(this.interval);
282
+ this.interval = null;
283
+ }
284
+ };
285
+
286
+ Pusher.PeriodicTimer = PeriodicTimer;
287
+ }).call(this);
288
+
211
289
  ;(function() {
212
290
  Pusher.Util = {
213
291
  now: function() {
@@ -218,6 +296,10 @@
218
296
  }
219
297
  },
220
298
 
299
+ defer: function(callback) {
300
+ return new Pusher.Timer(0, callback);
301
+ },
302
+
221
303
  /** Merges multiple objects into the target argument.
222
304
  *
223
305
  * For properties that are plain Objects, performs a deep-merge. For the
@@ -281,14 +363,48 @@
281
363
  return -1;
282
364
  },
283
365
 
284
- keys: function(object) {
285
- var result = [];
366
+ /** Applies a function f to all properties of an object.
367
+ *
368
+ * Function f gets 3 arguments passed:
369
+ * - element from the object
370
+ * - key of the element
371
+ * - reference to the object
372
+ *
373
+ * @param {Object} object
374
+ * @param {Function} f
375
+ */
376
+ objectApply: function(object, f) {
286
377
  for (var key in object) {
287
378
  if (Object.prototype.hasOwnProperty.call(object, key)) {
288
- result.push(key);
379
+ f(object[key], key, object);
289
380
  }
290
381
  }
291
- return result;
382
+ },
383
+
384
+ /** Return a list of object's own property keys
385
+ *
386
+ * @param {Object} object
387
+ * @returns {Array}
388
+ */
389
+ keys: function(object) {
390
+ var keys = [];
391
+ Pusher.Util.objectApply(object, function(_, key) {
392
+ keys.push(key);
393
+ });
394
+ return keys;
395
+ },
396
+
397
+ /** Return a list of object's own property values
398
+ *
399
+ * @param {Object} object
400
+ * @returns {Array}
401
+ */
402
+ values: function(object) {
403
+ var values = [];
404
+ Pusher.Util.objectApply(object, function(value) {
405
+ values.push(value);
406
+ });
407
+ return values;
292
408
  },
293
409
 
294
410
  /** Applies a function f to all elements of an array.
@@ -307,24 +423,6 @@
307
423
  }
308
424
  },
309
425
 
310
- /** Applies a function f to all properties of an object.
311
- *
312
- * Function f gets 3 arguments passed:
313
- * - element from the object
314
- * - key of the element
315
- * - reference to the object
316
- *
317
- * @param {Object} object
318
- * @param {Function} f
319
- */
320
- objectApply: function(object, f) {
321
- for (var key in object) {
322
- if (Object.prototype.hasOwnProperty.call(object, key)) {
323
- f(object[key], key, object);
324
- }
325
- }
326
- },
327
-
328
426
  /** Maps all elements of the array and returns the result.
329
427
  *
330
428
  * Function f gets 4 arguments passed:
@@ -357,11 +455,9 @@
357
455
  */
358
456
  mapObject: function(object, f) {
359
457
  var result = {};
360
- for (var key in object) {
361
- if (Object.prototype.hasOwnProperty.call(object, key)) {
362
- result[key] = f(object[key]);
363
- }
364
- }
458
+ Pusher.Util.objectApply(object, function(value, key) {
459
+ result[key] = f(value);
460
+ });
365
461
  return result;
366
462
  },
367
463
 
@@ -400,16 +496,12 @@
400
496
  * @param {Function} f
401
497
  */
402
498
  filterObject: function(object, test) {
403
- test = test || function(value) { return !!value; };
404
-
405
499
  var result = {};
406
- for (var key in object) {
407
- if (Object.prototype.hasOwnProperty.call(object, key)) {
408
- if (test(object[key], key, object, result)) {
409
- result[key] = object[key];
410
- }
500
+ Pusher.Util.objectApply(object, function(value, key) {
501
+ if ((test && test(value, key, object, result)) || Boolean(value)) {
502
+ result[key] = value;
411
503
  }
412
- }
504
+ });
413
505
  return result;
414
506
  },
415
507
 
@@ -420,11 +512,9 @@
420
512
  */
421
513
  flatten: function(object) {
422
514
  var result = [];
423
- for (var key in object) {
424
- if (Object.prototype.hasOwnProperty.call(object, key)) {
425
- result.push([key, object[key]]);
426
- }
427
- }
515
+ Pusher.Util.objectApply(object, function(value, key) {
516
+ result.push([key, value]);
517
+ });
428
518
  return result;
429
519
  },
430
520
 
@@ -509,8 +599,8 @@
509
599
  }).call(this);
510
600
 
511
601
  ;(function() {
512
- Pusher.VERSION = '2.1.3';
513
- Pusher.PROTOCOL = 6;
602
+ Pusher.VERSION = '2.1.5';
603
+ Pusher.PROTOCOL = 7;
514
604
 
515
605
  // DEPRECATED: WS connection parameters
516
606
  Pusher.host = 'ws.pusherapp.com';
@@ -852,79 +942,6 @@
852
942
  }
853
943
  })();
854
944
 
855
- ;(function() {
856
- /** Cross-browser compatible timer abstraction.
857
- *
858
- * @param {Number} delay
859
- * @param {Function} callback
860
- */
861
- function Timer(delay, callback) {
862
- var self = this;
863
-
864
- this.timeout = setTimeout(function() {
865
- if (self.timeout !== null) {
866
- callback();
867
- self.timeout = null;
868
- }
869
- }, delay);
870
- }
871
- var prototype = Timer.prototype;
872
-
873
- /** Returns whether the timer is still running.
874
- *
875
- * @return {Boolean}
876
- */
877
- prototype.isRunning = function() {
878
- return this.timeout !== null;
879
- };
880
-
881
- /** Aborts a timer when it's running. */
882
- prototype.ensureAborted = function() {
883
- if (this.timeout) {
884
- clearTimeout(this.timeout);
885
- this.timeout = null;
886
- }
887
- };
888
-
889
- Pusher.Timer = Timer;
890
- }).call(this);
891
-
892
- ;(function() {
893
- /** Cross-browser compatible periodic timer abstraction.
894
- *
895
- * @param {Number} interval
896
- * @param {Function} callback
897
- */
898
- function PeriodicTimer(interval, callback) {
899
- var self = this;
900
-
901
- this.interval = setInterval(function() {
902
- if (self.interval !== null) {
903
- callback();
904
- }
905
- }, interval);
906
- }
907
- var prototype = PeriodicTimer.prototype;
908
-
909
- /** Returns whether the timer is still running.
910
- *
911
- * @return {Boolean}
912
- */
913
- prototype.isRunning = function() {
914
- return this.interval !== null;
915
- };
916
-
917
- /** Aborts a timer when it's running. */
918
- prototype.ensureAborted = function() {
919
- if (this.interval) {
920
- clearInterval(this.interval);
921
- this.interval = null;
922
- }
923
- };
924
-
925
- Pusher.PeriodicTimer = PeriodicTimer;
926
- }).call(this);
927
-
928
945
  (function() {
929
946
 
930
947
  var Base64 = {
@@ -1142,7 +1159,7 @@
1142
1159
  this.events.push(
1143
1160
  Pusher.Util.extend({}, event, {
1144
1161
  timestamp: Pusher.Util.now(),
1145
- level: level
1162
+ level: (level !== Timeline.INFO ? level : undefined)
1146
1163
  })
1147
1164
  );
1148
1165
  if (this.options.limit && this.events.length > this.options.limit) {
@@ -1170,23 +1187,15 @@
1170
1187
  prototype.send = function(sendJSONP, callback) {
1171
1188
  var self = this;
1172
1189
 
1173
- if (Pusher.Network.isOnline() === false) {
1174
- return false;
1175
- }
1176
-
1177
- var data = {};
1178
- if (self.sent === 0) {
1179
- data = Pusher.Util.extend({
1180
- key: self.key,
1181
- features: self.options.features,
1182
- version: self.options.version
1183
- }, self.options.params || {});
1184
- }
1185
- data.session = self.session;
1186
- data.timeline = self.events;
1187
- data = Pusher.Util.filterObject(data, function(v) {
1188
- return v !== undefined;
1189
- });
1190
+ var data = Pusher.Util.extend({
1191
+ session: self.session,
1192
+ bundle: self.sent + 1,
1193
+ key: self.key,
1194
+ lib: "js",
1195
+ version: self.options.version,
1196
+ features: self.options.features,
1197
+ timeline: self.events
1198
+ }, self.options.params);
1190
1199
 
1191
1200
  self.events = [];
1192
1201
  sendJSONP(data, function(error, result) {
@@ -1226,7 +1235,9 @@
1226
1235
 
1227
1236
  var sendJSONP = function(data, callback) {
1228
1237
  var params = {
1229
- data: data,
1238
+ data: Pusher.Util.filterObject(data, function(v) {
1239
+ return v !== undefined;
1240
+ }),
1230
1241
  url: scheme + (self.host || self.options.host) + self.options.path,
1231
1242
  receiver: Pusher.JSONP
1232
1243
  };
@@ -1331,6 +1342,7 @@
1331
1342
  this.strategy = strategy;
1332
1343
  this.transports = transports;
1333
1344
  this.ttl = options.ttl || 1800*1000;
1345
+ this.encrypted = options.encrypted;
1334
1346
  this.timeline = options.timeline;
1335
1347
  }
1336
1348
  var prototype = CachedStrategy.prototype;
@@ -1340,7 +1352,8 @@
1340
1352
  };
1341
1353
 
1342
1354
  prototype.connect = function(minPriority, callback) {
1343
- var info = fetchTransportInfo();
1355
+ var encrypted = this.encrypted;
1356
+ var info = fetchTransportCache(encrypted);
1344
1357
 
1345
1358
  var strategies = [this.strategy];
1346
1359
  if (info && info.timestamp + this.ttl >= Pusher.Util.now()) {
@@ -1359,7 +1372,7 @@
1359
1372
  minPriority,
1360
1373
  function cb(error, handshake) {
1361
1374
  if (error) {
1362
- flushTransportInfo();
1375
+ flushTransportCache(encrypted);
1363
1376
  if (strategies.length > 0) {
1364
1377
  startTimestamp = Pusher.Util.now();
1365
1378
  runner = strategies.pop().connect(minPriority, cb);
@@ -1367,8 +1380,11 @@
1367
1380
  callback(error);
1368
1381
  }
1369
1382
  } else {
1370
- var latency = Pusher.Util.now() - startTimestamp;
1371
- storeTransportInfo(handshake.transport.name, latency);
1383
+ storeTransportCache(
1384
+ encrypted,
1385
+ handshake.transport.name,
1386
+ Pusher.Util.now() - startTimestamp
1387
+ );
1372
1388
  callback(null, handshake);
1373
1389
  }
1374
1390
  }
@@ -1387,26 +1403,30 @@
1387
1403
  };
1388
1404
  };
1389
1405
 
1390
- function fetchTransportInfo() {
1406
+ function getTransportCacheKey(encrypted) {
1407
+ return "pusherTransport" + (encrypted ? "Encrypted" : "Unencrypted");
1408
+ }
1409
+
1410
+ function fetchTransportCache(encrypted) {
1391
1411
  var storage = Pusher.Util.getLocalStorage();
1392
1412
  if (storage) {
1393
1413
  try {
1394
- var info = storage.pusherTransport;
1395
- if (info) {
1396
- return JSON.parse(info);
1414
+ var serializedCache = storage[getTransportCacheKey(encrypted)];
1415
+ if (serializedCache) {
1416
+ return JSON.parse(serializedCache);
1397
1417
  }
1398
1418
  } catch (e) {
1399
- flushTransportInfo();
1419
+ flushTransportCache(encrypted);
1400
1420
  }
1401
1421
  }
1402
1422
  return null;
1403
1423
  }
1404
1424
 
1405
- function storeTransportInfo(transport, latency) {
1425
+ function storeTransportCache(encrypted, transport, latency) {
1406
1426
  var storage = Pusher.Util.getLocalStorage();
1407
1427
  if (storage) {
1408
1428
  try {
1409
- storage.pusherTransport = JSON.stringify({
1429
+ storage[getTransportCacheKey(encrypted)] = JSON.stringify({
1410
1430
  timestamp: Pusher.Util.now(),
1411
1431
  transport: transport,
1412
1432
  latency: latency
@@ -1417,13 +1437,13 @@
1417
1437
  }
1418
1438
  }
1419
1439
 
1420
- function flushTransportInfo() {
1440
+ function flushTransportCache(encrypted) {
1421
1441
  var storage = Pusher.Util.getLocalStorage();
1422
- if (storage && storage.pusherTransport) {
1442
+ if (storage) {
1423
1443
  try {
1424
- delete storage.pusherTransport;
1444
+ delete storage[getTransportCacheKey(encrypted)];
1425
1445
  } catch (e) {
1426
- storage.pusherTransport = undefined;
1446
+ // catch exceptions raised by localStorage
1427
1447
  }
1428
1448
  }
1429
1449
  }
@@ -1618,6 +1638,13 @@
1618
1638
  var timer = null;
1619
1639
  var runner = null;
1620
1640
 
1641
+ if (options.timeout > 0) {
1642
+ timer = new Pusher.Timer(options.timeout, function() {
1643
+ runner.abort();
1644
+ callback(true);
1645
+ });
1646
+ }
1647
+
1621
1648
  runner = strategy.connect(minPriority, function(error, handshake) {
1622
1649
  if (error && timer && timer.isRunning() && !options.failFast) {
1623
1650
  // advance to the next strategy after the timeout
@@ -1629,13 +1656,6 @@
1629
1656
  callback(error, handshake);
1630
1657
  });
1631
1658
 
1632
- if (options.timeout > 0) {
1633
- timer = new Pusher.Timer(options.timeout, function() {
1634
- runner.abort();
1635
- callback(true);
1636
- });
1637
- }
1638
-
1639
1659
  return {
1640
1660
  abort: function() {
1641
1661
  if (timer) {
@@ -1673,9 +1693,7 @@
1673
1693
  * @returns {Boolean}
1674
1694
  */
1675
1695
  prototype.isSupported = function() {
1676
- return this.transport.isSupported({
1677
- disableFlash: !!this.options.disableFlash
1678
- });
1696
+ return this.transport.isSupported();
1679
1697
  };
1680
1698
 
1681
1699
  /** Launches a connection attempt and returns a strategy runner.
@@ -1684,7 +1702,7 @@
1684
1702
  * @return {Object} strategy runner
1685
1703
  */
1686
1704
  prototype.connect = function(minPriority, callback) {
1687
- if (!this.transport.isSupported()) {
1705
+ if (!this.isSupported()) {
1688
1706
  return failAttempt(new Pusher.Errors.UnsupportedStrategy(), callback);
1689
1707
  } else if (this.priority < minPriority) {
1690
1708
  return failAttempt(new Pusher.Errors.TransportPriorityTooLow(), callback);
@@ -1761,7 +1779,7 @@
1761
1779
  };
1762
1780
 
1763
1781
  function failAttempt(error, callback) {
1764
- new Pusher.Timer(0, function() {
1782
+ Pusher.Util.defer(function() {
1765
1783
  callback(error);
1766
1784
  });
1767
1785
  return {
@@ -1812,6 +1830,7 @@
1812
1830
  this.key = key;
1813
1831
  this.state = "new";
1814
1832
  this.timeline = options.timeline;
1833
+ this.activityTimeout = options.activityTimeout;
1815
1834
  this.id = this.timeline.generateUniqueID();
1816
1835
 
1817
1836
  this.options = {
@@ -1871,7 +1890,7 @@
1871
1890
  this.socket = this.createSocket(url);
1872
1891
  } catch (e) {
1873
1892
  var self = this;
1874
- new Pusher.Timer(0, function() {
1893
+ Pusher.Util.defer(function() {
1875
1894
  self.onError(e);
1876
1895
  self.changeState("closed");
1877
1896
  });
@@ -1925,10 +1944,6 @@
1925
1944
  }
1926
1945
  };
1927
1946
 
1928
- prototype.requestPing = function() {
1929
- this.emit("ping_request");
1930
- };
1931
-
1932
1947
  /** @protected */
1933
1948
  prototype.onOpen = function() {
1934
1949
  this.changeState("open");
@@ -2056,18 +2071,19 @@
2056
2071
  * @param {Object} environment
2057
2072
  * @returns {Boolean}
2058
2073
  */
2059
- FlashTransport.isSupported = function(environment) {
2060
- if (environment && environment.disableFlash) {
2061
- return false;
2062
- }
2074
+ FlashTransport.isSupported = function() {
2063
2075
  try {
2064
2076
  return Boolean(new ActiveXObject('ShockwaveFlash.ShockwaveFlash'));
2065
2077
  } catch (e) {
2066
- return Boolean(
2067
- navigator &&
2068
- navigator.mimeTypes &&
2069
- navigator.mimeTypes["application/x-shockwave-flash"] !== undefined
2070
- );
2078
+ try {
2079
+ return Boolean(
2080
+ navigator &&
2081
+ navigator.mimeTypes &&
2082
+ navigator.mimeTypes["application/x-shockwave-flash"] !== undefined
2083
+ );
2084
+ } catch(e) {
2085
+ return false;
2086
+ }
2071
2087
  }
2072
2088
  };
2073
2089
 
@@ -2261,39 +2277,29 @@
2261
2277
  this.transport = transport;
2262
2278
  this.minPingDelay = options.minPingDelay;
2263
2279
  this.maxPingDelay = options.maxPingDelay;
2264
- this.pingDelay = null;
2280
+ this.pingDelay = undefined;
2265
2281
  }
2266
2282
  var prototype = AssistantToTheTransportManager.prototype;
2267
2283
 
2268
2284
  prototype.createConnection = function(name, priority, key, options) {
2269
- var connection = this.transport.createConnection(
2285
+ var self = this;
2286
+
2287
+ var options = Pusher.Util.extend({}, options, {
2288
+ activityTimeout: self.pingDelay
2289
+ });
2290
+ var connection = self.transport.createConnection(
2270
2291
  name, priority, key, options
2271
2292
  );
2272
2293
 
2273
- var self = this;
2274
2294
  var openTimestamp = null;
2275
- var pingTimer = null;
2276
2295
 
2277
2296
  var onOpen = function() {
2278
2297
  connection.unbind("open", onOpen);
2279
-
2280
- openTimestamp = Pusher.Util.now();
2281
- if (self.pingDelay) {
2282
- pingTimer = setInterval(function() {
2283
- if (pingTimer) {
2284
- connection.requestPing();
2285
- }
2286
- }, self.pingDelay);
2287
- }
2288
-
2289
2298
  connection.bind("closed", onClosed);
2299
+ openTimestamp = Pusher.Util.now();
2290
2300
  };
2291
2301
  var onClosed = function(closeEvent) {
2292
2302
  connection.unbind("closed", onClosed);
2293
- if (pingTimer) {
2294
- clearInterval(pingTimer);
2295
- pingTimer = null;
2296
- }
2297
2303
 
2298
2304
  if (closeEvent.code === 1002 || closeEvent.code === 1003) {
2299
2305
  // we don't want to use transports not obeying the protocol
@@ -2312,8 +2318,8 @@
2312
2318
  return connection;
2313
2319
  };
2314
2320
 
2315
- prototype.isSupported = function(environment) {
2316
- return this.manager.isAlive() && this.transport.isSupported(environment);
2321
+ prototype.isSupported = function() {
2322
+ return this.manager.isAlive() && this.transport.isSupported();
2317
2323
  };
2318
2324
 
2319
2325
  Pusher.AssistantToTheTransportManager = AssistantToTheTransportManager;
@@ -2364,6 +2370,23 @@
2364
2370
  sockjs: Pusher.SockJSTransport
2365
2371
  };
2366
2372
 
2373
+ var UnsupportedStrategy = {
2374
+ isSupported: function() {
2375
+ return false;
2376
+ },
2377
+ connect: function(_, callback) {
2378
+ var deferred = Pusher.Util.defer(function() {
2379
+ callback(new Pusher.Errors.UnsupportedStrategy());
2380
+ });
2381
+ return {
2382
+ abort: function() {
2383
+ deferred.ensureAborted();
2384
+ },
2385
+ forceMinPriority: function() {}
2386
+ };
2387
+ }
2388
+ };
2389
+
2367
2390
  // DSL bindings
2368
2391
 
2369
2392
  function returnWithOriginalContext(f) {
@@ -2386,19 +2409,31 @@
2386
2409
  if (!transportClass) {
2387
2410
  throw new Pusher.Errors.UnsupportedTransport(type);
2388
2411
  }
2389
- var transportOptions = Pusher.Util.extend({}, {
2390
- key: context.key,
2391
- encrypted: context.encrypted,
2392
- timeline: context.timeline,
2393
- disableFlash: context.disableFlash,
2394
- ignoreNullOrigin: context.ignoreNullOrigin
2395
- }, options);
2396
- if (manager) {
2397
- transportClass = manager.getAssistant(transportClass);
2398
- }
2399
- var transport = new Pusher.TransportStrategy(
2400
- name, priority, transportClass, transportOptions
2401
- );
2412
+
2413
+ var enabled =
2414
+ (!context.enabledTransports ||
2415
+ Pusher.Util.arrayIndexOf(context.enabledTransports, name) !== -1) &&
2416
+ (!context.disabledTransports ||
2417
+ Pusher.Util.arrayIndexOf(context.disabledTransports, name) === -1) &&
2418
+ (name !== "flash" || context.disableFlash !== true);
2419
+
2420
+ var transport;
2421
+ if (enabled) {
2422
+ transport = new Pusher.TransportStrategy(
2423
+ name,
2424
+ priority,
2425
+ manager ? manager.getAssistant(transportClass) : transportClass,
2426
+ Pusher.Util.extend({
2427
+ key: context.key,
2428
+ encrypted: context.encrypted,
2429
+ timeline: context.timeline,
2430
+ ignoreNullOrigin: context.ignoreNullOrigin
2431
+ }, options)
2432
+ );
2433
+ } else {
2434
+ transport = UnsupportedStrategy;
2435
+ }
2436
+
2402
2437
  var newContext = context.def(context, name, transport)[1];
2403
2438
  newContext.transports = context.transports || {};
2404
2439
  newContext.transports[name] = transport;
@@ -2515,7 +2550,7 @@
2515
2550
  /**
2516
2551
  * Provides functions for handling Pusher protocol-specific messages.
2517
2552
  */
2518
- Protocol = {};
2553
+ var Protocol = {};
2519
2554
 
2520
2555
  /**
2521
2556
  * Decodes a message in a Pusher format.
@@ -2572,7 +2607,11 @@
2572
2607
  message = this.decodeMessage(message);
2573
2608
 
2574
2609
  if (message.event === "pusher:connection_established") {
2575
- return { action: "connected", id: message.data.socket_id };
2610
+ return {
2611
+ action: "connected",
2612
+ id: message.data.socket_id,
2613
+ activityTimeout: message.data.activity_timeout * 1000
2614
+ };
2576
2615
  } else if (message.event === "pusher:error") {
2577
2616
  // From protocol 6 close codes are sent only once, so this only
2578
2617
  // happens when connection does not support close codes
@@ -2669,6 +2708,7 @@
2669
2708
 
2670
2709
  this.id = id;
2671
2710
  this.transport = transport;
2711
+ this.activityTimeout = transport.activityTimeout;
2672
2712
  this.bindListeners();
2673
2713
  }
2674
2714
  var prototype = Connection.prototype;
@@ -2744,9 +2784,6 @@
2744
2784
  self.emit('message', message);
2745
2785
  }
2746
2786
  };
2747
- var onPingRequest = function() {
2748
- self.emit("ping_request");
2749
- };
2750
2787
  var onError = function(error) {
2751
2788
  self.emit("error", { type: "WebSocketError", error: error });
2752
2789
  };
@@ -2764,12 +2801,10 @@
2764
2801
  var unbindListeners = function() {
2765
2802
  self.transport.unbind("closed", onClosed);
2766
2803
  self.transport.unbind("error", onError);
2767
- self.transport.unbind("ping_request", onPingRequest);
2768
2804
  self.transport.unbind("message", onMessage);
2769
2805
  };
2770
2806
 
2771
2807
  self.transport.bind("message", onMessage);
2772
- self.transport.bind("ping_request", onPingRequest);
2773
2808
  self.transport.bind("error", onError);
2774
2809
  self.transport.bind("closed", onClosed);
2775
2810
  };
@@ -2829,7 +2864,8 @@
2829
2864
  var result = Pusher.Protocol.processHandshake(m);
2830
2865
  if (result.action === "connected") {
2831
2866
  self.finish("connected", {
2832
- connection: new Pusher.Connection(result.id, self.transport)
2867
+ connection: new Pusher.Connection(result.id, self.transport),
2868
+ activityTimeout: result.activityTimeout
2833
2869
  });
2834
2870
  } else {
2835
2871
  self.finish(result.action, { error: result.error });
@@ -2884,8 +2920,9 @@
2884
2920
  * - initialized - initial state, never transitioned to
2885
2921
  * - connecting - connection is being established
2886
2922
  * - connected - connection has been fully established
2887
- * - disconnected - on requested disconnection or before reconnecting
2923
+ * - disconnected - on requested disconnection
2888
2924
  * - unavailable - after connection timeout or when there's no network
2925
+ * - failed - when the connection strategy is not supported
2889
2926
  *
2890
2927
  * Options:
2891
2928
  * - unavailableTimeout - time to transition to unavailable state
@@ -2913,16 +2950,12 @@
2913
2950
 
2914
2951
  Pusher.Network.bind("online", function() {
2915
2952
  self.timeline.info({ netinfo: "online" });
2916
- if (self.state === "unavailable") {
2917
- self.connect();
2953
+ if (self.state === "connecting" || self.state === "unavailable") {
2954
+ self.retryIn(0);
2918
2955
  }
2919
2956
  });
2920
2957
  Pusher.Network.bind("offline", function() {
2921
2958
  self.timeline.info({ netinfo: "offline" });
2922
- if (self.shouldRetry()) {
2923
- self.disconnect();
2924
- self.updateState("unavailable");
2925
- }
2926
2959
  });
2927
2960
 
2928
2961
  this.updateStrategy();
@@ -2937,42 +2970,16 @@
2937
2970
  * to find events emitted on connection attempts.
2938
2971
  */
2939
2972
  prototype.connect = function() {
2940
- var self = this;
2941
-
2942
- if (self.connection) {
2943
- return;
2944
- }
2945
- if (self.state === "connecting") {
2973
+ if (this.connection || this.runner) {
2946
2974
  return;
2947
2975
  }
2948
-
2949
- if (!self.strategy.isSupported()) {
2950
- self.updateState("failed");
2976
+ if (!this.strategy.isSupported()) {
2977
+ this.updateState("failed");
2951
2978
  return;
2952
2979
  }
2953
- if (Pusher.Network.isOnline() === false) {
2954
- self.updateState("unavailable");
2955
- return;
2956
- }
2957
-
2958
- self.updateState("connecting");
2959
-
2960
- var callback = function(error, handshake) {
2961
- if (error) {
2962
- self.runner = self.strategy.connect(0, callback);
2963
- } else {
2964
- if (handshake.action === "error") {
2965
- self.timeline.error({ handshakeError: handshake.error });
2966
- } else {
2967
- // we don't support switching connections yet
2968
- self.runner.abort();
2969
- self.handshakeCallbacks[handshake.action](handshake);
2970
- }
2971
- }
2972
- };
2973
- self.runner = self.strategy.connect(0, callback);
2974
-
2975
- self.setUnavailableTimer();
2980
+ this.updateState("connecting");
2981
+ this.startConnecting();
2982
+ this.setUnavailableTimer();
2976
2983
  };
2977
2984
 
2978
2985
  /** Sends raw data.
@@ -3004,24 +3011,52 @@
3004
3011
 
3005
3012
  /** Closes the connection. */
3006
3013
  prototype.disconnect = function() {
3014
+ this.disconnectInternally();
3015
+ this.updateState("disconnected");
3016
+ };
3017
+
3018
+ prototype.isEncrypted = function() {
3019
+ return this.encrypted;
3020
+ };
3021
+
3022
+ /** @private */
3023
+ prototype.startConnecting = function() {
3024
+ var self = this;
3025
+ var callback = function(error, handshake) {
3026
+ if (error) {
3027
+ self.runner = self.strategy.connect(0, callback);
3028
+ } else {
3029
+ if (handshake.action === "error") {
3030
+ self.timeline.error({ handshakeError: handshake.error });
3031
+ } else {
3032
+ self.abortConnecting(); // we don't support switching connections yet
3033
+ self.handshakeCallbacks[handshake.action](handshake);
3034
+ }
3035
+ }
3036
+ };
3037
+ self.runner = self.strategy.connect(0, callback);
3038
+ };
3039
+
3040
+ /** @private */
3041
+ prototype.abortConnecting = function() {
3007
3042
  if (this.runner) {
3008
3043
  this.runner.abort();
3044
+ this.runner = null;
3009
3045
  }
3046
+ };
3047
+
3048
+ /** @private */
3049
+ prototype.disconnectInternally = function() {
3050
+ this.abortConnecting();
3010
3051
  this.clearRetryTimer();
3011
3052
  this.clearUnavailableTimer();
3012
3053
  this.stopActivityCheck();
3013
- this.updateState("disconnected");
3014
- // we're in disconnected state, so closing will not cause reconnecting
3015
3054
  if (this.connection) {
3016
- this.connection.close();
3017
- this.abandonConnection();
3055
+ var connection = this.abandonConnection();
3056
+ connection.close();
3018
3057
  }
3019
3058
  };
3020
3059
 
3021
- prototype.isEncrypted = function() {
3022
- return this.encrypted;
3023
- };
3024
-
3025
3060
  /** @private */
3026
3061
  prototype.updateStrategy = function() {
3027
3062
  this.strategy = this.options.getStrategy({
@@ -3039,7 +3074,7 @@
3039
3074
  self.emit("connecting_in", Math.round(delay / 1000));
3040
3075
  }
3041
3076
  self.retryTimer = new Pusher.Timer(delay || 0, function() {
3042
- self.disconnect();
3077
+ self.disconnectInternally();
3043
3078
  self.connect();
3044
3079
  });
3045
3080
  };
@@ -3048,6 +3083,7 @@
3048
3083
  prototype.clearRetryTimer = function() {
3049
3084
  if (this.retryTimer) {
3050
3085
  this.retryTimer.ensureAborted();
3086
+ this.retryTimer = null;
3051
3087
  }
3052
3088
  };
3053
3089
 
@@ -3076,7 +3112,7 @@
3076
3112
  if (!this.connection.supportsPing()) {
3077
3113
  var self = this;
3078
3114
  self.activityTimer = new Pusher.Timer(
3079
- self.options.activityTimeout,
3115
+ self.activityTimeout,
3080
3116
  function() {
3081
3117
  self.send_event('pusher:ping', {});
3082
3118
  // wait for pong response
@@ -3084,7 +3120,7 @@
3084
3120
  self.options.pongTimeout,
3085
3121
  function() {
3086
3122
  self.timeline.error({ pong_timed_out: self.options.pongTimeout });
3087
- self.connection.close();
3123
+ self.retryIn(0);
3088
3124
  }
3089
3125
  );
3090
3126
  }
@@ -3111,9 +3147,6 @@
3111
3147
  ping: function() {
3112
3148
  self.send_event('pusher:pong', {});
3113
3149
  },
3114
- ping_request: function() {
3115
- self.send_event('pusher:ping', {});
3116
- },
3117
3150
  error: function(error) {
3118
3151
  // just emit error to user - socket will already be closed by browser
3119
3152
  self.emit("error", { type: "WebSocketError", error: error });
@@ -3132,11 +3165,15 @@
3132
3165
  var self = this;
3133
3166
  return Pusher.Util.extend({}, errorCallbacks, {
3134
3167
  connected: function(handshake) {
3168
+ self.activityTimeout = Math.min(
3169
+ self.options.activityTimeout,
3170
+ handshake.activityTimeout,
3171
+ handshake.connection.activityTimeout || Infinity
3172
+ );
3135
3173
  self.clearUnavailableTimer();
3136
3174
  self.setConnection(handshake.connection);
3137
3175
  self.socket_id = self.connection.id;
3138
- self.timeline.info({ socket_id: self.socket_id });
3139
- self.updateState("connected");
3176
+ self.updateState("connected", { socket_id: self.socket_id });
3140
3177
  }
3141
3178
  });
3142
3179
  };
@@ -3189,19 +3226,18 @@
3189
3226
  for (var event in this.connectionCallbacks) {
3190
3227
  this.connection.unbind(event, this.connectionCallbacks[event]);
3191
3228
  }
3229
+ var connection = this.connection;
3192
3230
  this.connection = null;
3231
+ return connection;
3193
3232
  };
3194
3233
 
3195
3234
  /** @private */
3196
3235
  prototype.updateState = function(newState, data) {
3197
3236
  var previousState = this.state;
3198
-
3199
3237
  this.state = newState;
3200
- // Only emit when the state changes
3201
3238
  if (previousState !== newState) {
3202
3239
  Pusher.debug('State changed', previousState + ' -> ' + newState);
3203
-
3204
- this.timeline.info({ state: newState });
3240
+ this.timeline.info({ state: newState, params: data });
3205
3241
  this.emit('state_change', { previous: previousState, current: newState });
3206
3242
  this.emit(newState, data);
3207
3243
  }
@@ -3546,6 +3582,14 @@
3546
3582
  return this.channels[name];
3547
3583
  };
3548
3584
 
3585
+ /** Returns a list of all channels
3586
+ *
3587
+ * @return {Array}
3588
+ */
3589
+ prototype.all = function(name) {
3590
+ return Pusher.Util.values(this.channels);
3591
+ };
3592
+
3549
3593
  /** Finds a channel by its name.
3550
3594
  *
3551
3595
  * @param {String} name
@@ -13,7 +13,7 @@
13
13
  <ul></ul>
14
14
  </section>
15
15
 
16
- <script src="/javascripts/vendor/pusher-2.1.3.js"></script>
16
+ <script src="/javascripts/vendor/pusher-2.1.5.js"></script>
17
17
  <script>
18
18
  window.addEventListener("DOMContentLoaded", function() {
19
19
  // Create the client instance using the PusherFake server.
data/lib/pusher-fake.rb CHANGED
@@ -16,7 +16,7 @@ require "pusher-fake/webhook"
16
16
 
17
17
  module PusherFake
18
18
  # The current version string.
19
- VERSION = "0.11.0"
19
+ VERSION = "0.12.0"
20
20
 
21
21
  # Call this method to modify the defaults.
22
22
  #
data/spec/spec_helper.rb CHANGED
@@ -8,5 +8,5 @@ end
8
8
 
9
9
  RSpec.configure do |config|
10
10
  config.mock_with :mocha
11
- config.include(BartenderHelper)
11
+ config.include(ConfigurationHelper)
12
12
  end
@@ -1,4 +1,4 @@
1
- module BartenderHelper
1
+ module ConfigurationHelper
2
2
  class ConfigurationOption
3
3
  def initialize(option)
4
4
  @option = option
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pusher-fake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tristan Dunn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-31 00:00:00.000000000 Z
11
+ date: 2013-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.0.0
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: 1.2.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - ~>
27
+ - - '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: 1.0.0
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: 1.2.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: em-websocket
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +92,14 @@ dependencies:
86
92
  requirements:
87
93
  - - '='
88
94
  - !ruby/object:Gem::Version
89
- version: 1.0.0
95
+ version: 1.1.0
90
96
  type: :development
91
97
  prerelease: false
92
98
  version_requirements: !ruby/object:Gem::Requirement
93
99
  requirements:
94
100
  - - '='
95
101
  - !ruby/object:Gem::Version
96
- version: 1.0.0
102
+ version: 1.1.0
97
103
  - !ruby/object:Gem::Dependency
98
104
  name: coveralls
99
105
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +120,14 @@ dependencies:
114
120
  requirements:
115
121
  - - '='
116
122
  - !ruby/object:Gem::Version
117
- version: 1.3.8
123
+ version: 1.3.10
118
124
  type: :development
119
125
  prerelease: false
120
126
  version_requirements: !ruby/object:Gem::Requirement
121
127
  requirements:
122
128
  - - '='
123
129
  - !ruby/object:Gem::Version
124
- version: 1.3.8
130
+ version: 1.3.10
125
131
  - !ruby/object:Gem::Dependency
126
132
  name: pusher
127
133
  requirement: !ruby/object:Gem::Requirement
@@ -142,14 +148,14 @@ dependencies:
142
148
  requirements:
143
149
  - - '='
144
150
  - !ruby/object:Gem::Version
145
- version: 10.1.0
151
+ version: 10.1.1
146
152
  type: :development
147
153
  prerelease: false
148
154
  version_requirements: !ruby/object:Gem::Requirement
149
155
  requirements:
150
156
  - - '='
151
157
  - !ruby/object:Gem::Version
152
- version: 10.1.0
158
+ version: 10.1.1
153
159
  - !ruby/object:Gem::Dependency
154
160
  name: redcarpet
155
161
  requirement: !ruby/object:Gem::Requirement
@@ -198,14 +204,14 @@ dependencies:
198
204
  requirements:
199
205
  - - '='
200
206
  - !ruby/object:Gem::Version
201
- version: 0.8.7.2
207
+ version: 0.8.7.3
202
208
  type: :development
203
209
  prerelease: false
204
210
  version_requirements: !ruby/object:Gem::Requirement
205
211
  requirements:
206
212
  - - '='
207
213
  - !ruby/object:Gem::Version
208
- version: 0.8.7.2
214
+ version: 0.8.7.3
209
215
  description: A fake Pusher server for development and testing.
210
216
  email: hello@tristandunn.com
211
217
  executables: []
@@ -236,7 +242,7 @@ files:
236
242
  - features/step_definitions/navigation_steps.rb
237
243
  - features/step_definitions/presence_steps.rb
238
244
  - features/step_definitions/webhook_steps.rb
239
- - features/support/application/public/javascripts/vendor/pusher-2.1.3.js
245
+ - features/support/application/public/javascripts/vendor/pusher-2.1.5.js
240
246
  - features/support/application/views/index.erb
241
247
  - features/support/application.rb
242
248
  - features/support/coveralls.rb
@@ -279,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
279
285
  version: '0'
280
286
  requirements: []
281
287
  rubyforge_project:
282
- rubygems_version: 2.0.2
288
+ rubygems_version: 2.0.14
283
289
  signing_key:
284
290
  specification_version: 4
285
291
  summary: A fake Pusher server for development and testing.
@@ -297,7 +303,7 @@ test_files:
297
303
  - features/step_definitions/navigation_steps.rb
298
304
  - features/step_definitions/presence_steps.rb
299
305
  - features/step_definitions/webhook_steps.rb
300
- - features/support/application/public/javascripts/vendor/pusher-2.1.3.js
306
+ - features/support/application/public/javascripts/vendor/pusher-2.1.5.js
301
307
  - features/support/application/views/index.erb
302
308
  - features/support/application.rb
303
309
  - features/support/coveralls.rb