pusher-js 8.2.0 → 8.3.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.
Files changed (27) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/node/pusher.js +24 -17
  3. package/dist/node/pusher.js.map +1 -1
  4. package/dist/react-native/pusher.js +2 -2
  5. package/dist/react-native/pusher.js.map +1 -1
  6. package/dist/web/pusher-with-encryption.js +24 -17
  7. package/dist/web/pusher-with-encryption.js.map +1 -1
  8. package/dist/web/pusher-with-encryption.min.js +2 -2
  9. package/dist/web/pusher-with-encryption.min.js.map +1 -1
  10. package/dist/web/pusher.js +24 -17
  11. package/dist/web/pusher.js.map +1 -1
  12. package/dist/web/pusher.min.js +2 -2
  13. package/dist/web/pusher.min.js.map +1 -1
  14. package/dist/worker/pusher-with-encryption.worker.js +24 -17
  15. package/dist/worker/pusher-with-encryption.worker.js.map +1 -1
  16. package/dist/worker/pusher-with-encryption.worker.min.js +2 -2
  17. package/dist/worker/pusher-with-encryption.worker.min.js.map +1 -1
  18. package/dist/worker/pusher.worker.js +24 -17
  19. package/dist/worker/pusher.worker.js.map +1 -1
  20. package/dist/worker/pusher.worker.min.js +2 -2
  21. package/dist/worker/pusher.worker.min.js.map +1 -1
  22. package/package.json +1 -1
  23. package/spec/javascripts/unit/core/strategies/{cached_strategy_spec.js → websocket_prioritized_cached_strategy_spec.js} +56 -14
  24. package/src/core/strategies/{cached_strategy.ts → websocket_prioritized_cached_strategy.ts} +25 -16
  25. package/src/runtimes/isomorphic/default_strategy.ts +3 -3
  26. package/src/runtimes/web/default_strategy.ts +3 -3
  27. package/types/src/core/strategies/{cached_strategy.d.ts → websocket_prioritized_cached_strategy.d.ts} +1 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Pusher JavaScript Library v8.2.0
2
+ * Pusher JavaScript Library v8.3.0
3
3
  * https://pusher.com/
4
4
  *
5
5
  * Copyright 2020, Pusher
@@ -2996,7 +2996,7 @@ var ScriptReceivers = new ScriptReceiverFactory('_pusher_script_', 'Pusher.Scrip
2996
2996
 
2997
2997
  // CONCATENATED MODULE: ./src/core/defaults.ts
2998
2998
  var Defaults = {
2999
- VERSION: "8.2.0",
2999
+ VERSION: "8.3.0",
3000
3000
  PROTOCOL: 7,
3001
3001
  wsPort: 80,
3002
3002
  wssPort: 443,
@@ -5361,12 +5361,12 @@ function abortRunner(runner) {
5361
5361
  }
5362
5362
  }
5363
5363
 
5364
- // CONCATENATED MODULE: ./src/core/strategies/cached_strategy.ts
5364
+ // CONCATENATED MODULE: ./src/core/strategies/websocket_prioritized_cached_strategy.ts
5365
5365
 
5366
5366
 
5367
5367
 
5368
5368
 
5369
- class cached_strategy_CachedStrategy {
5369
+ class websocket_prioritized_cached_strategy_WebSocketPrioritizedCachedStrategy {
5370
5370
  constructor(strategy, transports, options) {
5371
5371
  this.strategy = strategy;
5372
5372
  this.transports = transports;
@@ -5380,19 +5380,25 @@ class cached_strategy_CachedStrategy {
5380
5380
  connect(minPriority, callback) {
5381
5381
  var usingTLS = this.usingTLS;
5382
5382
  var info = fetchTransportCache(usingTLS);
5383
+ var cacheSkipCount = info && info.cacheSkipCount ? info.cacheSkipCount : 0;
5383
5384
  var strategies = [this.strategy];
5384
5385
  if (info && info.timestamp + this.ttl >= util.now()) {
5385
5386
  var transport = this.transports[info.transport];
5386
5387
  if (transport) {
5387
- this.timeline.info({
5388
- cached: true,
5389
- transport: info.transport,
5390
- latency: info.latency
5391
- });
5392
- strategies.push(new sequential_strategy_SequentialStrategy([transport], {
5393
- timeout: info.latency * 2 + 1000,
5394
- failFast: true
5395
- }));
5388
+ if (['ws', 'wss'].includes(info.transport) || cacheSkipCount > 3) {
5389
+ this.timeline.info({
5390
+ cached: true,
5391
+ transport: info.transport,
5392
+ latency: info.latency
5393
+ });
5394
+ strategies.push(new sequential_strategy_SequentialStrategy([transport], {
5395
+ timeout: info.latency * 2 + 1000,
5396
+ failFast: true
5397
+ }));
5398
+ }
5399
+ else {
5400
+ cacheSkipCount++;
5401
+ }
5396
5402
  }
5397
5403
  }
5398
5404
  var startTimestamp = util.now();
@@ -5410,7 +5416,7 @@ class cached_strategy_CachedStrategy {
5410
5416
  }
5411
5417
  }
5412
5418
  else {
5413
- storeTransportCache(usingTLS, handshake.transport.name, util.now() - startTimestamp);
5419
+ storeTransportCache(usingTLS, handshake.transport.name, util.now() - startTimestamp, cacheSkipCount);
5414
5420
  callback(null, handshake);
5415
5421
  }
5416
5422
  });
@@ -5445,14 +5451,15 @@ function fetchTransportCache(usingTLS) {
5445
5451
  }
5446
5452
  return null;
5447
5453
  }
5448
- function storeTransportCache(usingTLS, transport, latency) {
5454
+ function storeTransportCache(usingTLS, transport, latency, cacheSkipCount) {
5449
5455
  var storage = runtime.getLocalStorage();
5450
5456
  if (storage) {
5451
5457
  try {
5452
5458
  storage[getTransportCacheKey(usingTLS)] = safeJSONStringify({
5453
5459
  timestamp: util.now(),
5454
5460
  transport: transport,
5455
- latency: latency
5461
+ latency: latency,
5462
+ cacheSkipCount: cacheSkipCount
5456
5463
  });
5457
5464
  }
5458
5465
  catch (e) {
@@ -5623,7 +5630,7 @@ var getDefaultStrategy = function (config, baseOptions, defineTransport) {
5623
5630
  new delayed_strategy_DelayedStrategy(http_fallback_loop, { delay: 5000 })
5624
5631
  ]);
5625
5632
  }
5626
- return new cached_strategy_CachedStrategy(new FirstConnectedStrategy(new IfStrategy(testSupportsStrategy(ws_transport), wsStrategy, http_fallback_loop)), definedTransports, {
5633
+ return new websocket_prioritized_cached_strategy_WebSocketPrioritizedCachedStrategy(new FirstConnectedStrategy(new IfStrategy(testSupportsStrategy(ws_transport), wsStrategy, http_fallback_loop)), definedTransports, {
5627
5634
  ttl: 1800000,
5628
5635
  timeline: baseOptions.timeline,
5629
5636
  useTLS: baseOptions.useTLS