centrifuge 2.8.2 → 2.8.5

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.
@@ -0,0 +1,3 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: centrifugal
@@ -19,3 +19,5 @@ jobs:
19
19
  run: npm install --pure-lockfile
20
20
  - name: Test
21
21
  run: npm run test
22
+ - name: Check ts definitions
23
+ run: npx check-dts@0.5.6 dist/centrifuge.d.ts
package/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ 2.8.5
2
+ =====
3
+
4
+ * fix typing of subscribe error context [#187](https://github.com/centrifugal/centrifuge-js/pull/187)
5
+ * throw error if no transport configured [#176](https://github.com/centrifugal/centrifuge-js/pull/176)
6
+
7
+ 2.8.4
8
+ =====
9
+
10
+ * Support setting a custom `data` attached to a subscribe request. This `data` will be then available in `OnSubscribe` callback on the server side (in the case of Centrifugo subscribe proxy will be able to access this data). [#171](https://github.com/centrifugal/centrifuge-js/pull/171).
11
+
12
+ 2.8.3
13
+ =====
14
+
15
+ * Fix regression of 2.8.0: handle server-side subscribe and unsubscribe pushes.
16
+
1
17
  2.8.2
2
18
  =====
3
19
 
package/README.md CHANGED
@@ -19,18 +19,14 @@ This client can connect to [Centrifuge](https://github.com/centrifugal/centrifug
19
19
 
20
20
  ## Install and quick start
21
21
 
22
- The simplest way to use `centrifuge-js` client is download it from `dist` folder and include into your web page using `script` tag:
23
-
24
- ```html
25
- <script src="centrifuge.js"></script>
26
- ```
27
-
28
- Or using cdn (replace `X` to concrete version number):
22
+ The simplest way is to include `centrifuge-js` into your web page using `script` tag. For example, from CDN (replace `X` to concrete version number):
29
23
 
30
24
  ```html
31
25
  <script src="https://cdn.jsdelivr.net/gh/centrifugal/centrifuge-js@2.X.X/dist/centrifuge.min.js"></script>
32
26
  ```
33
27
 
28
+ Or check out [centrifuge-js on cdnjs.com](https://cdnjs.com/libraries/centrifuge).
29
+
34
30
  Client is also available via `npm`:
35
31
 
36
32
  ```bash
@@ -346,7 +342,7 @@ centrifuge.rpc({"input": "hello"}).then(function(res) {
346
342
  `namedRPC` method allows to send rpc request from client to server and wait for data response. Unlike `rpc` it additionally allows to provide method name string (which can be handy to have on RPC request top level).
347
343
 
348
344
  ```javascript
349
- centrifuge.namedRPC({"input": "hello"}).then(function(res) {
345
+ centrifuge.namedRPC("my.method.name", {"input": "hello"}).then(function(res) {
350
346
  console.log('rpc result', res);
351
347
  }, function(err) {
352
348
  console.log('rpc error', err);
@@ -139,7 +139,8 @@ declare namespace Centrifuge {
139
139
  }
140
140
 
141
141
  export interface SubscribeErrorContext {
142
- error: string;
142
+ code: number;
143
+ message: string;
143
144
  channel: string;
144
145
  isResubscribe: boolean;
145
146
  }
@@ -210,6 +211,7 @@ declare namespace Centrifuge {
210
211
 
211
212
  export interface SubscribeOptions {
212
213
  since?: StreamPosition;
214
+ data?: any;
213
215
  }
214
216
 
215
217
  export interface StreamPosition {
@@ -46,11 +46,11 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
46
46
 
47
47
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
48
48
 
49
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
49
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
50
50
 
51
51
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
52
52
 
53
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
53
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
54
54
 
55
55
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
56
56
 
@@ -568,7 +568,7 @@ var Centrifuge = /*#__PURE__*/function (_EventEmitter) {
568
568
  if (!this._websocketSupported()) {
569
569
  this._debug('No Websocket support and no SockJS configured, can not connect');
570
570
 
571
- return;
571
+ throw new Error('No Websocket support and no SockJS configured, can not connect');
572
572
  }
573
573
 
574
574
  if (this._config.websocket !== null) {
@@ -1418,11 +1418,16 @@ var Centrifuge = /*#__PURE__*/function (_EventEmitter) {
1418
1418
  params: {
1419
1419
  channel: channel
1420
1420
  }
1421
- }; // If channel name does not start with privateChannelPrefix - then we
1421
+ };
1422
+
1423
+ if (sub._subscribeData) {
1424
+ msg.params.data = sub._subscribeData;
1425
+ } // If channel name does not start with privateChannelPrefix - then we
1422
1426
  // can just send subscription message to Centrifuge. If channel name
1423
1427
  // starts with privateChannelPrefix - then this is a private channel
1424
1428
  // and we should ask web application backend for permission first.
1425
1429
 
1430
+
1426
1431
  if ((0, _utils.startsWith)(channel, this._config.privateChannelPrefix)) {
1427
1432
  // private channel.
1428
1433
  if (this._isSubscribeBatching) {
@@ -2013,12 +2018,12 @@ var Centrifuge = /*#__PURE__*/function (_EventEmitter) {
2013
2018
  var leave = this._decoder.decodePushData(this._pushType.LEAVE, push.data);
2014
2019
 
2015
2020
  this._handleLeave(channel, leave);
2016
- } else if (type === this._pushType.UNSUB) {
2017
- var unsub = this._decoder.decodePushData(this._pushType.UNSUB, push.data);
2021
+ } else if (type === this._pushType.UNSUBSCRIBE) {
2022
+ var unsub = this._decoder.decodePushData(this._pushType.UNSUBSCRIBE, push.data);
2018
2023
 
2019
2024
  this._handleUnsub(channel, unsub);
2020
- } else if (type === this._pushType.SUB) {
2021
- var sub = this._decoder.decodePushData(this._pushType.SUB, push.data);
2025
+ } else if (type === this._pushType.SUBSCRIBE) {
2026
+ var sub = this._decoder.decodePushData(this._pushType.UNSUBSCRIBE, push.data);
2022
2027
 
2023
2028
  this._handleSub(channel, sub);
2024
2029
  }
@@ -2391,7 +2396,7 @@ var Centrifuge = /*#__PURE__*/function (_EventEmitter) {
2391
2396
  currentSub._setEvents(events);
2392
2397
 
2393
2398
  if (currentSub._isUnsubscribed()) {
2394
- currentSub.subscribe();
2399
+ currentSub.subscribe(opts);
2395
2400
  }
2396
2401
 
2397
2402
  return currentSub;
@@ -2399,12 +2404,7 @@ var Centrifuge = /*#__PURE__*/function (_EventEmitter) {
2399
2404
 
2400
2405
  var sub = new _subscription["default"](this, channel, events);
2401
2406
  this._subs[channel] = sub;
2402
-
2403
- if (opts && opts.since) {
2404
- this._setSubscribeSince(sub, opts.since);
2405
- }
2406
-
2407
- sub.subscribe();
2407
+ sub.subscribe(opts);
2408
2408
  return sub;
2409
2409
  }
2410
2410
  }]);
@@ -2424,12 +2424,12 @@ exports.Centrifuge = Centrifuge;
2424
2424
  Object.defineProperty(exports, "__esModule", ({
2425
2425
  value: true
2426
2426
  }));
2427
- exports.default = void 0;
2427
+ exports["default"] = void 0;
2428
2428
 
2429
2429
  var _centrifuge = __webpack_require__(382);
2430
2430
 
2431
2431
  var _default = _centrifuge.Centrifuge;
2432
- exports.default = _default;
2432
+ exports["default"] = _default;
2433
2433
  module.exports = exports["default"];
2434
2434
 
2435
2435
  /***/ }),
@@ -2442,7 +2442,7 @@ module.exports = exports["default"];
2442
2442
  Object.defineProperty(exports, "__esModule", ({
2443
2443
  value: true
2444
2444
  }));
2445
- exports.JsonDecoder = exports.JsonEncoder = exports.JsonPushType = exports.JsonMethodType = void 0;
2445
+ exports.JsonPushType = exports.JsonMethodType = exports.JsonEncoder = exports.JsonDecoder = void 0;
2446
2446
 
2447
2447
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2448
2448
 
@@ -2542,7 +2542,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
2542
2542
  Object.defineProperty(exports, "__esModule", ({
2543
2543
  value: true
2544
2544
  }));
2545
- exports.default = void 0;
2545
+ exports["default"] = void 0;
2546
2546
 
2547
2547
  var _events = _interopRequireDefault(__webpack_require__(187));
2548
2548
 
@@ -2562,11 +2562,11 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
2562
2562
 
2563
2563
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
2564
2564
 
2565
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
2565
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
2566
2566
 
2567
2567
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
2568
2568
 
2569
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
2569
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
2570
2570
 
2571
2571
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
2572
2572
 
@@ -2604,6 +2604,7 @@ var Subscription = /*#__PURE__*/function (_EventEmitter) {
2604
2604
 
2605
2605
  _this._promises = {};
2606
2606
  _this._promiseId = 0;
2607
+ _this._subscribeData = null;
2607
2608
 
2608
2609
  _this.on('error', function (errContext) {
2609
2610
  this._centrifuge._debug('subscription error', errContext);
@@ -2825,6 +2826,11 @@ var Subscription = /*#__PURE__*/function (_EventEmitter) {
2825
2826
  subscribeErrorContext.isResubscribe = this._isResubscribe;
2826
2827
  return subscribeErrorContext;
2827
2828
  }
2829
+ }, {
2830
+ key: "_setSubscribeData",
2831
+ value: function _setSubscribeData(data) {
2832
+ this._subscribeData = data;
2833
+ }
2828
2834
  }, {
2829
2835
  key: "ready",
2830
2836
  value: function ready(callback, errback) {
@@ -2843,12 +2849,16 @@ var Subscription = /*#__PURE__*/function (_EventEmitter) {
2843
2849
  return;
2844
2850
  }
2845
2851
 
2846
- this._noResubscribe = false;
2847
-
2848
2852
  if (opts && opts.since) {
2849
2853
  this._centrifuge._setSubscribeSince(this, opts.since);
2850
2854
  }
2851
2855
 
2856
+ if (opts && opts.data) {
2857
+ this._setSubscribeData(opts.data);
2858
+ }
2859
+
2860
+ this._noResubscribe = false;
2861
+
2852
2862
  this._centrifuge._subscribe(this);
2853
2863
  }
2854
2864
  }, {
@@ -2921,7 +2931,7 @@ var Subscription = /*#__PURE__*/function (_EventEmitter) {
2921
2931
  return Subscription;
2922
2932
  }(_events["default"]);
2923
2933
 
2924
- exports.default = Subscription;
2934
+ exports["default"] = Subscription;
2925
2935
  module.exports = exports["default"];
2926
2936
 
2927
2937
  /***/ }),
@@ -2934,12 +2944,12 @@ module.exports = exports["default"];
2934
2944
  Object.defineProperty(exports, "__esModule", ({
2935
2945
  value: true
2936
2946
  }));
2937
- exports.startsWith = startsWith;
2938
- exports.isFunction = isFunction;
2939
- exports.log = log;
2940
2947
  exports.backoff = backoff;
2941
2948
  exports.errorExists = errorExists;
2942
2949
  exports.extend = extend;
2950
+ exports.isFunction = isFunction;
2951
+ exports.log = log;
2952
+ exports.startsWith = startsWith;
2943
2953
 
2944
2954
  function startsWith(value, prefix) {
2945
2955
  return value.lastIndexOf(prefix, 0) === 0;