pusher-js 7.0.6 → 7.1.0-beta

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 (98) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/node/pusher.js +311 -71
  3. package/dist/node/pusher.js.map +1 -1
  4. package/dist/react-native/pusher.js +1 -1
  5. package/dist/react-native/pusher.js.map +1 -1
  6. package/dist/web/pusher-with-encryption.js +316 -76
  7. package/dist/web/pusher-with-encryption.js.map +1 -1
  8. package/dist/web/pusher-with-encryption.min.js +1 -1
  9. package/dist/web/pusher-with-encryption.min.js.map +1 -1
  10. package/dist/web/pusher.js +316 -76
  11. package/dist/web/pusher.js.map +1 -1
  12. package/dist/web/pusher.min.js +1 -1
  13. package/dist/web/pusher.min.js.map +1 -1
  14. package/dist/worker/pusher-with-encryption.worker.js +300 -67
  15. package/dist/worker/pusher-with-encryption.worker.js.map +1 -1
  16. package/dist/worker/pusher-with-encryption.worker.min.js +1 -1
  17. package/dist/worker/pusher-with-encryption.worker.min.js.map +1 -1
  18. package/dist/worker/pusher.worker.js +300 -67
  19. package/dist/worker/pusher.worker.js.map +1 -1
  20. package/dist/worker/pusher.worker.min.js +1 -1
  21. package/dist/worker/pusher.worker.min.js.map +1 -1
  22. package/package.json +2 -2
  23. package/spec/config/karma/config.worker.js +3 -0
  24. package/spec/config/karma/integration.js +4 -2
  25. package/spec/javascripts/helpers/mocks.js +41 -8
  26. package/spec/javascripts/helpers/worker/mock-dom-dependencies.js +1 -0
  27. package/spec/javascripts/integration/core/cluster_config_spec.js +8 -0
  28. package/spec/javascripts/integration/core/timeout_configuration_spec.js +1 -0
  29. package/spec/javascripts/integration/index.worker.js +12 -1
  30. package/spec/javascripts/unit/core/channels/encrypted_channel_spec.js +64 -66
  31. package/spec/javascripts/unit/core/channels/presence_channel_spec.js +51 -41
  32. package/spec/javascripts/unit/core/channels/private_channel_spec.js +8 -46
  33. package/spec/javascripts/unit/core/config_spec.js +307 -7
  34. package/spec/javascripts/unit/core/connection/connection_manager_spec.js +1 -0
  35. package/spec/javascripts/unit/core/http/http_socket_spec.js +1 -0
  36. package/spec/javascripts/unit/core/logger_spec.js +21 -20
  37. package/spec/javascripts/unit/core/pusher_spec.js +67 -39
  38. package/spec/javascripts/unit/core/pusher_with_encryption_spec.js +2 -0
  39. package/spec/javascripts/unit/core/strategies/cached_strategy_spec.js +1 -0
  40. package/spec/javascripts/unit/core/strategies/delayed_strategy_spec.js +1 -0
  41. package/spec/javascripts/unit/core/strategies/sequential_strategy_spec.js +1 -0
  42. package/spec/javascripts/unit/core/strategies/transport_strategy_spec.js +1 -0
  43. package/spec/javascripts/unit/core/transports/assistant_to_the_transport_manager_spec.js +1 -0
  44. package/spec/javascripts/unit/core/user_spec.js +295 -0
  45. package/spec/javascripts/unit/core/utils/periodic_timer_spec.js +4 -1
  46. package/spec/javascripts/unit/core/utils/timers_spec.js +6 -0
  47. package/spec/javascripts/unit/core/utils/url_store_spec.js +1 -1
  48. package/spec/javascripts/unit/core_with_runtime/auth/channel_authorizer_spec.js +55 -0
  49. package/spec/javascripts/unit/core_with_runtime/auth/deprecated_channel_authorizer_spec.js +48 -0
  50. package/spec/javascripts/unit/core_with_runtime/auth/user_authorizer_spec.js +52 -0
  51. package/spec/javascripts/unit/core_with_runtime/readme.md +5 -0
  52. package/spec/javascripts/unit/index.node.js +3 -0
  53. package/spec/javascripts/unit/index.web.js +3 -0
  54. package/spec/javascripts/unit/index.worker.js +3 -0
  55. package/spec/javascripts/unit/web/pusher_authorizer_spec.js +15 -16
  56. package/spec/javascripts/unit/web/transports/hosts_and_ports_spec.js +1 -0
  57. package/spec/javascripts/unit/worker/channel_authorizer_spec.js +110 -0
  58. package/src/core/auth/auth_transports.ts +8 -1
  59. package/src/core/auth/channel_authorizer.ts +53 -0
  60. package/src/core/auth/deprecated_channel_authorizer.ts +58 -0
  61. package/src/core/auth/options.ts +52 -17
  62. package/src/core/auth/user_authenticator.ts +51 -0
  63. package/src/core/channels/channel.ts +6 -3
  64. package/src/core/channels/channels.ts +4 -0
  65. package/src/core/channels/encrypted_channel.ts +26 -20
  66. package/src/core/channels/presence_channel.ts +2 -2
  67. package/src/core/channels/private_channel.ts +9 -4
  68. package/src/core/config.ts +76 -11
  69. package/src/core/defaults.ts +15 -0
  70. package/src/core/errors.ts +9 -0
  71. package/src/core/options.ts +18 -5
  72. package/src/core/pusher.ts +9 -1
  73. package/src/core/user.ts +143 -0
  74. package/src/core/utils/factory.ts +1 -10
  75. package/src/core/utils/url_store.ts +4 -1
  76. package/src/runtimes/isomorphic/auth/xhr_auth.ts +32 -19
  77. package/src/runtimes/web/auth/jsonp_auth.ts +13 -7
  78. package/src/runtimes/worker/auth/fetch_auth.ts +17 -12
  79. package/types/src/core/auth/auth_transports.d.ts +2 -1
  80. package/types/src/core/auth/channel_authorizer.d.ts +3 -0
  81. package/types/src/core/auth/deprecated_channel_authorizer.d.ts +18 -0
  82. package/types/src/core/auth/options.d.ts +34 -15
  83. package/types/src/core/auth/user_authenticator.d.ts +3 -0
  84. package/types/src/core/auth/user_authorizer.d.ts +3 -0
  85. package/types/src/core/channels/channel.d.ts +2 -2
  86. package/types/src/core/channels/encrypted_channel.d.ts +2 -2
  87. package/types/src/core/channels/private_channel.d.ts +2 -2
  88. package/types/src/core/config.d.ts +4 -6
  89. package/types/src/core/defaults.d.ts +3 -0
  90. package/types/src/core/errors.d.ts +3 -0
  91. package/types/src/core/options.d.ts +6 -3
  92. package/types/src/core/pusher.d.ts +3 -0
  93. package/types/src/core/user.d.ts +15 -0
  94. package/types/src/core/utils/factory.d.ts +0 -2
  95. package/types/src/runtimes/isomorphic/auth/xhr_auth.d.ts +1 -1
  96. package/spec/javascripts/unit/core/pusher_authorizer_spec.js +0 -160
  97. package/spec/javascripts/unit/worker/pusher_authorizer_spec.js +0 -111
  98. package/src/core/auth/pusher_authorizer.ts +0 -64
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 7.1.0-beta
4
+
5
+ [ADDED] Support for authenticating users with the `signin` method
6
+
7
+ [ADDED] Support for binding to events sent to a specific authenticated user
8
+
9
+ [UPDATED] The initialization of the `Pusher` object has been changed. Two new parameters were introduced: `userAuthentication` and `channelAuthorization`.
10
+
11
+ [DEPRECATED] The Pusher object parameters `auth`, `authEndpoint`, and `authTransport` are still supported, but deprecated. They have been replaced with the `channelAuthorization` parameter.
12
+
3
13
  ## 7.0.6
4
14
 
5
15
  * [FIXED] pusher-js/worker can now be bundled and used in a web worker context
@@ -7503,6 +7503,14 @@ var Defaults = {
7503
7503
  pongTimeout: 30000,
7504
7504
  unavailableTimeout: 10000,
7505
7505
  cluster: 'mt1',
7506
+ userAuthentication: {
7507
+ endpoint: '/pusher/user-auth',
7508
+ transport: 'ajax'
7509
+ },
7510
+ channelAuthorization: {
7511
+ endpoint: '/pusher/auth',
7512
+ transport: 'ajax'
7513
+ },
7506
7514
  cdn_http: "http://js.pusher.com",
7507
7515
  cdn_https: "https://js.pusher.com",
7508
7516
  dependency_suffix: ""
@@ -8283,42 +8291,6 @@ var handshake_Handshake = (function () {
8283
8291
  }());
8284
8292
  /* harmony default export */ var connection_handshake = (handshake_Handshake);
8285
8293
 
8286
- // CONCATENATED MODULE: ./src/core/auth/pusher_authorizer.ts
8287
-
8288
- var pusher_authorizer_PusherAuthorizer = (function () {
8289
- function PusherAuthorizer(channel, options) {
8290
- this.channel = channel;
8291
- var authTransport = options.authTransport;
8292
- if (typeof node_runtime.getAuthorizers()[authTransport] === 'undefined') {
8293
- throw "'" + authTransport + "' is not a recognized auth transport";
8294
- }
8295
- this.type = authTransport;
8296
- this.options = options;
8297
- this.authOptions = options.auth || {};
8298
- }
8299
- PusherAuthorizer.prototype.composeQuery = function (socketId) {
8300
- var query = 'socket_id=' +
8301
- encodeURIComponent(socketId) +
8302
- '&channel_name=' +
8303
- encodeURIComponent(this.channel.name);
8304
- for (var i in this.authOptions.params) {
8305
- query +=
8306
- '&' +
8307
- encodeURIComponent(i) +
8308
- '=' +
8309
- encodeURIComponent(this.authOptions.params[i]);
8310
- }
8311
- return query;
8312
- };
8313
- PusherAuthorizer.prototype.authorize = function (socketId, callback) {
8314
- PusherAuthorizer.authorizers =
8315
- PusherAuthorizer.authorizers || node_runtime.getAuthorizers();
8316
- PusherAuthorizer.authorizers[this.type].call(this, node_runtime, socketId, callback);
8317
- };
8318
- return PusherAuthorizer;
8319
- }());
8320
- /* harmony default export */ var pusher_authorizer = (pusher_authorizer_PusherAuthorizer);
8321
-
8322
8294
  // CONCATENATED MODULE: ./src/core/timeline/timeline_sender.ts
8323
8295
 
8324
8296
  var timeline_sender_TimelineSender = (function () {
@@ -8361,6 +8333,17 @@ var BadEventName = (function (_super) {
8361
8333
  return BadEventName;
8362
8334
  }(Error));
8363
8335
 
8336
+ var BadChannelName = (function (_super) {
8337
+ errors_extends(BadChannelName, _super);
8338
+ function BadChannelName(msg) {
8339
+ var _newTarget = this.constructor;
8340
+ var _this = _super.call(this, msg) || this;
8341
+ Object.setPrototypeOf(_this, _newTarget.prototype);
8342
+ return _this;
8343
+ }
8344
+ return BadChannelName;
8345
+ }(Error));
8346
+
8364
8347
  var RequestTimedOut = (function (_super) {
8365
8348
  errors_extends(RequestTimedOut, _super);
8366
8349
  function RequestTimedOut(msg) {
@@ -8445,7 +8428,10 @@ var urlStore = {
8445
8428
  baseUrl: 'https://pusher.com',
8446
8429
  urls: {
8447
8430
  authenticationEndpoint: {
8448
- path: '/docs/authenticating_users'
8431
+ path: '/docs/channels/server_api/authenticating_users'
8432
+ },
8433
+ authorizationEndpoint: {
8434
+ path: '/docs/channels/server_api/authorizing-users/'
8449
8435
  },
8450
8436
  javascriptQuickStart: {
8451
8437
  path: '/docs/javascript_quick_start'
@@ -8602,19 +8588,20 @@ var private_channel_extends = (undefined && undefined.__extends) || (function ()
8602
8588
  };
8603
8589
  })();
8604
8590
 
8605
-
8606
- var private_channel_PrivateChannel = (function (_super) {
8591
+ var PrivateChannel = (function (_super) {
8607
8592
  private_channel_extends(PrivateChannel, _super);
8608
8593
  function PrivateChannel() {
8609
8594
  return _super !== null && _super.apply(this, arguments) || this;
8610
8595
  }
8611
8596
  PrivateChannel.prototype.authorize = function (socketId, callback) {
8612
- var authorizer = factory.createAuthorizer(this, this.pusher.config);
8613
- return authorizer.authorize(socketId, callback);
8597
+ return this.pusher.config.channelAuthorizer({
8598
+ channelName: this.name,
8599
+ socketId: socketId
8600
+ }, callback);
8614
8601
  };
8615
8602
  return PrivateChannel;
8616
8603
  }(channels_channel));
8617
- /* harmony default export */ var private_channel = (private_channel_PrivateChannel);
8604
+ /* harmony default export */ var private_channel = (PrivateChannel);
8618
8605
 
8619
8606
  // CONCATENATED MODULE: ./src/core/channels/members.ts
8620
8607
 
@@ -9214,6 +9201,9 @@ function createChannel(name, pusher) {
9214
9201
  else if (name.indexOf('presence-') === 0) {
9215
9202
  return factory.createPresenceChannel(name, pusher);
9216
9203
  }
9204
+ else if (name.indexOf('#') === 0) {
9205
+ throw new BadChannelName('Cannot create a channel with name "' + name + '".');
9206
+ }
9217
9207
  else {
9218
9208
  return factory.createChannel(name, pusher);
9219
9209
  }
@@ -9229,7 +9219,6 @@ function createChannel(name, pusher) {
9229
9219
 
9230
9220
 
9231
9221
 
9232
-
9233
9222
  var Factory = {
9234
9223
  createChannels: function () {
9235
9224
  return new channels();
@@ -9252,12 +9241,6 @@ var Factory = {
9252
9241
  createTimelineSender: function (timeline, options) {
9253
9242
  return new timeline_sender(timeline, options);
9254
9243
  },
9255
- createAuthorizer: function (channel, options) {
9256
- if (options.authorizer) {
9257
- return options.authorizer(channel, options);
9258
- }
9259
- return new pusher_authorizer(channel, options);
9260
- },
9261
9244
  createHandshake: function (transport, callback) {
9262
9245
  return new connection_handshake(transport, callback);
9263
9246
  },
@@ -10166,17 +10149,24 @@ var NetInfo = (function (_super) {
10166
10149
 
10167
10150
  var net_info_Network = new NetInfo();
10168
10151
 
10152
+ // CONCATENATED MODULE: ./src/core/auth/options.ts
10153
+ var AuthRequestType;
10154
+ (function (AuthRequestType) {
10155
+ AuthRequestType["UserAuthentication"] = "user-authentication";
10156
+ AuthRequestType["ChannelAuthorization"] = "channel-authorization";
10157
+ })(AuthRequestType || (AuthRequestType = {}));
10158
+
10169
10159
  // CONCATENATED MODULE: ./src/runtimes/isomorphic/auth/xhr_auth.ts
10170
10160
 
10171
10161
 
10172
10162
 
10173
- var ajax = function (context, socketId, callback) {
10174
- var self = this, xhr;
10175
- xhr = node_runtime.createXHR();
10176
- xhr.open('POST', self.options.authEndpoint, true);
10163
+
10164
+ var ajax = function (context, query, authOptions, authRequestType, callback) {
10165
+ var xhr = node_runtime.createXHR();
10166
+ xhr.open('POST', authOptions.endpoint, true);
10177
10167
  xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
10178
- for (var headerName in this.authOptions.headers) {
10179
- xhr.setRequestHeader(headerName, this.authOptions.headers[headerName]);
10168
+ for (var headerName in authOptions.headers) {
10169
+ xhr.setRequestHeader(headerName, authOptions.headers[headerName]);
10180
10170
  }
10181
10171
  xhr.onreadystatechange = function () {
10182
10172
  if (xhr.readyState === 4) {
@@ -10188,22 +10178,28 @@ var ajax = function (context, socketId, callback) {
10188
10178
  parsed = true;
10189
10179
  }
10190
10180
  catch (e) {
10191
- callback(new HTTPAuthError(200, 'JSON returned from auth endpoint was invalid, yet status code was 200. Data was: ' +
10192
- xhr.responseText), { auth: '' });
10181
+ callback(new HTTPAuthError(200, "JSON returned from " + authRequestType.toString() + " endpoint was invalid, yet status code was 200. Data was: " + xhr.responseText), null);
10193
10182
  }
10194
10183
  if (parsed) {
10195
10184
  callback(null, data);
10196
10185
  }
10197
10186
  }
10198
10187
  else {
10199
- var suffix = url_store.buildLogSuffix('authenticationEndpoint');
10200
- callback(new HTTPAuthError(xhr.status, 'Unable to retrieve auth string from auth endpoint - ' +
10201
- ("received status: " + xhr.status + " from " + self.options.authEndpoint + ". ") +
10202
- ("Clients must be authenticated to join private or presence channels. " + suffix)), { auth: '' });
10188
+ var suffix = '';
10189
+ switch (authRequestType) {
10190
+ case AuthRequestType.UserAuthentication:
10191
+ suffix = url_store.buildLogSuffix('authenticationEndpoint');
10192
+ break;
10193
+ case AuthRequestType.ChannelAuthorization:
10194
+ suffix = "Clients must be authenticated to join private or presence channels. " + url_store.buildLogSuffix('authorizationEndpoint');
10195
+ break;
10196
+ }
10197
+ callback(new HTTPAuthError(xhr.status, "Unable to retrieve auth string from " + authRequestType.toString() + " endpoint - " +
10198
+ ("received status: " + xhr.status + " from " + authOptions.endpoint + ". " + suffix)), null);
10203
10199
  }
10204
10200
  }
10205
10201
  };
10206
- xhr.send(this.composeQuery(socketId));
10202
+ xhr.send(query);
10207
10203
  return xhr;
10208
10204
  };
10209
10205
  /* harmony default export */ var xhr_auth = (ajax);
@@ -10502,14 +10498,94 @@ var strategy_builder_UnsupportedStrategy = {
10502
10498
  }
10503
10499
  };
10504
10500
 
10501
+ // CONCATENATED MODULE: ./src/core/auth/user_authenticator.ts
10502
+
10503
+
10504
+ var composeChannelQuery = function (params, authOptions) {
10505
+ var query = 'socket_id=' + encodeURIComponent(params.socketId);
10506
+ for (var i in authOptions.params) {
10507
+ query +=
10508
+ '&' +
10509
+ encodeURIComponent(i) +
10510
+ '=' +
10511
+ encodeURIComponent(authOptions.params[i]);
10512
+ }
10513
+ return query;
10514
+ };
10515
+ var UserAuthenticator = function (authOptions) {
10516
+ if (typeof node_runtime.getAuthorizers()[authOptions.transport] === 'undefined') {
10517
+ throw "'" + authOptions.transport + "' is not a recognized auth transport";
10518
+ }
10519
+ return function (params, callback) {
10520
+ var query = composeChannelQuery(params, authOptions);
10521
+ node_runtime.getAuthorizers()[authOptions.transport](node_runtime, query, authOptions, AuthRequestType.UserAuthentication, callback);
10522
+ };
10523
+ };
10524
+ /* harmony default export */ var user_authenticator = (UserAuthenticator);
10525
+
10526
+ // CONCATENATED MODULE: ./src/core/auth/channel_authorizer.ts
10527
+
10528
+
10529
+ var channel_authorizer_composeChannelQuery = function (params, authOptions) {
10530
+ var query = 'socket_id=' + encodeURIComponent(params.socketId);
10531
+ query += '&channel_name=' + encodeURIComponent(params.channelName);
10532
+ for (var i in authOptions.params) {
10533
+ query +=
10534
+ '&' +
10535
+ encodeURIComponent(i) +
10536
+ '=' +
10537
+ encodeURIComponent(authOptions.params[i]);
10538
+ }
10539
+ return query;
10540
+ };
10541
+ var ChannelAuthorizer = function (authOptions) {
10542
+ if (typeof node_runtime.getAuthorizers()[authOptions.transport] === 'undefined') {
10543
+ throw "'" + authOptions.transport + "' is not a recognized auth transport";
10544
+ }
10545
+ return function (params, callback) {
10546
+ var query = channel_authorizer_composeChannelQuery(params, authOptions);
10547
+ node_runtime.getAuthorizers()[authOptions.transport](node_runtime, query, authOptions, AuthRequestType.ChannelAuthorization, callback);
10548
+ };
10549
+ };
10550
+ /* harmony default export */ var channel_authorizer = (ChannelAuthorizer);
10551
+
10552
+ // CONCATENATED MODULE: ./src/core/auth/deprecated_channel_authorizer.ts
10553
+ var ChannelAuthorizerProxy = function (pusher, authOptions, channelAuthorizerGenerator) {
10554
+ var deprecatedAuthorizerOptions = {
10555
+ authTransport: authOptions.transport,
10556
+ authEndpoint: authOptions.endpoint,
10557
+ auth: {
10558
+ params: authOptions.params,
10559
+ headers: authOptions.headers
10560
+ }
10561
+ };
10562
+ return function (params, callback) {
10563
+ var channel = pusher.channel(params.channelName);
10564
+ var channelAuthorizer = channelAuthorizerGenerator(channel, deprecatedAuthorizerOptions);
10565
+ channelAuthorizer.authorize(params.socketId, callback);
10566
+ };
10567
+ };
10568
+
10505
10569
  // CONCATENATED MODULE: ./src/core/config.ts
10570
+ var __assign = (undefined && undefined.__assign) || function () {
10571
+ __assign = Object.assign || function(t) {
10572
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
10573
+ s = arguments[i];
10574
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
10575
+ t[p] = s[p];
10576
+ }
10577
+ return t;
10578
+ };
10579
+ return __assign.apply(this, arguments);
10580
+ };
10581
+
10582
+
10583
+
10506
10584
 
10507
10585
 
10508
- function getConfig(opts) {
10586
+ function getConfig(opts, pusher) {
10509
10587
  var config = {
10510
10588
  activityTimeout: opts.activityTimeout || defaults.activityTimeout,
10511
- authEndpoint: opts.authEndpoint || defaults.authEndpoint,
10512
- authTransport: opts.authTransport || defaults.authTransport,
10513
10589
  cluster: opts.cluster || defaults.cluster,
10514
10590
  httpPath: opts.httpPath || defaults.httpPath,
10515
10591
  httpPort: opts.httpPort || defaults.httpPort,
@@ -10523,12 +10599,10 @@ function getConfig(opts) {
10523
10599
  enableStats: getEnableStatsConfig(opts),
10524
10600
  httpHost: getHttpHost(opts),
10525
10601
  useTLS: shouldUseTLS(opts),
10526
- wsHost: getWebsocketHost(opts)
10602
+ wsHost: getWebsocketHost(opts),
10603
+ userAuthenticator: buildUserAuthenticator(opts),
10604
+ channelAuthorizer: buildChannelAuthorizer(opts, pusher)
10527
10605
  };
10528
- if ('auth' in opts)
10529
- config.auth = opts.auth;
10530
- if ('authorizer' in opts)
10531
- config.authorizer = opts.authorizer;
10532
10606
  if ('disabledTransports' in opts)
10533
10607
  config.disabledTransports = opts.disabledTransports;
10534
10608
  if ('enabledTransports' in opts)
@@ -10581,6 +10655,167 @@ function getEnableStatsConfig(opts) {
10581
10655
  }
10582
10656
  return false;
10583
10657
  }
10658
+ function buildUserAuthenticator(opts) {
10659
+ var userAuthentication = __assign({}, defaults.userAuthentication, opts.userAuthentication);
10660
+ if ('customHandler' in userAuthentication &&
10661
+ userAuthentication['customHandler'] != null) {
10662
+ return userAuthentication['customHandler'];
10663
+ }
10664
+ return user_authenticator(userAuthentication);
10665
+ }
10666
+ function buildChannelAuth(opts, pusher) {
10667
+ var channelAuthorization;
10668
+ if ('channelAuthorization' in opts) {
10669
+ channelAuthorization = __assign({}, defaults.channelAuthorization, opts.channelAuthorization);
10670
+ }
10671
+ else {
10672
+ channelAuthorization = {
10673
+ transport: opts.authTransport || defaults.authTransport,
10674
+ endpoint: opts.authEndpoint || defaults.authEndpoint
10675
+ };
10676
+ if ('auth' in opts) {
10677
+ if ('params' in opts.auth)
10678
+ channelAuthorization.params = opts.auth.params;
10679
+ if ('headers' in opts.auth)
10680
+ channelAuthorization.headers = opts.auth.headers;
10681
+ }
10682
+ if ('authorizer' in opts)
10683
+ channelAuthorization.customHandler = ChannelAuthorizerProxy(pusher, channelAuthorization, opts.authorizer);
10684
+ }
10685
+ return channelAuthorization;
10686
+ }
10687
+ function buildChannelAuthorizer(opts, pusher) {
10688
+ var channelAuthorization = buildChannelAuth(opts, pusher);
10689
+ if ('customHandler' in channelAuthorization &&
10690
+ channelAuthorization['customHandler'] != null) {
10691
+ return channelAuthorization['customHandler'];
10692
+ }
10693
+ return channel_authorizer(channelAuthorization);
10694
+ }
10695
+
10696
+ // CONCATENATED MODULE: ./src/core/user.ts
10697
+ var user_extends = (undefined && undefined.__extends) || (function () {
10698
+ var extendStatics = function (d, b) {
10699
+ extendStatics = Object.setPrototypeOf ||
10700
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
10701
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
10702
+ return extendStatics(d, b);
10703
+ };
10704
+ return function (d, b) {
10705
+ extendStatics(d, b);
10706
+ function __() { this.constructor = d; }
10707
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10708
+ };
10709
+ })();
10710
+
10711
+
10712
+
10713
+ var user_UserFacade = (function (_super) {
10714
+ user_extends(UserFacade, _super);
10715
+ function UserFacade(pusher) {
10716
+ var _this = _super.call(this, function (eventName, data) {
10717
+ logger.debug('No callbacks on user for ' + eventName);
10718
+ }) || this;
10719
+ _this.signin_requested = false;
10720
+ _this.user_data = null;
10721
+ _this.serverToUserChannel = null;
10722
+ _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();
10731
+ });
10732
+ _this.pusher.connection.bind('message', function (event) {
10733
+ var eventName = event.event;
10734
+ if (eventName === 'pusher:signin_success') {
10735
+ _this._onSigninSuccess(event.data);
10736
+ }
10737
+ if (_this.serverToUserChannel &&
10738
+ _this.serverToUserChannel.name === event.channel) {
10739
+ _this.serverToUserChannel.handleEvent(event);
10740
+ }
10741
+ });
10742
+ return _this;
10743
+ }
10744
+ UserFacade.prototype.signin = function () {
10745
+ if (this.signin_requested) {
10746
+ return;
10747
+ }
10748
+ this.signin_requested = true;
10749
+ this._signin();
10750
+ };
10751
+ UserFacade.prototype._signin = function () {
10752
+ var _this = this;
10753
+ if (!this.signin_requested) {
10754
+ return;
10755
+ }
10756
+ if (this.pusher.connection.state !== 'connected') {
10757
+ return;
10758
+ }
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
+ this.pusher.config.userAuthenticator({
10770
+ socketId: this.pusher.connection.socket_id
10771
+ }, onAuthorize);
10772
+ };
10773
+ UserFacade.prototype._onSigninSuccess = function (data) {
10774
+ try {
10775
+ this.user_data = JSON.parse(data.user_data);
10776
+ }
10777
+ catch (e) {
10778
+ logger.error("Failed parsing user data after signin: " + data.user_data);
10779
+ return;
10780
+ }
10781
+ if (typeof this.user_data.id !== 'string' || this.user_data.id === '') {
10782
+ logger.error("user_data doesn't contain an id. user_data: " + this.user_data);
10783
+ return;
10784
+ }
10785
+ this._subscribeChannels();
10786
+ };
10787
+ UserFacade.prototype._subscribeChannels = function () {
10788
+ var _this = this;
10789
+ var ensure_subscribed = function (channel) {
10790
+ if (channel.subscriptionPending && channel.subscriptionCancelled) {
10791
+ channel.reinstateSubscription();
10792
+ }
10793
+ else if (!channel.subscriptionPending &&
10794
+ _this.pusher.connection.state === 'connected') {
10795
+ channel.subscribe();
10796
+ }
10797
+ };
10798
+ this.serverToUserChannel = new channels_channel("#server-to-user-" + this.user_data.id, this.pusher);
10799
+ this.serverToUserChannel.bind_global(function (eventName, data) {
10800
+ if (eventName.indexOf('pusher_internal:') === 0 ||
10801
+ eventName.indexOf('pusher:') === 0) {
10802
+ return;
10803
+ }
10804
+ _this.emit(eventName, data);
10805
+ });
10806
+ ensure_subscribed(this.serverToUserChannel);
10807
+ };
10808
+ UserFacade.prototype._disconnect = function () {
10809
+ this.user_data = null;
10810
+ if (this.serverToUserChannel) {
10811
+ this.serverToUserChannel.unbind_all();
10812
+ this.serverToUserChannel.disconnect();
10813
+ this.serverToUserChannel = null;
10814
+ }
10815
+ };
10816
+ return UserFacade;
10817
+ }(dispatcher));
10818
+ /* harmony default export */ var user = (user_UserFacade);
10584
10819
 
10585
10820
  // CONCATENATED MODULE: ./src/core/pusher.ts
10586
10821
 
@@ -10595,6 +10830,7 @@ function getEnableStatsConfig(opts) {
10595
10830
 
10596
10831
 
10597
10832
 
10833
+
10598
10834
  var pusher_Pusher = (function () {
10599
10835
  function Pusher(app_key, options) {
10600
10836
  var _this = this;
@@ -10608,7 +10844,7 @@ var pusher_Pusher = (function () {
10608
10844
  logger.warn('The disableStats option is deprecated in favor of enableStats');
10609
10845
  }
10610
10846
  this.key = app_key;
10611
- this.config = getConfig(options);
10847
+ this.config = getConfig(options, this);
10612
10848
  this.channels = factory.createChannels();
10613
10849
  this.global_emitter = new dispatcher();
10614
10850
  this.sessionID = Math.floor(Math.random() * 1000000000);
@@ -10667,6 +10903,7 @@ var pusher_Pusher = (function () {
10667
10903
  });
10668
10904
  Pusher.instances.push(this);
10669
10905
  this.timeline.info({ instances: Pusher.instances.length });
10906
+ this.user = new user(this);
10670
10907
  if (Pusher.isReady) {
10671
10908
  this.connect();
10672
10909
  }
@@ -10764,6 +11001,9 @@ var pusher_Pusher = (function () {
10764
11001
  Pusher.prototype.shouldUseTLS = function () {
10765
11002
  return this.config.useTLS;
10766
11003
  };
11004
+ Pusher.prototype.signin = function () {
11005
+ this.user.signin();
11006
+ };
10767
11007
  Pusher.instances = [];
10768
11008
  Pusher.isReady = false;
10769
11009
  Pusher.logToConsole = false;