pusher-js 7.0.0 → 7.0.4

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 (109) hide show
  1. package/.github/stale.yml +26 -0
  2. package/.github/workflows/release.yml +112 -0
  3. package/.github/workflows/release_pr.yml +42 -0
  4. package/.github/workflows/run-tests.yml +38 -0
  5. package/.vscode/settings.json +31 -0
  6. package/CHANGELOG.md +29 -0
  7. package/Makefile +17 -12
  8. package/README.md +28 -0
  9. package/dist/node/pusher.js +87 -45
  10. package/dist/node/pusher.js.map +1 -0
  11. package/dist/react-native/pusher.js +3 -2
  12. package/dist/react-native/pusher.js.map +1 -0
  13. package/dist/web/pusher-with-encryption.js +9 -6
  14. package/dist/web/pusher-with-encryption.js.map +1 -0
  15. package/dist/web/pusher-with-encryption.min.js +3 -2
  16. package/dist/web/pusher-with-encryption.min.js.map +1 -0
  17. package/dist/web/pusher.js +9 -6
  18. package/dist/web/pusher.js.map +1 -0
  19. package/dist/web/pusher.min.js +3 -2
  20. package/dist/web/pusher.min.js.map +1 -0
  21. package/dist/worker/pusher-with-encryption.worker.js +9 -6
  22. package/dist/worker/pusher-with-encryption.worker.js.map +1 -0
  23. package/dist/worker/pusher-with-encryption.worker.min.js +3 -2
  24. package/dist/worker/pusher-with-encryption.worker.min.js.map +1 -0
  25. package/dist/worker/pusher.worker.js +9 -6
  26. package/dist/worker/pusher.worker.js.map +1 -0
  27. package/dist/worker/pusher.worker.min.js +3 -2
  28. package/dist/worker/pusher.worker.min.js.map +1 -0
  29. package/package.json +17 -15
  30. package/react-native/index.d.ts +7 -8
  31. package/spec/config/jasmine/helpers/reporter.js +14 -0
  32. package/spec/config/jasmine/integration.json +13 -0
  33. package/spec/config/jasmine/unit.json +13 -0
  34. package/spec/config/{jasmine-node → jasmine}/webpack.integration.js +4 -4
  35. package/spec/config/{jasmine-node → jasmine}/webpack.unit.js +4 -6
  36. package/spec/config/karma/config.common.js +10 -4
  37. package/spec/config/karma/config.integration.js +4 -4
  38. package/spec/config/karma/config.unit.js +5 -7
  39. package/spec/config/karma/integration.js +3 -3
  40. package/spec/config/karma/unit.js +2 -2
  41. package/spec/javascripts/helpers/mocks.js +18 -18
  42. package/spec/javascripts/helpers/waitsFor.js +37 -0
  43. package/spec/javascripts/integration/core/cluster_config_spec.js +45 -34
  44. package/spec/javascripts/integration/core/falling_back_spec.js +124 -127
  45. package/spec/javascripts/integration/core/pusher_spec/test_builder.js +264 -284
  46. package/spec/javascripts/integration/core/timeout_configuration_spec.js +24 -22
  47. package/spec/javascripts/integration/core/transport_lists_spec.js +8 -8
  48. package/spec/javascripts/integration/web/dom/jsonp_spec.js +67 -69
  49. package/spec/javascripts/integration/web/dom/script_request_spec.js +44 -52
  50. package/spec/javascripts/unit/core/channels/channel_spec.js +32 -19
  51. package/spec/javascripts/unit/core/channels/encrypted_channel_spec.js +9 -17
  52. package/spec/javascripts/unit/core/channels/presence_channel_spec.js +8 -19
  53. package/spec/javascripts/unit/core/channels/private_channel_spec.js +9 -19
  54. package/spec/javascripts/unit/core/config_spec.js +2 -2
  55. package/spec/javascripts/unit/core/connection/connection_manager_spec.js +69 -63
  56. package/spec/javascripts/unit/core/connection/connection_spec.js +14 -13
  57. package/spec/javascripts/unit/core/connection/handshake_spec.js +14 -12
  58. package/spec/javascripts/unit/core/connection/protocol_spec.js +9 -4
  59. package/spec/javascripts/unit/core/defaults_spec.js +1 -1
  60. package/spec/javascripts/unit/core/events_dispatcher_spec.js +20 -20
  61. package/spec/javascripts/unit/core/http/http_polling_socket_spec.js +4 -4
  62. package/spec/javascripts/unit/core/http/http_request_spec.js +20 -17
  63. package/spec/javascripts/unit/core/http/http_socket_spec.js +35 -32
  64. package/spec/javascripts/unit/core/http/http_streaming_socket_spec.js +4 -4
  65. package/spec/javascripts/unit/core/http/http_xhr_request_spec.js +13 -13
  66. package/spec/javascripts/unit/core/pusher_authorizer_spec.js +11 -11
  67. package/spec/javascripts/unit/core/pusher_spec.js +41 -27
  68. package/spec/javascripts/unit/core/strategies/best_connected_ever_strategy_spec.js +5 -5
  69. package/spec/javascripts/unit/core/strategies/cached_strategy_spec.js +17 -13
  70. package/spec/javascripts/unit/core/strategies/delayed_strategy_spec.js +12 -8
  71. package/spec/javascripts/unit/core/strategies/sequential_strategy_spec.js +23 -19
  72. package/spec/javascripts/unit/core/strategies/transport_strategy_spec.js +22 -24
  73. package/spec/javascripts/unit/core/timeline/timeline_spec.js +16 -9
  74. package/spec/javascripts/unit/core/transports/assistant_to_the_transport_manager_spec.js +36 -22
  75. package/spec/javascripts/unit/core/transports/hosts_and_ports_spec.js +10 -10
  76. package/spec/javascripts/unit/core/transports/transport_connection_spec.js +81 -86
  77. package/spec/javascripts/unit/core/transports/transport_manager_spec.js +1 -1
  78. package/spec/javascripts/unit/core/utils/periodic_timer_spec.js +17 -16
  79. package/spec/javascripts/unit/core/utils/timers_spec.js +32 -26
  80. package/spec/javascripts/unit/isomorphic/transports/hosts_and_ports_spec.js +12 -8
  81. package/spec/javascripts/unit/isomorphic/transports/transports_spec.js +7 -7
  82. package/spec/javascripts/unit/node/timeline_sender_spec.js +5 -5
  83. package/spec/javascripts/unit/web/dom/dependency_loader_spec.js +30 -30
  84. package/spec/javascripts/unit/web/dom/jsonp_request_spec.js +7 -7
  85. package/spec/javascripts/unit/web/http/http_xdomain_request_spec.js +22 -22
  86. package/spec/javascripts/unit/web/pusher_authorizer_spec.js +3 -3
  87. package/spec/javascripts/unit/web/timeline/timeline_sender_spec.js +12 -12
  88. package/spec/javascripts/unit/web/transports/hosts_and_ports_spec.js +15 -12
  89. package/spec/javascripts/unit/web/transports/transports_spec.js +24 -26
  90. package/spec/javascripts/unit/worker/pusher_authorizer_spec.js +2 -2
  91. package/spec/javascripts/unit/worker/timeline_sender_spec.js +2 -2
  92. package/src/core/auth/options.ts +1 -0
  93. package/src/core/channels/channel.ts +1 -0
  94. package/src/core/pusher.ts +1 -1
  95. package/tags +393 -0
  96. package/types/src/core/auth/options.d.ts +1 -0
  97. package/webpack/config.node.js +2 -2
  98. package/webpack/config.react-native.js +2 -2
  99. package/webpack/config.shared.js +9 -1
  100. package/webpack/config.web.js +2 -2
  101. package/webpack/config.worker.js +2 -2
  102. package/with-encryption/index.d.ts +0 -1
  103. package/worker/index.d.ts +15 -0
  104. package/worker/index.js +1 -0
  105. package/worker/with-encryption/index.d.ts +15 -0
  106. package/worker/with-encryption/index.js +1 -0
  107. package/.travis.build +0 -22
  108. package/.travis.yml +0 -7
  109. package/spec/config/jasmine-node/config.js +0 -10
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Pusher JavaScript Library v7.0.0
2
+ * Pusher JavaScript Library v7.0.4
3
3
  * https://pusher.com/
4
4
  *
5
5
  * Copyright 2020, Pusher
@@ -369,12 +369,6 @@ module.exports = Base;
369
369
 
370
370
  /***/ }),
371
371
  /* 3 */
372
- /***/ (function(module, exports) {
373
-
374
- module.exports = require("crypto");
375
-
376
- /***/ }),
377
- /* 4 */
378
372
  /***/ (function(module, exports, __webpack_require__) {
379
373
 
380
374
  "use strict";
@@ -424,11 +418,17 @@ module.exports = Driver;
424
418
 
425
419
 
426
420
  /***/ }),
427
- /* 5 */
421
+ /* 4 */
428
422
  /***/ (function(module, exports) {
429
423
 
430
424
  module.exports = require("stream");
431
425
 
426
+ /***/ }),
427
+ /* 5 */
428
+ /***/ (function(module, exports) {
429
+
430
+ module.exports = require("crypto");
431
+
432
432
  /***/ }),
433
433
  /* 6 */
434
434
  /***/ (function(module, exports) {
@@ -437,7 +437,10 @@ module.exports = require("url");
437
437
 
438
438
  /***/ }),
439
439
  /* 7 */
440
- /***/ (function(module, exports) {
440
+ /***/ (function(module, exports, __webpack_require__) {
441
+
442
+ "use strict";
443
+
441
444
 
442
445
  var Event = function(eventType, options) {
443
446
  this.type = eventType;
@@ -747,7 +750,7 @@ exports.maxDecodedLength = function (length) {
747
750
  exports.decodedLength = function (s) {
748
751
  return stdCoder.decodedLength(s);
749
752
  };
750
- //# sourceMappingURL=base64.js.map
753
+
751
754
 
752
755
  /***/ }),
753
756
  /* 9 */
@@ -937,9 +940,12 @@ module.exports = HttpParser;
937
940
  /* 11 */
938
941
  /***/ (function(module, exports, __webpack_require__) {
939
942
 
940
- var Stream = __webpack_require__(5).Stream,
943
+ "use strict";
944
+
945
+
946
+ var Stream = __webpack_require__(4).Stream,
941
947
  util = __webpack_require__(0),
942
- driver = __webpack_require__(4),
948
+ driver = __webpack_require__(3),
943
949
  EventTarget = __webpack_require__(16),
944
950
  Event = __webpack_require__(7);
945
951
 
@@ -1002,6 +1008,8 @@ API.OPEN = 1;
1002
1008
  API.CLOSING = 2;
1003
1009
  API.CLOSED = 3;
1004
1010
 
1011
+ API.CLOSE_TIMEOUT = 30000;
1012
+
1005
1013
  var instance = {
1006
1014
  write: function(data) {
1007
1015
  return this.send(data);
@@ -1031,9 +1039,23 @@ var instance = {
1031
1039
  return this._driver.ping(message, callback);
1032
1040
  },
1033
1041
 
1034
- close: function() {
1042
+ close: function(code, reason) {
1043
+ if (code === undefined) code = 1000;
1044
+ if (reason === undefined) reason = '';
1045
+
1046
+ if (code !== 1000 && (code < 3000 || code > 4999))
1047
+ throw new Error("Failed to execute 'close' on WebSocket: " +
1048
+ "The code must be either 1000, or between 3000 and 4999. " +
1049
+ code + " is neither.");
1050
+
1035
1051
  if (this.readyState !== API.CLOSED) this.readyState = API.CLOSING;
1036
- this._driver.close();
1052
+ var self = this;
1053
+
1054
+ this._closeTimer = setTimeout(function() {
1055
+ self._beginClose('', 1006);
1056
+ }, API.CLOSE_TIMEOUT);
1057
+
1058
+ this._driver.close(reason, code);
1037
1059
  },
1038
1060
 
1039
1061
  _configureStream: function() {
@@ -1052,7 +1074,7 @@ var instance = {
1052
1074
  });
1053
1075
  },
1054
1076
 
1055
- _open: function() {
1077
+ _open: function() {
1056
1078
  if (this.readyState !== API.CONNECTING) return;
1057
1079
 
1058
1080
  this.readyState = API.OPEN;
@@ -1084,18 +1106,19 @@ var instance = {
1084
1106
  _beginClose: function(reason, code) {
1085
1107
  if (this.readyState === API.CLOSED) return;
1086
1108
  this.readyState = API.CLOSING;
1109
+ this._closeParams = [reason, code];
1087
1110
 
1088
1111
  if (this._stream) {
1089
- this._stream.end();
1112
+ this._stream.destroy();
1090
1113
  if (!this._stream.readable) this._finalizeClose();
1091
1114
  }
1092
- this._closeParams = [reason, code];
1093
1115
  },
1094
1116
 
1095
1117
  _finalizeClose: function() {
1096
1118
  if (this.readyState === API.CLOSED) return;
1097
1119
  this.readyState = API.CLOSED;
1098
1120
 
1121
+ if (this._closeTimer) clearTimeout(this._closeTimer);
1099
1122
  if (this._pingTimer) clearInterval(this._pingTimer);
1100
1123
  if (this._stream) this._stream.end();
1101
1124
 
@@ -1125,7 +1148,7 @@ module.exports = API;
1125
1148
 
1126
1149
 
1127
1150
  var Buffer = __webpack_require__(1).Buffer,
1128
- crypto = __webpack_require__(3),
1151
+ crypto = __webpack_require__(5),
1129
1152
  util = __webpack_require__(0),
1130
1153
  Extensions = __webpack_require__(29),
1131
1154
  Base = __webpack_require__(2),
@@ -1858,6 +1881,9 @@ module.exports = Draft75;
1858
1881
  /* 16 */
1859
1882
  /***/ (function(module, exports, __webpack_require__) {
1860
1883
 
1884
+ "use strict";
1885
+
1886
+
1861
1887
  var Event = __webpack_require__(7);
1862
1888
 
1863
1889
  var EventTarget = {
@@ -2041,20 +2067,23 @@ function decode(arr) {
2041
2067
  return chars.join("");
2042
2068
  }
2043
2069
  exports.decode = decode;
2044
- //# sourceMappingURL=utf8.js.map
2070
+
2045
2071
 
2046
2072
  /***/ }),
2047
2073
  /* 18 */
2048
2074
  /***/ (function(module, exports, __webpack_require__) {
2049
2075
 
2076
+ "use strict";
2050
2077
  // API references:
2051
2078
  //
2052
- // * http://dev.w3.org/html5/websockets/
2053
- // * http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-eventtarget
2054
- // * http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-event
2079
+ // * https://html.spec.whatwg.org/multipage/comms.html#network
2080
+ // * https://dom.spec.whatwg.org/#interface-eventtarget
2081
+ // * https://dom.spec.whatwg.org/#interface-event
2082
+
2083
+
2055
2084
 
2056
2085
  var util = __webpack_require__(0),
2057
- driver = __webpack_require__(4),
2086
+ driver = __webpack_require__(3),
2058
2087
  API = __webpack_require__(11);
2059
2088
 
2060
2089
  var WebSocket = function(request, socket, body, protocols, options) {
@@ -5103,7 +5132,7 @@ nacl.setPRNG = function(fn) {
5103
5132
  });
5104
5133
  } else if (true) {
5105
5134
  // Node.js.
5106
- crypto = __webpack_require__(3);
5135
+ crypto = __webpack_require__(5);
5107
5136
  if (crypto && crypto.randomBytes) {
5108
5137
  nacl.setPRNG(function(x, n) {
5109
5138
  var i, v = crypto.randomBytes(n);
@@ -5186,7 +5215,7 @@ driver having these two methods.
5186
5215
  **/
5187
5216
 
5188
5217
 
5189
- var Stream = __webpack_require__(5).Stream,
5218
+ var Stream = __webpack_require__(4).Stream,
5190
5219
  util = __webpack_require__(0);
5191
5220
 
5192
5221
 
@@ -5373,7 +5402,7 @@ module.exports = StreamReader;
5373
5402
 
5374
5403
 
5375
5404
  var Buffer = __webpack_require__(1).Buffer,
5376
- crypto = __webpack_require__(3),
5405
+ crypto = __webpack_require__(5),
5377
5406
  url = __webpack_require__(6),
5378
5407
  util = __webpack_require__(0),
5379
5408
  HttpParser = __webpack_require__(10),
@@ -6500,7 +6529,7 @@ module.exports = Message;
6500
6529
 
6501
6530
 
6502
6531
  var Buffer = __webpack_require__(1).Buffer,
6503
- Stream = __webpack_require__(5).Stream,
6532
+ Stream = __webpack_require__(4).Stream,
6504
6533
  url = __webpack_require__(6),
6505
6534
  util = __webpack_require__(0),
6506
6535
  Base = __webpack_require__(2),
@@ -6727,7 +6756,7 @@ module.exports = Server;
6727
6756
  var Buffer = __webpack_require__(1).Buffer,
6728
6757
  Base = __webpack_require__(2),
6729
6758
  Draft75 = __webpack_require__(15),
6730
- crypto = __webpack_require__(3),
6759
+ crypto = __webpack_require__(5),
6731
6760
  util = __webpack_require__(0);
6732
6761
 
6733
6762
 
@@ -6845,12 +6874,14 @@ module.exports = Draft76;
6845
6874
  /* 39 */
6846
6875
  /***/ (function(module, exports, __webpack_require__) {
6847
6876
 
6877
+ "use strict";
6878
+
6879
+
6848
6880
  var util = __webpack_require__(0),
6849
6881
  net = __webpack_require__(40),
6850
6882
  tls = __webpack_require__(41),
6851
- crypto = __webpack_require__(3),
6852
6883
  url = __webpack_require__(6),
6853
- driver = __webpack_require__(4),
6884
+ driver = __webpack_require__(3),
6854
6885
  API = __webpack_require__(11),
6855
6886
  Event = __webpack_require__(7);
6856
6887
 
@@ -6870,20 +6901,25 @@ var Client = function(_url, protocols, options) {
6870
6901
  });
6871
6902
  }, this);
6872
6903
 
6873
- var proxy = options.proxy || {},
6874
- endpoint = url.parse(proxy.origin || this.url),
6875
- port = endpoint.port || DEFAULT_PORTS[endpoint.protocol],
6876
- secure = SECURE_PROTOCOLS.indexOf(endpoint.protocol) >= 0,
6877
- onConnect = function() { self._onConnect() },
6878
- originTLS = options.tls || {},
6879
- socketTLS = proxy.origin ? (proxy.tls || {}) : originTLS,
6880
- self = this;
6904
+ var proxy = options.proxy || {},
6905
+ endpoint = url.parse(proxy.origin || this.url),
6906
+ port = endpoint.port || DEFAULT_PORTS[endpoint.protocol],
6907
+ secure = SECURE_PROTOCOLS.indexOf(endpoint.protocol) >= 0,
6908
+ onConnect = function() { self._onConnect() },
6909
+ netOptions = options.net || {},
6910
+ originTLS = options.tls || {},
6911
+ socketTLS = proxy.origin ? (proxy.tls || {}) : originTLS,
6912
+ self = this;
6913
+
6914
+ netOptions.host = socketTLS.host = endpoint.hostname;
6915
+ netOptions.port = socketTLS.port = port;
6881
6916
 
6882
6917
  originTLS.ca = originTLS.ca || options.ca;
6918
+ socketTLS.servername = socketTLS.servername || endpoint.hostname;
6883
6919
 
6884
6920
  this._stream = secure
6885
- ? tls.connect(port, endpoint.hostname, socketTLS, onConnect)
6886
- : net.connect(port, endpoint.hostname, onConnect);
6921
+ ? tls.connect(socketTLS, onConnect)
6922
+ : net.connect(netOptions, onConnect);
6887
6923
 
6888
6924
  if (proxy.origin) this._configureProxy(proxy, originTLS);
6889
6925
 
@@ -6947,9 +6983,12 @@ module.exports = require("tls");
6947
6983
  /* 42 */
6948
6984
  /***/ (function(module, exports, __webpack_require__) {
6949
6985
 
6950
- var Stream = __webpack_require__(5).Stream,
6986
+ "use strict";
6987
+
6988
+
6989
+ var Stream = __webpack_require__(4).Stream,
6951
6990
  util = __webpack_require__(0),
6952
- driver = __webpack_require__(4),
6991
+ driver = __webpack_require__(3),
6953
6992
  Headers = __webpack_require__(9),
6954
6993
  API = __webpack_require__(11),
6955
6994
  EventTarget = __webpack_require__(16),
@@ -7109,6 +7148,7 @@ module.exports = require("https");
7109
7148
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
7110
7149
 
7111
7150
  "use strict";
7151
+ // ESM COMPAT FLAG
7112
7152
  __webpack_require__.r(__webpack_exports__);
7113
7153
 
7114
7154
  // CONCATENATED MODULE: ./src/core/base64.ts
@@ -7447,7 +7487,7 @@ function safeJSONStringify(source) {
7447
7487
 
7448
7488
  // CONCATENATED MODULE: ./src/core/defaults.ts
7449
7489
  var Defaults = {
7450
- VERSION: "7.0.0",
7490
+ VERSION: "7.0.4",
7451
7491
  PROTOCOL: 7,
7452
7492
  wsPort: 80,
7453
7493
  wssPort: 443,
@@ -8515,6 +8555,7 @@ var channel_Channel = (function (_super) {
8515
8555
  this.subscriptionCancelled = false;
8516
8556
  this.authorize(this.pusher.connection.socket_id, function (error, data) {
8517
8557
  if (error) {
8558
+ _this.subscriptionPending = false;
8518
8559
  logger.error(error.toString());
8519
8560
  _this.emit('pusher:subscription_error', Object.assign({}, {
8520
8561
  type: 'AuthError',
@@ -10712,7 +10753,7 @@ var pusher_Pusher = (function () {
10712
10753
  }
10713
10754
  else {
10714
10755
  channel = this.channels.remove(channel_name);
10715
- if (channel && this.connection.state === 'connected') {
10756
+ if (channel && channel.subscribed) {
10716
10757
  channel.unsubscribe();
10717
10758
  }
10718
10759
  }
@@ -10776,4 +10817,5 @@ var pusher_with_encryption_PusherWithEncryption = (function (_super) {
10776
10817
 
10777
10818
 
10778
10819
  /***/ })
10779
- /******/ ]);
10820
+ /******/ ]);
10821
+ //# sourceMappingURL=pusher.js.map