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
@@ -868,7 +868,7 @@ function safeJSONStringify(source) {
868
868
 
869
869
  // CONCATENATED MODULE: ./src/core/defaults.ts
870
870
  var Defaults = {
871
- VERSION: "8.2.0",
871
+ VERSION: "8.3.0",
872
872
  PROTOCOL: 7,
873
873
  wsPort: 80,
874
874
  wssPort: 443,
@@ -2593,12 +2593,12 @@ function abortRunner(runner) {
2593
2593
  }
2594
2594
  }
2595
2595
 
2596
- // CONCATENATED MODULE: ./src/core/strategies/cached_strategy.ts
2596
+ // CONCATENATED MODULE: ./src/core/strategies/websocket_prioritized_cached_strategy.ts
2597
2597
 
2598
2598
 
2599
2599
 
2600
2600
 
2601
- class cached_strategy_CachedStrategy {
2601
+ class websocket_prioritized_cached_strategy_WebSocketPrioritizedCachedStrategy {
2602
2602
  constructor(strategy, transports, options) {
2603
2603
  this.strategy = strategy;
2604
2604
  this.transports = transports;
@@ -2612,19 +2612,25 @@ class cached_strategy_CachedStrategy {
2612
2612
  connect(minPriority, callback) {
2613
2613
  var usingTLS = this.usingTLS;
2614
2614
  var info = fetchTransportCache(usingTLS);
2615
+ var cacheSkipCount = info && info.cacheSkipCount ? info.cacheSkipCount : 0;
2615
2616
  var strategies = [this.strategy];
2616
2617
  if (info && info.timestamp + this.ttl >= util.now()) {
2617
2618
  var transport = this.transports[info.transport];
2618
2619
  if (transport) {
2619
- this.timeline.info({
2620
- cached: true,
2621
- transport: info.transport,
2622
- latency: info.latency
2623
- });
2624
- strategies.push(new sequential_strategy_SequentialStrategy([transport], {
2625
- timeout: info.latency * 2 + 1000,
2626
- failFast: true
2627
- }));
2620
+ if (['ws', 'wss'].includes(info.transport) || cacheSkipCount > 3) {
2621
+ this.timeline.info({
2622
+ cached: true,
2623
+ transport: info.transport,
2624
+ latency: info.latency
2625
+ });
2626
+ strategies.push(new sequential_strategy_SequentialStrategy([transport], {
2627
+ timeout: info.latency * 2 + 1000,
2628
+ failFast: true
2629
+ }));
2630
+ }
2631
+ else {
2632
+ cacheSkipCount++;
2633
+ }
2628
2634
  }
2629
2635
  }
2630
2636
  var startTimestamp = util.now();
@@ -2642,7 +2648,7 @@ class cached_strategy_CachedStrategy {
2642
2648
  }
2643
2649
  }
2644
2650
  else {
2645
- storeTransportCache(usingTLS, handshake.transport.name, util.now() - startTimestamp);
2651
+ storeTransportCache(usingTLS, handshake.transport.name, util.now() - startTimestamp, cacheSkipCount);
2646
2652
  callback(null, handshake);
2647
2653
  }
2648
2654
  });
@@ -2677,14 +2683,15 @@ function fetchTransportCache(usingTLS) {
2677
2683
  }
2678
2684
  return null;
2679
2685
  }
2680
- function storeTransportCache(usingTLS, transport, latency) {
2686
+ function storeTransportCache(usingTLS, transport, latency, cacheSkipCount) {
2681
2687
  var storage = worker_runtime.getLocalStorage();
2682
2688
  if (storage) {
2683
2689
  try {
2684
2690
  storage[getTransportCacheKey(usingTLS)] = safeJSONStringify({
2685
2691
  timestamp: util.now(),
2686
2692
  transport: transport,
2687
- latency: latency
2693
+ latency: latency,
2694
+ cacheSkipCount: cacheSkipCount
2688
2695
  });
2689
2696
  }
2690
2697
  catch (e) {
@@ -2847,7 +2854,7 @@ var getDefaultStrategy = function (config, baseOptions, defineTransport) {
2847
2854
  new delayed_strategy_DelayedStrategy(http_loop, { delay: 5000 })
2848
2855
  ]);
2849
2856
  }
2850
- return new cached_strategy_CachedStrategy(new FirstConnectedStrategy(new IfStrategy(testSupportsStrategy(ws_transport), wsStrategy, http_loop)), definedTransports, {
2857
+ return new websocket_prioritized_cached_strategy_WebSocketPrioritizedCachedStrategy(new FirstConnectedStrategy(new IfStrategy(testSupportsStrategy(ws_transport), wsStrategy, http_loop)), definedTransports, {
2851
2858
  ttl: 1800000,
2852
2859
  timeline: baseOptions.timeline,
2853
2860
  useTLS: baseOptions.useTLS