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
@@ -591,7 +591,7 @@ var ScriptReceivers = new ScriptReceiverFactory('_pusher_script_', 'Pusher.Scrip
591
591
 
592
592
  // CONCATENATED MODULE: ./src/core/defaults.ts
593
593
  var Defaults = {
594
- VERSION: "8.2.0",
594
+ VERSION: "8.3.0",
595
595
  PROTOCOL: 7,
596
596
  wsPort: 80,
597
597
  wssPort: 443,
@@ -2956,12 +2956,12 @@ function abortRunner(runner) {
2956
2956
  }
2957
2957
  }
2958
2958
 
2959
- // CONCATENATED MODULE: ./src/core/strategies/cached_strategy.ts
2959
+ // CONCATENATED MODULE: ./src/core/strategies/websocket_prioritized_cached_strategy.ts
2960
2960
 
2961
2961
 
2962
2962
 
2963
2963
 
2964
- class cached_strategy_CachedStrategy {
2964
+ class websocket_prioritized_cached_strategy_WebSocketPrioritizedCachedStrategy {
2965
2965
  constructor(strategy, transports, options) {
2966
2966
  this.strategy = strategy;
2967
2967
  this.transports = transports;
@@ -2975,19 +2975,25 @@ class cached_strategy_CachedStrategy {
2975
2975
  connect(minPriority, callback) {
2976
2976
  var usingTLS = this.usingTLS;
2977
2977
  var info = fetchTransportCache(usingTLS);
2978
+ var cacheSkipCount = info && info.cacheSkipCount ? info.cacheSkipCount : 0;
2978
2979
  var strategies = [this.strategy];
2979
2980
  if (info && info.timestamp + this.ttl >= util.now()) {
2980
2981
  var transport = this.transports[info.transport];
2981
2982
  if (transport) {
2982
- this.timeline.info({
2983
- cached: true,
2984
- transport: info.transport,
2985
- latency: info.latency
2986
- });
2987
- strategies.push(new sequential_strategy_SequentialStrategy([transport], {
2988
- timeout: info.latency * 2 + 1000,
2989
- failFast: true
2990
- }));
2983
+ if (['ws', 'wss'].includes(info.transport) || cacheSkipCount > 3) {
2984
+ this.timeline.info({
2985
+ cached: true,
2986
+ transport: info.transport,
2987
+ latency: info.latency
2988
+ });
2989
+ strategies.push(new sequential_strategy_SequentialStrategy([transport], {
2990
+ timeout: info.latency * 2 + 1000,
2991
+ failFast: true
2992
+ }));
2993
+ }
2994
+ else {
2995
+ cacheSkipCount++;
2996
+ }
2991
2997
  }
2992
2998
  }
2993
2999
  var startTimestamp = util.now();
@@ -3005,7 +3011,7 @@ class cached_strategy_CachedStrategy {
3005
3011
  }
3006
3012
  }
3007
3013
  else {
3008
- storeTransportCache(usingTLS, handshake.transport.name, util.now() - startTimestamp);
3014
+ storeTransportCache(usingTLS, handshake.transport.name, util.now() - startTimestamp, cacheSkipCount);
3009
3015
  callback(null, handshake);
3010
3016
  }
3011
3017
  });
@@ -3040,14 +3046,15 @@ function fetchTransportCache(usingTLS) {
3040
3046
  }
3041
3047
  return null;
3042
3048
  }
3043
- function storeTransportCache(usingTLS, transport, latency) {
3049
+ function storeTransportCache(usingTLS, transport, latency, cacheSkipCount) {
3044
3050
  var storage = runtime.getLocalStorage();
3045
3051
  if (storage) {
3046
3052
  try {
3047
3053
  storage[getTransportCacheKey(usingTLS)] = safeJSONStringify({
3048
3054
  timestamp: util.now(),
3049
3055
  transport: transport,
3050
- latency: latency
3056
+ latency: latency,
3057
+ cacheSkipCount: cacheSkipCount
3051
3058
  });
3052
3059
  }
3053
3060
  catch (e) {
@@ -3218,7 +3225,7 @@ var getDefaultStrategy = function (config, baseOptions, defineTransport) {
3218
3225
  new delayed_strategy_DelayedStrategy(http_fallback_loop, { delay: 5000 })
3219
3226
  ]);
3220
3227
  }
3221
- return new cached_strategy_CachedStrategy(new FirstConnectedStrategy(new IfStrategy(testSupportsStrategy(ws_transport), wsStrategy, http_fallback_loop)), definedTransports, {
3228
+ return new websocket_prioritized_cached_strategy_WebSocketPrioritizedCachedStrategy(new FirstConnectedStrategy(new IfStrategy(testSupportsStrategy(ws_transport), wsStrategy, http_fallback_loop)), definedTransports, {
3222
3229
  ttl: 1800000,
3223
3230
  timeline: baseOptions.timeline,
3224
3231
  useTLS: baseOptions.useTLS