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
@@ -3273,7 +3273,7 @@ function safeJSONStringify(source) {
3273
3273
 
3274
3274
  // CONCATENATED MODULE: ./src/core/defaults.ts
3275
3275
  var Defaults = {
3276
- VERSION: "8.2.0",
3276
+ VERSION: "8.3.0",
3277
3277
  PROTOCOL: 7,
3278
3278
  wsPort: 80,
3279
3279
  wssPort: 443,
@@ -4998,12 +4998,12 @@ function abortRunner(runner) {
4998
4998
  }
4999
4999
  }
5000
5000
 
5001
- // CONCATENATED MODULE: ./src/core/strategies/cached_strategy.ts
5001
+ // CONCATENATED MODULE: ./src/core/strategies/websocket_prioritized_cached_strategy.ts
5002
5002
 
5003
5003
 
5004
5004
 
5005
5005
 
5006
- class cached_strategy_CachedStrategy {
5006
+ class websocket_prioritized_cached_strategy_WebSocketPrioritizedCachedStrategy {
5007
5007
  constructor(strategy, transports, options) {
5008
5008
  this.strategy = strategy;
5009
5009
  this.transports = transports;
@@ -5017,19 +5017,25 @@ class cached_strategy_CachedStrategy {
5017
5017
  connect(minPriority, callback) {
5018
5018
  var usingTLS = this.usingTLS;
5019
5019
  var info = fetchTransportCache(usingTLS);
5020
+ var cacheSkipCount = info && info.cacheSkipCount ? info.cacheSkipCount : 0;
5020
5021
  var strategies = [this.strategy];
5021
5022
  if (info && info.timestamp + this.ttl >= util.now()) {
5022
5023
  var transport = this.transports[info.transport];
5023
5024
  if (transport) {
5024
- this.timeline.info({
5025
- cached: true,
5026
- transport: info.transport,
5027
- latency: info.latency
5028
- });
5029
- strategies.push(new sequential_strategy_SequentialStrategy([transport], {
5030
- timeout: info.latency * 2 + 1000,
5031
- failFast: true
5032
- }));
5025
+ if (['ws', 'wss'].includes(info.transport) || cacheSkipCount > 3) {
5026
+ this.timeline.info({
5027
+ cached: true,
5028
+ transport: info.transport,
5029
+ latency: info.latency
5030
+ });
5031
+ strategies.push(new sequential_strategy_SequentialStrategy([transport], {
5032
+ timeout: info.latency * 2 + 1000,
5033
+ failFast: true
5034
+ }));
5035
+ }
5036
+ else {
5037
+ cacheSkipCount++;
5038
+ }
5033
5039
  }
5034
5040
  }
5035
5041
  var startTimestamp = util.now();
@@ -5047,7 +5053,7 @@ class cached_strategy_CachedStrategy {
5047
5053
  }
5048
5054
  }
5049
5055
  else {
5050
- storeTransportCache(usingTLS, handshake.transport.name, util.now() - startTimestamp);
5056
+ storeTransportCache(usingTLS, handshake.transport.name, util.now() - startTimestamp, cacheSkipCount);
5051
5057
  callback(null, handshake);
5052
5058
  }
5053
5059
  });
@@ -5082,14 +5088,15 @@ function fetchTransportCache(usingTLS) {
5082
5088
  }
5083
5089
  return null;
5084
5090
  }
5085
- function storeTransportCache(usingTLS, transport, latency) {
5091
+ function storeTransportCache(usingTLS, transport, latency, cacheSkipCount) {
5086
5092
  var storage = worker_runtime.getLocalStorage();
5087
5093
  if (storage) {
5088
5094
  try {
5089
5095
  storage[getTransportCacheKey(usingTLS)] = safeJSONStringify({
5090
5096
  timestamp: util.now(),
5091
5097
  transport: transport,
5092
- latency: latency
5098
+ latency: latency,
5099
+ cacheSkipCount: cacheSkipCount
5093
5100
  });
5094
5101
  }
5095
5102
  catch (e) {
@@ -5252,7 +5259,7 @@ var getDefaultStrategy = function (config, baseOptions, defineTransport) {
5252
5259
  new delayed_strategy_DelayedStrategy(http_loop, { delay: 5000 })
5253
5260
  ]);
5254
5261
  }
5255
- return new cached_strategy_CachedStrategy(new FirstConnectedStrategy(new IfStrategy(testSupportsStrategy(ws_transport), wsStrategy, http_loop)), definedTransports, {
5262
+ return new websocket_prioritized_cached_strategy_WebSocketPrioritizedCachedStrategy(new FirstConnectedStrategy(new IfStrategy(testSupportsStrategy(ws_transport), wsStrategy, http_loop)), definedTransports, {
5256
5263
  ttl: 1800000,
5257
5264
  timeline: baseOptions.timeline,
5258
5265
  useTLS: baseOptions.useTLS