centrifuge 2.8.0 → 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.
@@ -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,23 @@
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
+
6
+ 2.8.3
7
+ =====
8
+
9
+ * Fix regression of 2.8.0: handle server-side subscribe and unsubscribe pushes.
10
+
11
+ 2.8.2
12
+ =====
13
+
14
+ * Fix TypeScript definitions for subscribe (`A rest parameter must be last in a parameter list.`).
15
+
16
+ 2.8.1
17
+ =====
18
+
19
+ * Support `sockjsTimeout` (number) option which translates to [SockJS.timeout option](https://github.com/sockjs/sockjs-client#sockjs-class) - i.e. a minimum timeout in milliseconds to use for the transport connections. By default SockJS uses timeout determined automatically based on calculating round trip time during info request.
20
+
1
21
  2.8.0
2
22
  =====
3
23
 
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);
@@ -678,10 +678,9 @@ var subscription = centrifuge.subscribe("news", function(message) {
678
678
  });
679
679
 
680
680
  subscription.history().then(function(response) {
681
- // history messages received
682
- }, function(err) {
683
- // history call failed with error
684
- });
681
+ // history messages received
682
+ }, function(err) {
683
+ // history call failed with error
685
684
  });
686
685
  ```
687
686
 
@@ -50,7 +50,7 @@ declare class Centrifuge extends EventEmitter {
50
50
  stopBatching(): void;
51
51
  startSubscribeBatching(): void;
52
52
  stopSubscribeBatching(): void;
53
- subscribe(channel: string, events?: (...args: any[], opts?: Centrifuge.SubscribeOptions) => void): Centrifuge.Subscription;
53
+ subscribe(channel: string, events?: (...args: any[]) => void, opts?: Centrifuge.SubscribeOptions): Centrifuge.Subscription;
54
54
  subscribe(channel: string, events?: Centrifuge.SubscriptionEvents, opts?: Centrifuge.SubscribeOptions): Centrifuge.Subscription;
55
55
  }
56
56
 
@@ -73,6 +73,7 @@ declare namespace Centrifuge {
73
73
  privateChannelPrefix?: string;
74
74
  onTransportClose?: (ctx: object) => void;
75
75
  sockjsServer?: string;
76
+ sockjsTimeout?: number;
76
77
  sockjsTransports?: string[];
77
78
  refreshEndpoint?: string;
78
79
  refreshHeaders?: object;
@@ -209,6 +210,7 @@ declare namespace Centrifuge {
209
210
 
210
211
  export interface SubscribeOptions {
211
212
  since?: StreamPosition;
213
+ data?: any;
212
214
  }
213
215
 
214
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
 
@@ -129,6 +129,7 @@ var Centrifuge = /*#__PURE__*/function (_EventEmitter) {
129
129
  privateChannelPrefix: '$',
130
130
  onTransportClose: null,
131
131
  sockjsServer: null,
132
+ sockjsTimeout: null,
132
133
  sockjsTransports: ['websocket', 'xdr-streaming', 'xhr-streaming', 'eventsource', 'iframe-eventsource', 'iframe-htmlfile', 'xdr-polling', 'xhr-polling', 'iframe-xhr-polling', 'jsonp-polling'],
133
134
  refreshEndpoint: '/centrifuge/refresh',
134
135
  refreshHeaders: {},
@@ -557,6 +558,10 @@ var Centrifuge = /*#__PURE__*/function (_EventEmitter) {
557
558
  sockjsOptions.server = this._config.sockjsServer;
558
559
  }
559
560
 
561
+ if (this._config.sockjsTimeout !== null) {
562
+ sockjsOptions.timeout = this._config.sockjsTimeout;
563
+ }
564
+
560
565
  this._isSockjs = true;
561
566
  this._transport = new this._sockjs(this._url, null, sockjsOptions);
562
567
  } else {
@@ -1413,11 +1418,16 @@ var Centrifuge = /*#__PURE__*/function (_EventEmitter) {
1413
1418
  params: {
1414
1419
  channel: channel
1415
1420
  }
1416
- }; // 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
1417
1426
  // can just send subscription message to Centrifuge. If channel name
1418
1427
  // starts with privateChannelPrefix - then this is a private channel
1419
1428
  // and we should ask web application backend for permission first.
1420
1429
 
1430
+
1421
1431
  if ((0, _utils.startsWith)(channel, this._config.privateChannelPrefix)) {
1422
1432
  // private channel.
1423
1433
  if (this._isSubscribeBatching) {
@@ -2008,12 +2018,12 @@ var Centrifuge = /*#__PURE__*/function (_EventEmitter) {
2008
2018
  var leave = this._decoder.decodePushData(this._pushType.LEAVE, push.data);
2009
2019
 
2010
2020
  this._handleLeave(channel, leave);
2011
- } else if (type === this._pushType.UNSUB) {
2012
- 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);
2013
2023
 
2014
2024
  this._handleUnsub(channel, unsub);
2015
- } else if (type === this._pushType.SUB) {
2016
- 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);
2017
2027
 
2018
2028
  this._handleSub(channel, sub);
2019
2029
  }
@@ -2386,7 +2396,7 @@ var Centrifuge = /*#__PURE__*/function (_EventEmitter) {
2386
2396
  currentSub._setEvents(events);
2387
2397
 
2388
2398
  if (currentSub._isUnsubscribed()) {
2389
- currentSub.subscribe();
2399
+ currentSub.subscribe(opts);
2390
2400
  }
2391
2401
 
2392
2402
  return currentSub;
@@ -2394,12 +2404,7 @@ var Centrifuge = /*#__PURE__*/function (_EventEmitter) {
2394
2404
 
2395
2405
  var sub = new _subscription["default"](this, channel, events);
2396
2406
  this._subs[channel] = sub;
2397
-
2398
- if (opts && opts.since) {
2399
- this._setSubscribeSince(sub, opts.since);
2400
- }
2401
-
2402
- sub.subscribe();
2407
+ sub.subscribe(opts);
2403
2408
  return sub;
2404
2409
  }
2405
2410
  }]);
@@ -2419,12 +2424,12 @@ exports.Centrifuge = Centrifuge;
2419
2424
  Object.defineProperty(exports, "__esModule", ({
2420
2425
  value: true
2421
2426
  }));
2422
- exports.default = void 0;
2427
+ exports["default"] = void 0;
2423
2428
 
2424
2429
  var _centrifuge = __webpack_require__(382);
2425
2430
 
2426
2431
  var _default = _centrifuge.Centrifuge;
2427
- exports.default = _default;
2432
+ exports["default"] = _default;
2428
2433
  module.exports = exports["default"];
2429
2434
 
2430
2435
  /***/ }),
@@ -2437,7 +2442,7 @@ module.exports = exports["default"];
2437
2442
  Object.defineProperty(exports, "__esModule", ({
2438
2443
  value: true
2439
2444
  }));
2440
- exports.JsonDecoder = exports.JsonEncoder = exports.JsonPushType = exports.JsonMethodType = void 0;
2445
+ exports.JsonPushType = exports.JsonMethodType = exports.JsonEncoder = exports.JsonDecoder = void 0;
2441
2446
 
2442
2447
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2443
2448
 
@@ -2537,7 +2542,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
2537
2542
  Object.defineProperty(exports, "__esModule", ({
2538
2543
  value: true
2539
2544
  }));
2540
- exports.default = void 0;
2545
+ exports["default"] = void 0;
2541
2546
 
2542
2547
  var _events = _interopRequireDefault(__webpack_require__(187));
2543
2548
 
@@ -2557,11 +2562,11 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
2557
2562
 
2558
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); }; }
2559
2564
 
2560
- 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); }
2561
2566
 
2562
2567
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
2563
2568
 
2564
- 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; } }
2565
2570
 
2566
2571
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
2567
2572
 
@@ -2599,6 +2604,7 @@ var Subscription = /*#__PURE__*/function (_EventEmitter) {
2599
2604
 
2600
2605
  _this._promises = {};
2601
2606
  _this._promiseId = 0;
2607
+ _this._subscribeData = null;
2602
2608
 
2603
2609
  _this.on('error', function (errContext) {
2604
2610
  this._centrifuge._debug('subscription error', errContext);
@@ -2820,6 +2826,11 @@ var Subscription = /*#__PURE__*/function (_EventEmitter) {
2820
2826
  subscribeErrorContext.isResubscribe = this._isResubscribe;
2821
2827
  return subscribeErrorContext;
2822
2828
  }
2829
+ }, {
2830
+ key: "_setSubscribeData",
2831
+ value: function _setSubscribeData(data) {
2832
+ this._subscribeData = data;
2833
+ }
2823
2834
  }, {
2824
2835
  key: "ready",
2825
2836
  value: function ready(callback, errback) {
@@ -2838,12 +2849,16 @@ var Subscription = /*#__PURE__*/function (_EventEmitter) {
2838
2849
  return;
2839
2850
  }
2840
2851
 
2841
- this._noResubscribe = false;
2842
-
2843
2852
  if (opts && opts.since) {
2844
2853
  this._centrifuge._setSubscribeSince(this, opts.since);
2845
2854
  }
2846
2855
 
2856
+ if (opts && opts.data) {
2857
+ this._setSubscribeData(opts.data);
2858
+ }
2859
+
2860
+ this._noResubscribe = false;
2861
+
2847
2862
  this._centrifuge._subscribe(this);
2848
2863
  }
2849
2864
  }, {
@@ -2916,7 +2931,7 @@ var Subscription = /*#__PURE__*/function (_EventEmitter) {
2916
2931
  return Subscription;
2917
2932
  }(_events["default"]);
2918
2933
 
2919
- exports.default = Subscription;
2934
+ exports["default"] = Subscription;
2920
2935
  module.exports = exports["default"];
2921
2936
 
2922
2937
  /***/ }),
@@ -2929,12 +2944,12 @@ module.exports = exports["default"];
2929
2944
  Object.defineProperty(exports, "__esModule", ({
2930
2945
  value: true
2931
2946
  }));
2932
- exports.startsWith = startsWith;
2933
- exports.isFunction = isFunction;
2934
- exports.log = log;
2935
2947
  exports.backoff = backoff;
2936
2948
  exports.errorExists = errorExists;
2937
2949
  exports.extend = extend;
2950
+ exports.isFunction = isFunction;
2951
+ exports.log = log;
2952
+ exports.startsWith = startsWith;
2938
2953
 
2939
2954
  function startsWith(value, prefix) {
2940
2955
  return value.lastIndexOf(prefix, 0) === 0;