pusher-js 7.1.1-beta → 7.4.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 (61) hide show
  1. package/.github/dependabot.yml +14 -0
  2. package/.github/workflows/release.yml +1 -1
  3. package/.github/workflows/release_pr.yml +1 -1
  4. package/.github/workflows/run-tests.yml +2 -2
  5. package/.gitmodules +1 -1
  6. package/CHANGELOG.md +12 -0
  7. package/README.md +16 -34
  8. package/dist/node/pusher.js +139 -37
  9. package/dist/node/pusher.js.map +1 -1
  10. package/dist/react-native/pusher.js +2 -2
  11. package/dist/react-native/pusher.js.map +1 -1
  12. package/dist/web/pusher-with-encryption.js +139 -37
  13. package/dist/web/pusher-with-encryption.js.map +1 -1
  14. package/dist/web/pusher-with-encryption.min.js +2 -2
  15. package/dist/web/pusher-with-encryption.min.js.map +1 -1
  16. package/dist/web/pusher.js +139 -37
  17. package/dist/web/pusher.js.map +1 -1
  18. package/dist/web/pusher.min.js +2 -2
  19. package/dist/web/pusher.min.js.map +1 -1
  20. package/dist/worker/pusher-with-encryption.worker.js +139 -37
  21. package/dist/worker/pusher-with-encryption.worker.js.map +1 -1
  22. package/dist/worker/pusher-with-encryption.worker.min.js +2 -2
  23. package/dist/worker/pusher-with-encryption.worker.min.js.map +1 -1
  24. package/dist/worker/pusher.worker.js +139 -37
  25. package/dist/worker/pusher.worker.js.map +1 -1
  26. package/dist/worker/pusher.worker.min.js +2 -2
  27. package/dist/worker/pusher.worker.min.js.map +1 -1
  28. package/index.d.ts +19 -10
  29. package/package.json +6 -5
  30. package/react-native/index.d.ts +18 -4
  31. package/spec/javascripts/helpers/timers/promises.js +9 -0
  32. package/spec/javascripts/unit/core/channels/channel_spec.js +25 -0
  33. package/spec/javascripts/unit/core/channels/presence_channel_spec.js +85 -16
  34. package/spec/javascripts/unit/core/user_spec.js +13 -6
  35. package/src/core/auth/options.ts +8 -1
  36. package/src/core/channels/channel.ts +11 -0
  37. package/src/core/channels/presence_channel.ts +24 -12
  38. package/src/core/config.ts +3 -6
  39. package/src/core/defaults.ts +4 -5
  40. package/src/core/http/http_socket.ts +3 -1
  41. package/src/core/options.ts +4 -5
  42. package/src/core/pusher.ts +1 -1
  43. package/src/core/user.ts +65 -27
  44. package/src/core/utils/flat_promise.ts +10 -0
  45. package/src/runtimes/interface.ts +1 -0
  46. package/src/runtimes/node/runtime.ts +5 -0
  47. package/src/runtimes/react-native/runtime.ts +5 -0
  48. package/src/runtimes/web/runtime.ts +14 -0
  49. package/src/runtimes/worker/runtime.ts +14 -0
  50. package/types/src/core/auth/options.d.ts +3 -1
  51. package/types/src/core/channels/channel.d.ts +2 -0
  52. package/types/src/core/defaults.d.ts +3 -3
  53. package/types/src/core/options.d.ts +3 -3
  54. package/types/src/core/strategies/transport_strategy.d.ts +3 -0
  55. package/types/src/core/user.d.ts +5 -1
  56. package/types/src/core/utils/flat_promise.d.ts +6 -0
  57. package/types/src/runtimes/interface.d.ts +1 -0
  58. package/with-encryption/index.d.ts +18 -4
  59. package/worker/index.d.ts +18 -4
  60. package/worker/with-encryption/index.d.ts +18 -4
  61. package/worker/with-encryption/index.js +1 -1
@@ -0,0 +1,14 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "npm"
9
+ directory: "/" # Location of package manifests
10
+ schedule:
11
+ interval: "weekly"
12
+ # Always increase the version requirement
13
+ # to match the new version.
14
+ versioning-strategy: increase
@@ -71,7 +71,7 @@ jobs:
71
71
  - uses: actions/setup-node@v2
72
72
  if: ${{ steps.is-published.outputs.published == 'false' }}
73
73
  with:
74
- node-version: '14'
74
+ node-version: '16'
75
75
  registry-url: https://registry.npmjs.org/
76
76
  - run: npm install
77
77
  if: ${{ steps.is-published.outputs.published == 'false' }}
@@ -28,7 +28,7 @@ jobs:
28
28
  current_version: ${{ env.CURRENT_VERSION }}
29
29
  - uses: actions/setup-node@v2
30
30
  with:
31
- node-version: '14'
31
+ node-version: '16'
32
32
  - run: npm install
33
33
  - name: Push
34
34
  shell: bash
@@ -16,7 +16,7 @@ jobs:
16
16
  - uses: actions/checkout@v2
17
17
  - uses: actions/setup-node@v2
18
18
  with:
19
- node-version: '14'
19
+ node-version: '16'
20
20
  - run: npm install
21
21
  - run: npm run check-format
22
22
  - run: make web_unit
@@ -30,7 +30,7 @@ jobs:
30
30
  - uses: actions/checkout@v2
31
31
  - uses: actions/setup-node@v2
32
32
  with:
33
- node-version: '14'
33
+ node-version: '16'
34
34
  - run: npm install
35
35
  - run: npm run check-format
36
36
  - run: make node_unit
package/.gitmodules CHANGED
@@ -1,3 +1,3 @@
1
1
  [submodule "sockjs-client"]
2
2
  path = src/runtimes/web/dom/sockjs
3
- url = git://github.com/pusher/sockjs-client.git
3
+ url = https://github.com/pusher/sockjs-client.git
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 7.4.0
4
+
5
+ * [FIXED] Allow presence channel authorization to depend on user authentication
6
+
7
+ ## 7.3.0
8
+
9
+ * [FIXED] Restore previously exported types
10
+
11
+ ## 7.2.0
12
+
13
+ * [ADDED] Add support for subscription_count event
14
+
3
15
  ## 7.1.1-beta
4
16
 
5
17
  [FIXED] Exported Typescript types in index.d.ts
package/README.md CHANGED
@@ -2,8 +2,7 @@
2
2
 
3
3
  ![test badge](https://github.com/pusher/pusher-js/workflows/test/badge.svg)
4
4
 
5
- This Pusher Channels client library supports web browsers, web workers, Node.js
6
- and React Native.
5
+ This Pusher Channels client library supports web browsers, web workers and Node.js
7
6
 
8
7
  If you're looking for the Pusher Channels server library for Node.js, use
9
8
  [pusher-http-node](https://github.com/pusher/pusher-http-node) instead.
@@ -145,29 +144,11 @@ var presenceChannel: PusherTypes.PresenceChannel;
145
144
 
146
145
  ### React Native
147
146
 
148
- **Warning it's now necessary to install
149
- [@react-native-community/netinfo](https://github.com/react-native-community/react-native-netinfo)
150
- in order to use pusher-js with react-native.** pusher-js depends on NetInfo.
151
- NetInfo. NetInfo was included within react-native core until v0.60, when it was
152
- moved to the
153
- [@react-native-community/netinfo](https://github.com/react-native-community/react-native-netinfo)
154
- library. Please follow the [install
155
- instructions](https://github.com/react-native-community/react-native-netinfo#getting-started)
156
- for the
157
- [@react-native-community/netinfo](https://github.com/react-native-community/react-native-netinfo)
158
- library before trying to use pusher-js in your react-native project.
159
-
160
- Use a package manager like Yarn or NPM to install `pusher-js` and then import
161
- it as follows:
162
-
163
- ```javascript
164
- import Pusher from 'pusher-js/react-native';
165
- ```
166
-
167
- Notes:
168
-
169
- * The fallbacks available for this runtime are HTTP streaming and polling.
170
- * This build uses React Native's NetInfo API to detect changes on connectivity state. It will use this to automatically reconnect.
147
+ > **⚠️ Important notice**
148
+ >
149
+ > React Native support has been **deprecated** and soon will be removed from this repository.
150
+ >
151
+ > Please, use our official [React Native SDK](https://github.com/pusher/pusher-websocket-react-native) instead.
171
152
 
172
153
  ### Web Workers
173
154
  (`pusher-js`'s Web Workers implementation is currently not compatible with Internet Explorer)
@@ -225,7 +206,9 @@ There are a number of configuration parameters which can be set for the client,
225
206
  ```js
226
207
  const pusher = new Pusher(APP_KEY, {
227
208
  cluster: APP_CLUSTER,
228
- authEndpoint: 'http://example.com/pusher/auth'
209
+ channelAuthorization: {
210
+ endpoint: 'http://example.com/pusher/auth'
211
+ },
229
212
  });
230
213
  ```
231
214
 
@@ -252,7 +235,7 @@ Object containing the configuration for user authentication. Valid keys are:
252
235
  * `customHandler` (Function) - When present, this function is called instead of a request being made to the endpoint specified by `userAuthentication.endpoint`.
253
236
 
254
237
 
255
- For more information see [authenticating users](https://pusher.com/docs/channels/server_api/authenticating-users/).
238
+ For more information see [authenticating users](https://pusher.com/docs/channels/server_api/authenticating-users/).
256
239
 
257
240
 
258
241
  ### `channelAuthorization` (Object)
@@ -272,7 +255,7 @@ Object containing the configuration for user authorization. Valid keys are:
272
255
  * `customHandler` (Function) - When present, this function is called instead of a request being made to the endpoint specified by `channelAuthorization.endpoint`.
273
256
 
274
257
 
275
- For more information see [authorizing users](https://pusher.com/docs/channels/server_api/authorizing-users).
258
+ For more information see [authorizing users](https://pusher.com/docs/channels/server_api/authorizing-users).
276
259
 
277
260
 
278
261
  #### `cluster` (String)
@@ -463,7 +446,7 @@ It is possible to access all subscribed channels through the `allChannels` funct
463
446
  pusher.allChannels().forEach(channel => console.log(channel.name));
464
447
  ```
465
448
 
466
- Private, presence and encrypted channels will make a request to your `authEndpoint` (`/pusher/auth`) by default, where you will have to [authenticate the subscription](https://pusher.com/docs/authenticating_users). You will have to send back the correct auth response and a 200 status code.
449
+ Private, presence and encrypted channels will make a request to your `channelAuthorization.endpoint` (`/pusher/auth`) by default, where you will have to [authorize the subscription](https://pusher.com/docs/authorizing_users). You will have to send back the correct authorization response and a 200 status code.
467
450
 
468
451
  ## Unsubscribing from channels
469
452
 
@@ -564,9 +547,9 @@ channel.trigger('client-my-event', {message: 'Hello, world!'})
564
547
  ```
565
548
 
566
549
 
567
- ## Batching auth requests (aka multi-auth)
550
+ ## Batching authorization requests (aka multi-authorization)
568
551
 
569
- Currently, pusher-js itself does not support authenticating multiple channels in one HTTP request. However, thanks to @dirkbonhomme you can use the [pusher-js-auth](https://github.com/dirkbonhomme/pusher-js-auth) plugin that buffers subscription requests and sends auth requests to your endpoint in batches.
552
+ Currently, pusher-js itself does not support authorizing multiple channels in one HTTP request. However, thanks to @dirkbonhomme you can use the [pusher-js-auth](https://github.com/dirkbonhomme/pusher-js-auth) plugin that buffers subscription requests and sends authorization requests to your endpoint in batches.
570
553
 
571
554
  ## Default events
572
555
 
@@ -641,7 +624,7 @@ This command will serve `pusher.js`, `sockjs.js`, `json2.js`, and their respecti
641
624
 
642
625
  ### Core Vs. Platform-Specific Code
643
626
 
644
- New to pusher-js 3.1 is the ability for the library to produce builds for different runtimes: classic web, React Native, NodeJS and
627
+ New to pusher-js 3.1 is the ability for the library to produce builds for different runtimes: classic web, NodeJS and
645
628
  Web Workers.
646
629
 
647
630
  In order for this to happen, we have split the library into two directories: `core/` and `runtimes/`. In `core` we keep anything that is platform-independent. In `runtimes` we keep code that depends on certain runtimes.
@@ -680,7 +663,6 @@ In order to specify the library version, you can either update `package.json` or
680
663
  Other build commands include:
681
664
 
682
665
  ```bash
683
- make react-native # for the React Native build
684
666
  make node # for the NodeJS build
685
667
  make worker # for the worker build
686
668
  ```
@@ -694,7 +676,7 @@ Each test environment contains two types of tests:
694
676
 
695
677
  Unit tests are simple, fast and don't need any external dependencies. Integration tests usually connect to production and js-integration-api servers and can use a local server for loading JS files, so they need an Internet connection to work.
696
678
 
697
- There are 3 different testing environments: one for web, one for NodeJS and one for workers. We may consider adding another one for React Native in the future.
679
+ There are 3 different testing environments: one for web, one for NodeJS and one for workers.
698
680
 
699
681
  The web and worker tests use [Karma](https://github.com/karma-runner/karma) to execute specs in real browsers. The NodeJS tests use [jasmine-node](https://github.com/mhevery/jasmine-node).
700
682
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Pusher JavaScript Library v7.1.1-beta
2
+ * Pusher JavaScript Library v7.4.0
3
3
  * https://pusher.com/
4
4
  *
5
5
  * Copyright 2020, Pusher
@@ -7487,7 +7487,7 @@ function safeJSONStringify(source) {
7487
7487
 
7488
7488
  // CONCATENATED MODULE: ./src/core/defaults.ts
7489
7489
  var Defaults = {
7490
- VERSION: "7.1.1-beta",
7490
+ VERSION: "7.4.0",
7491
7491
  PROTOCOL: 7,
7492
7492
  wsPort: 80,
7493
7493
  wssPort: 443,
@@ -8517,6 +8517,9 @@ var channel_Channel = (function (_super) {
8517
8517
  if (eventName === 'pusher_internal:subscription_succeeded') {
8518
8518
  this.handleSubscriptionSucceededEvent(event);
8519
8519
  }
8520
+ else if (eventName === 'pusher_internal:subscription_count') {
8521
+ this.handleSubscriptionCountEvent(event);
8522
+ }
8520
8523
  else if (eventName.indexOf('pusher_internal:') !== 0) {
8521
8524
  var metadata = {};
8522
8525
  this.emit(eventName, data, metadata);
@@ -8532,6 +8535,12 @@ var channel_Channel = (function (_super) {
8532
8535
  this.emit('pusher:subscription_succeeded', event.data);
8533
8536
  }
8534
8537
  };
8538
+ Channel.prototype.handleSubscriptionCountEvent = function (event) {
8539
+ if (event.data.subscription_count) {
8540
+ this.subscriptionCount = event.data.subscription_count;
8541
+ }
8542
+ this.emit('pusher:subscription_count', event.data);
8543
+ };
8535
8544
  Channel.prototype.subscribe = function () {
8536
8545
  var _this = this;
8537
8546
  if (this.subscribed) {
@@ -8673,6 +8682,41 @@ var presence_channel_extends = (undefined && undefined.__extends) || (function (
8673
8682
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
8674
8683
  };
8675
8684
  })();
8685
+ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
8686
+ return new (P || (P = Promise))(function (resolve, reject) {
8687
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8688
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8689
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
8690
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8691
+ });
8692
+ };
8693
+ var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
8694
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
8695
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
8696
+ function verb(n) { return function (v) { return step([n, v]); }; }
8697
+ function step(op) {
8698
+ if (f) throw new TypeError("Generator is already executing.");
8699
+ while (_) try {
8700
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
8701
+ if (y = 0, t) op = [op[0] & 2, t.value];
8702
+ switch (op[0]) {
8703
+ case 0: case 1: t = op; break;
8704
+ case 4: _.label++; return { value: op[1], done: false };
8705
+ case 5: _.label++; y = op[1]; op = [0]; continue;
8706
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
8707
+ default:
8708
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
8709
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
8710
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
8711
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
8712
+ if (t[2]) _.ops.pop();
8713
+ _.trys.pop(); continue;
8714
+ }
8715
+ op = body.call(thisArg, _);
8716
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
8717
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
8718
+ }
8719
+ };
8676
8720
 
8677
8721
 
8678
8722
 
@@ -8686,21 +8730,38 @@ var presence_channel_PresenceChannel = (function (_super) {
8686
8730
  }
8687
8731
  PresenceChannel.prototype.authorize = function (socketId, callback) {
8688
8732
  var _this = this;
8689
- _super.prototype.authorize.call(this, socketId, function (error, authData) {
8690
- if (!error) {
8691
- authData = authData;
8692
- if (authData.channel_data === undefined) {
8693
- var suffix = url_store.buildLogSuffix('authenticationEndpoint');
8694
- logger.error("Invalid auth response for channel '" + _this.name + "'," +
8695
- ("expected 'channel_data' field. " + suffix));
8696
- callback('Invalid auth response');
8697
- return;
8733
+ _super.prototype.authorize.call(this, socketId, function (error, authData) { return __awaiter(_this, void 0, void 0, function () {
8734
+ var channelData, suffix;
8735
+ return __generator(this, function (_a) {
8736
+ switch (_a.label) {
8737
+ case 0:
8738
+ if (!!error) return [3, 3];
8739
+ authData = authData;
8740
+ if (!(authData.channel_data != null)) return [3, 1];
8741
+ channelData = JSON.parse(authData.channel_data);
8742
+ this.members.setMyID(channelData.user_id);
8743
+ return [3, 3];
8744
+ case 1: return [4, this.pusher.user.signinDonePromise];
8745
+ case 2:
8746
+ _a.sent();
8747
+ if (this.pusher.user.user_data != null) {
8748
+ this.members.setMyID(this.pusher.user.user_data.id);
8749
+ }
8750
+ else {
8751
+ suffix = url_store.buildLogSuffix('authorizationEndpoint');
8752
+ logger.error("Invalid auth response for channel '" + this.name + "', " +
8753
+ ("expected 'channel_data' field. " + suffix + ", ") +
8754
+ "or the user should be signed in.");
8755
+ callback('Invalid auth response');
8756
+ return [2];
8757
+ }
8758
+ _a.label = 3;
8759
+ case 3:
8760
+ callback(error, authData);
8761
+ return [2];
8698
8762
  }
8699
- var channelData = JSON.parse(authData.channel_data);
8700
- _this.members.setMyID(channelData.user_id);
8701
- }
8702
- callback(error, authData);
8703
- });
8763
+ });
8764
+ }); });
8704
8765
  };
8705
8766
  PresenceChannel.prototype.handleEvent = function (event) {
8706
8767
  var eventName = event.event;
@@ -8723,6 +8784,9 @@ var presence_channel_PresenceChannel = (function (_super) {
8723
8784
  case 'pusher_internal:subscription_succeeded':
8724
8785
  this.handleSubscriptionSucceededEvent(event);
8725
8786
  break;
8787
+ case 'pusher_internal:subscription_count':
8788
+ this.handleSubscriptionCountEvent(event);
8789
+ break;
8726
8790
  case 'pusher_internal:member_added':
8727
8791
  var addedMember = this.members.addMember(data);
8728
8792
  this.emit('pusher:member_added', addedMember);
@@ -10693,6 +10757,17 @@ function buildChannelAuthorizer(opts, pusher) {
10693
10757
  return channel_authorizer(channelAuthorization);
10694
10758
  }
10695
10759
 
10760
+ // CONCATENATED MODULE: ./src/core/utils/flat_promise.ts
10761
+ function flatPromise() {
10762
+ var resolve, reject;
10763
+ var promise = new Promise(function (res, rej) {
10764
+ resolve = res;
10765
+ reject = rej;
10766
+ });
10767
+ return { promise: promise, resolve: resolve, reject: reject };
10768
+ }
10769
+ /* harmony default export */ var flat_promise = (flatPromise);
10770
+
10696
10771
  // CONCATENATED MODULE: ./src/core/user.ts
10697
10772
  var user_extends = (undefined && undefined.__extends) || (function () {
10698
10773
  var extendStatics = function (d, b) {
@@ -10710,6 +10785,7 @@ var user_extends = (undefined && undefined.__extends) || (function () {
10710
10785
 
10711
10786
 
10712
10787
 
10788
+
10713
10789
  var user_UserFacade = (function (_super) {
10714
10790
  user_extends(UserFacade, _super);
10715
10791
  function UserFacade(pusher) {
@@ -10719,15 +10795,29 @@ var user_UserFacade = (function (_super) {
10719
10795
  _this.signin_requested = false;
10720
10796
  _this.user_data = null;
10721
10797
  _this.serverToUserChannel = null;
10798
+ _this.signinDonePromise = null;
10799
+ _this._signinDoneResolve = null;
10800
+ _this._onAuthorize = function (err, authData) {
10801
+ if (err) {
10802
+ logger.warn("Error during signin: " + err);
10803
+ _this._cleanup();
10804
+ return;
10805
+ }
10806
+ _this.pusher.send_event('pusher:signin', {
10807
+ auth: authData.auth,
10808
+ user_data: authData.user_data
10809
+ });
10810
+ };
10722
10811
  _this.pusher = pusher;
10723
- _this.pusher.connection.bind('connected', function () {
10724
- _this._signin();
10725
- });
10726
- _this.pusher.connection.bind('connecting', function () {
10727
- _this._disconnect();
10728
- });
10729
- _this.pusher.connection.bind('disconnected', function () {
10730
- _this._disconnect();
10812
+ _this.pusher.connection.bind('state_change', function (_a) {
10813
+ var previous = _a.previous, current = _a.current;
10814
+ if (previous !== 'connected' && current === 'connected') {
10815
+ _this._signin();
10816
+ }
10817
+ if (previous === 'connected' && current !== 'connected') {
10818
+ _this._cleanup();
10819
+ _this._newSigninPromiseIfNeeded();
10820
+ }
10731
10821
  });
10732
10822
  _this.pusher.connection.bind('message', function (event) {
10733
10823
  var eventName = event.event;
@@ -10749,26 +10839,16 @@ var user_UserFacade = (function (_super) {
10749
10839
  this._signin();
10750
10840
  };
10751
10841
  UserFacade.prototype._signin = function () {
10752
- var _this = this;
10753
10842
  if (!this.signin_requested) {
10754
10843
  return;
10755
10844
  }
10845
+ this._newSigninPromiseIfNeeded();
10756
10846
  if (this.pusher.connection.state !== 'connected') {
10757
10847
  return;
10758
10848
  }
10759
- var onAuthorize = function (err, authData) {
10760
- if (err) {
10761
- logger.warn("Error during signin: " + err);
10762
- return;
10763
- }
10764
- _this.pusher.send_event('pusher:signin', {
10765
- auth: authData.auth,
10766
- user_data: authData.user_data
10767
- });
10768
- };
10769
10849
  this.pusher.config.userAuthenticator({
10770
10850
  socketId: this.pusher.connection.socket_id
10771
- }, onAuthorize);
10851
+ }, this._onAuthorize);
10772
10852
  };
10773
10853
  UserFacade.prototype._onSigninSuccess = function (data) {
10774
10854
  try {
@@ -10776,12 +10856,15 @@ var user_UserFacade = (function (_super) {
10776
10856
  }
10777
10857
  catch (e) {
10778
10858
  logger.error("Failed parsing user data after signin: " + data.user_data);
10859
+ this._cleanup();
10779
10860
  return;
10780
10861
  }
10781
10862
  if (typeof this.user_data.id !== 'string' || this.user_data.id === '') {
10782
10863
  logger.error("user_data doesn't contain an id. user_data: " + this.user_data);
10864
+ this._cleanup();
10783
10865
  return;
10784
10866
  }
10867
+ this._signinDoneResolve();
10785
10868
  this._subscribeChannels();
10786
10869
  };
10787
10870
  UserFacade.prototype._subscribeChannels = function () {
@@ -10805,13 +10888,32 @@ var user_UserFacade = (function (_super) {
10805
10888
  });
10806
10889
  ensure_subscribed(this.serverToUserChannel);
10807
10890
  };
10808
- UserFacade.prototype._disconnect = function () {
10891
+ UserFacade.prototype._cleanup = function () {
10809
10892
  this.user_data = null;
10810
10893
  if (this.serverToUserChannel) {
10811
10894
  this.serverToUserChannel.unbind_all();
10812
10895
  this.serverToUserChannel.disconnect();
10813
10896
  this.serverToUserChannel = null;
10814
10897
  }
10898
+ if (this.signin_requested) {
10899
+ this._signinDoneResolve();
10900
+ }
10901
+ };
10902
+ UserFacade.prototype._newSigninPromiseIfNeeded = function () {
10903
+ if (!this.signin_requested) {
10904
+ return;
10905
+ }
10906
+ if (this.signinDonePromise && !this.signinDonePromise.done) {
10907
+ return;
10908
+ }
10909
+ var _a = flat_promise(), promise = _a.promise, resolve = _a.resolve, _ = _a.reject;
10910
+ promise.done = false;
10911
+ var setDone = function () {
10912
+ promise.done = true;
10913
+ };
10914
+ promise.then(setDone)["catch"](setDone);
10915
+ this.signinDonePromise = promise;
10916
+ this._signinDoneResolve = resolve;
10815
10917
  };
10816
10918
  return UserFacade;
10817
10919
  }(dispatcher));