centrifuge 2.8.3 → 2.8.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.
@@ -20,4 +20,4 @@ jobs:
20
20
  - name: Test
21
21
  run: npm run test
22
22
  - name: Check ts definitions
23
- run: npx check-dts dist/centrifuge.d.ts
23
+ run: npx check-dts@0.5.6 dist/centrifuge.d.ts
package/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ 2.8.4
2
+ =====
3
+
4
+ * 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).
5
+
1
6
  2.8.3
2
7
  =====
3
8
 
package/README.md CHANGED
@@ -346,7 +346,7 @@ centrifuge.rpc({"input": "hello"}).then(function(res) {
346
346
  `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
347
 
348
348
  ```javascript
349
- centrifuge.namedRPC({"input": "hello"}).then(function(res) {
349
+ centrifuge.namedRPC("my.method.name", {"input": "hello"}).then(function(res) {
350
350
  console.log('rpc result', res);
351
351
  }, function(err) {
352
352
  console.log('rpc error', err);
@@ -210,6 +210,7 @@ declare namespace Centrifuge {
210
210
 
211
211
  export interface SubscribeOptions {
212
212
  since?: StreamPosition;
213
+ data?: any;
213
214
  }
214
215
 
215
216
  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
 
@@ -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) {
@@ -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;