pusher-js 7.0.6 → 7.2.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 (106) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +27 -87
  3. package/dist/node/pusher.js +325 -73
  4. package/dist/node/pusher.js.map +1 -1
  5. package/dist/react-native/pusher.js +2 -2
  6. package/dist/react-native/pusher.js.map +1 -1
  7. package/dist/web/pusher-with-encryption.js +330 -78
  8. package/dist/web/pusher-with-encryption.js.map +1 -1
  9. package/dist/web/pusher-with-encryption.min.js +2 -2
  10. package/dist/web/pusher-with-encryption.min.js.map +1 -1
  11. package/dist/web/pusher.js +330 -78
  12. package/dist/web/pusher.js.map +1 -1
  13. package/dist/web/pusher.min.js +2 -2
  14. package/dist/web/pusher.min.js.map +1 -1
  15. package/dist/worker/pusher-with-encryption.worker.js +314 -69
  16. package/dist/worker/pusher-with-encryption.worker.js.map +1 -1
  17. package/dist/worker/pusher-with-encryption.worker.min.js +2 -2
  18. package/dist/worker/pusher-with-encryption.worker.min.js.map +1 -1
  19. package/dist/worker/pusher.worker.js +314 -69
  20. package/dist/worker/pusher.worker.js.map +1 -1
  21. package/dist/worker/pusher.worker.min.js +2 -2
  22. package/dist/worker/pusher.worker.min.js.map +1 -1
  23. package/index.d.ts +8 -3
  24. package/package.json +2 -2
  25. package/spec/config/karma/config.worker.js +3 -0
  26. package/spec/config/karma/integration.js +4 -2
  27. package/spec/javascripts/helpers/mocks.js +41 -8
  28. package/spec/javascripts/helpers/worker/mock-dom-dependencies.js +1 -0
  29. package/spec/javascripts/integration/core/cluster_config_spec.js +8 -0
  30. package/spec/javascripts/integration/core/timeout_configuration_spec.js +1 -0
  31. package/spec/javascripts/integration/index.worker.js +12 -1
  32. package/spec/javascripts/unit/core/channels/channel_spec.js +25 -0
  33. package/spec/javascripts/unit/core/channels/encrypted_channel_spec.js +64 -66
  34. package/spec/javascripts/unit/core/channels/presence_channel_spec.js +51 -41
  35. package/spec/javascripts/unit/core/channels/private_channel_spec.js +8 -46
  36. package/spec/javascripts/unit/core/config_spec.js +307 -7
  37. package/spec/javascripts/unit/core/connection/connection_manager_spec.js +1 -0
  38. package/spec/javascripts/unit/core/http/http_socket_spec.js +1 -0
  39. package/spec/javascripts/unit/core/logger_spec.js +21 -20
  40. package/spec/javascripts/unit/core/pusher_spec.js +67 -39
  41. package/spec/javascripts/unit/core/pusher_with_encryption_spec.js +2 -0
  42. package/spec/javascripts/unit/core/strategies/cached_strategy_spec.js +1 -0
  43. package/spec/javascripts/unit/core/strategies/delayed_strategy_spec.js +1 -0
  44. package/spec/javascripts/unit/core/strategies/sequential_strategy_spec.js +1 -0
  45. package/spec/javascripts/unit/core/strategies/transport_strategy_spec.js +1 -0
  46. package/spec/javascripts/unit/core/transports/assistant_to_the_transport_manager_spec.js +1 -0
  47. package/spec/javascripts/unit/core/user_spec.js +295 -0
  48. package/spec/javascripts/unit/core/utils/periodic_timer_spec.js +4 -1
  49. package/spec/javascripts/unit/core/utils/timers_spec.js +6 -0
  50. package/spec/javascripts/unit/core/utils/url_store_spec.js +1 -1
  51. package/spec/javascripts/unit/core_with_runtime/auth/channel_authorizer_spec.js +55 -0
  52. package/spec/javascripts/unit/core_with_runtime/auth/deprecated_channel_authorizer_spec.js +48 -0
  53. package/spec/javascripts/unit/core_with_runtime/auth/user_authorizer_spec.js +52 -0
  54. package/spec/javascripts/unit/core_with_runtime/readme.md +5 -0
  55. package/spec/javascripts/unit/index.node.js +3 -0
  56. package/spec/javascripts/unit/index.web.js +3 -0
  57. package/spec/javascripts/unit/index.worker.js +3 -0
  58. package/spec/javascripts/unit/web/pusher_authorizer_spec.js +15 -16
  59. package/spec/javascripts/unit/web/transports/hosts_and_ports_spec.js +1 -0
  60. package/spec/javascripts/unit/worker/channel_authorizer_spec.js +110 -0
  61. package/src/core/auth/auth_transports.ts +8 -1
  62. package/src/core/auth/channel_authorizer.ts +53 -0
  63. package/src/core/auth/deprecated_channel_authorizer.ts +58 -0
  64. package/src/core/auth/options.ts +52 -17
  65. package/src/core/auth/user_authenticator.ts +51 -0
  66. package/src/core/channels/channel.ts +17 -3
  67. package/src/core/channels/channels.ts +4 -0
  68. package/src/core/channels/encrypted_channel.ts +26 -20
  69. package/src/core/channels/presence_channel.ts +5 -2
  70. package/src/core/channels/private_channel.ts +9 -4
  71. package/src/core/config.ts +76 -11
  72. package/src/core/defaults.ts +15 -0
  73. package/src/core/errors.ts +9 -0
  74. package/src/core/options.ts +18 -5
  75. package/src/core/pusher.ts +9 -1
  76. package/src/core/user.ts +143 -0
  77. package/src/core/utils/factory.ts +1 -10
  78. package/src/core/utils/url_store.ts +4 -1
  79. package/src/runtimes/isomorphic/auth/xhr_auth.ts +32 -19
  80. package/src/runtimes/web/auth/jsonp_auth.ts +13 -7
  81. package/src/runtimes/worker/auth/fetch_auth.ts +17 -12
  82. package/types/src/core/auth/auth_transports.d.ts +2 -1
  83. package/types/src/core/auth/channel_authorizer.d.ts +3 -0
  84. package/types/src/core/auth/deprecated_channel_authorizer.d.ts +18 -0
  85. package/types/src/core/auth/options.d.ts +34 -15
  86. package/types/src/core/auth/user_authenticator.d.ts +3 -0
  87. package/types/src/core/channels/channel.d.ts +4 -2
  88. package/types/src/core/channels/encrypted_channel.d.ts +2 -2
  89. package/types/src/core/channels/private_channel.d.ts +2 -2
  90. package/types/src/core/config.d.ts +4 -6
  91. package/types/src/core/defaults.d.ts +3 -0
  92. package/types/src/core/errors.d.ts +3 -0
  93. package/types/src/core/options.d.ts +6 -3
  94. package/types/src/core/pusher.d.ts +3 -0
  95. package/types/src/core/user.d.ts +15 -0
  96. package/types/src/core/utils/factory.d.ts +0 -2
  97. package/types/src/runtimes/isomorphic/auth/xhr_auth.d.ts +1 -1
  98. package/worker/with-encryption/index.js +1 -1
  99. package/spec/javascripts/unit/core/pusher_authorizer_spec.js +0 -160
  100. package/spec/javascripts/unit/worker/pusher_authorizer_spec.js +0 -111
  101. package/src/core/auth/pusher_authorizer.ts +0 -64
  102. package/types/index.d.ts +0 -15
  103. package/types/src/core/auth/pusher_authorizer.d.ts +0 -13
  104. package/types/src/core/index.d.ts +0 -6
  105. package/types/src/runtimes/react-native/tweetnacl-dummy.d.ts +0 -5
  106. package/types/src/runtimes/react-native/tweetnacl-util-dummy.d.ts +0 -7
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Pusher JavaScript Library v7.0.6
2
+ * Pusher JavaScript Library v7.2.0
3
3
  * https://pusher.com/
4
4
  *
5
5
  * Copyright 2020, Pusher
@@ -2995,7 +2995,7 @@ var ScriptReceivers = new ScriptReceiverFactory('_pusher_script_', 'Pusher.Scrip
2995
2995
 
2996
2996
  // CONCATENATED MODULE: ./src/core/defaults.ts
2997
2997
  var Defaults = {
2998
- VERSION: "7.0.6",
2998
+ VERSION: "7.2.0",
2999
2999
  PROTOCOL: 7,
3000
3000
  wsPort: 80,
3001
3001
  wssPort: 443,
@@ -3011,6 +3011,14 @@ var Defaults = {
3011
3011
  pongTimeout: 30000,
3012
3012
  unavailableTimeout: 10000,
3013
3013
  cluster: 'mt1',
3014
+ userAuthentication: {
3015
+ endpoint: '/pusher/user-auth',
3016
+ transport: 'ajax'
3017
+ },
3018
+ channelAuthorization: {
3019
+ endpoint: '/pusher/auth',
3020
+ transport: 'ajax'
3021
+ },
3014
3022
  cdn_http: "http://js.pusher.com",
3015
3023
  cdn_https: "https://js.pusher.com",
3016
3024
  dependency_suffix: ""
@@ -3088,7 +3096,10 @@ var urlStore = {
3088
3096
  baseUrl: 'https://pusher.com',
3089
3097
  urls: {
3090
3098
  authenticationEndpoint: {
3091
- path: '/docs/authenticating_users'
3099
+ path: '/docs/channels/server_api/authenticating_users'
3100
+ },
3101
+ authorizationEndpoint: {
3102
+ path: '/docs/channels/server_api/authorizing-users/'
3092
3103
  },
3093
3104
  javascriptQuickStart: {
3094
3105
  path: '/docs/javascript_quick_start'
@@ -3119,6 +3130,13 @@ var buildLogSuffix = function (key) {
3119
3130
  };
3120
3131
  /* harmony default export */ var url_store = ({ buildLogSuffix: buildLogSuffix });
3121
3132
 
3133
+ // CONCATENATED MODULE: ./src/core/auth/options.ts
3134
+ var AuthRequestType;
3135
+ (function (AuthRequestType) {
3136
+ AuthRequestType["UserAuthentication"] = "user-authentication";
3137
+ AuthRequestType["ChannelAuthorization"] = "channel-authorization";
3138
+ })(AuthRequestType || (AuthRequestType = {}));
3139
+
3122
3140
  // CONCATENATED MODULE: ./src/core/errors.ts
3123
3141
  var __extends = (undefined && undefined.__extends) || (function () {
3124
3142
  var extendStatics = function (d, b) {
@@ -3144,6 +3162,17 @@ var BadEventName = (function (_super) {
3144
3162
  return BadEventName;
3145
3163
  }(Error));
3146
3164
 
3165
+ var BadChannelName = (function (_super) {
3166
+ __extends(BadChannelName, _super);
3167
+ function BadChannelName(msg) {
3168
+ var _newTarget = this.constructor;
3169
+ var _this = _super.call(this, msg) || this;
3170
+ Object.setPrototypeOf(_this, _newTarget.prototype);
3171
+ return _this;
3172
+ }
3173
+ return BadChannelName;
3174
+ }(Error));
3175
+
3147
3176
  var RequestTimedOut = (function (_super) {
3148
3177
  __extends(RequestTimedOut, _super);
3149
3178
  function RequestTimedOut(msg) {
@@ -3227,13 +3256,13 @@ var HTTPAuthError = (function (_super) {
3227
3256
 
3228
3257
 
3229
3258
 
3230
- var ajax = function (context, socketId, callback) {
3231
- var self = this, xhr;
3232
- xhr = runtime.createXHR();
3233
- xhr.open('POST', self.options.authEndpoint, true);
3259
+
3260
+ var ajax = function (context, query, authOptions, authRequestType, callback) {
3261
+ var xhr = runtime.createXHR();
3262
+ xhr.open('POST', authOptions.endpoint, true);
3234
3263
  xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
3235
- for (var headerName in this.authOptions.headers) {
3236
- xhr.setRequestHeader(headerName, this.authOptions.headers[headerName]);
3264
+ for (var headerName in authOptions.headers) {
3265
+ xhr.setRequestHeader(headerName, authOptions.headers[headerName]);
3237
3266
  }
3238
3267
  xhr.onreadystatechange = function () {
3239
3268
  if (xhr.readyState === 4) {
@@ -3245,22 +3274,28 @@ var ajax = function (context, socketId, callback) {
3245
3274
  parsed = true;
3246
3275
  }
3247
3276
  catch (e) {
3248
- callback(new HTTPAuthError(200, 'JSON returned from auth endpoint was invalid, yet status code was 200. Data was: ' +
3249
- xhr.responseText), { auth: '' });
3277
+ callback(new HTTPAuthError(200, "JSON returned from " + authRequestType.toString() + " endpoint was invalid, yet status code was 200. Data was: " + xhr.responseText), null);
3250
3278
  }
3251
3279
  if (parsed) {
3252
3280
  callback(null, data);
3253
3281
  }
3254
3282
  }
3255
3283
  else {
3256
- var suffix = url_store.buildLogSuffix('authenticationEndpoint');
3257
- callback(new HTTPAuthError(xhr.status, 'Unable to retrieve auth string from auth endpoint - ' +
3258
- ("received status: " + xhr.status + " from " + self.options.authEndpoint + ". ") +
3259
- ("Clients must be authenticated to join private or presence channels. " + suffix)), { auth: '' });
3284
+ var suffix = '';
3285
+ switch (authRequestType) {
3286
+ case AuthRequestType.UserAuthentication:
3287
+ suffix = url_store.buildLogSuffix('authenticationEndpoint');
3288
+ break;
3289
+ case AuthRequestType.ChannelAuthorization:
3290
+ suffix = "Clients must be authenticated to join private or presence channels. " + url_store.buildLogSuffix('authorizationEndpoint');
3291
+ break;
3292
+ }
3293
+ callback(new HTTPAuthError(xhr.status, "Unable to retrieve auth string from " + authRequestType.toString() + " endpoint - " +
3294
+ ("received status: " + xhr.status + " from " + authOptions.endpoint + ". " + suffix)), null);
3260
3295
  }
3261
3296
  }
3262
3297
  };
3263
- xhr.send(this.composeQuery(socketId));
3298
+ xhr.send(query);
3264
3299
  return xhr;
3265
3300
  };
3266
3301
  /* harmony default export */ var xhr_auth = (ajax);
@@ -3667,9 +3702,9 @@ var logger_Logger = (function () {
3667
3702
 
3668
3703
  // CONCATENATED MODULE: ./src/runtimes/web/auth/jsonp_auth.ts
3669
3704
 
3670
- var jsonp = function (context, socketId, callback) {
3671
- if (this.authOptions.headers !== undefined) {
3672
- logger.warn('To send headers with the auth request, you must use AJAX, rather than JSONP.');
3705
+ var jsonp = function (context, query, authOptions, authRequestType, callback) {
3706
+ if (authOptions.headers !== undefined) {
3707
+ logger.warn("To send headers with the " + authRequestType.toString() + " request, you must use AJAX, rather than JSONP.");
3673
3708
  }
3674
3709
  var callbackName = context.nextAuthCallbackID.toString();
3675
3710
  context.nextAuthCallbackID++;
@@ -3680,11 +3715,11 @@ var jsonp = function (context, socketId, callback) {
3680
3715
  };
3681
3716
  var callback_name = "Pusher.auth_callbacks['" + callbackName + "']";
3682
3717
  script.src =
3683
- this.options.authEndpoint +
3718
+ authOptions.endpoint +
3684
3719
  '?callback=' +
3685
3720
  encodeURIComponent(callback_name) +
3686
3721
  '&' +
3687
- this.composeQuery(socketId);
3722
+ query;
3688
3723
  var head = document.getElementsByTagName('head')[0] || document.documentElement;
3689
3724
  head.insertBefore(script, head.firstChild);
3690
3725
  };
@@ -4603,42 +4638,6 @@ var handshake_Handshake = (function () {
4603
4638
  }());
4604
4639
  /* harmony default export */ var connection_handshake = (handshake_Handshake);
4605
4640
 
4606
- // CONCATENATED MODULE: ./src/core/auth/pusher_authorizer.ts
4607
-
4608
- var pusher_authorizer_PusherAuthorizer = (function () {
4609
- function PusherAuthorizer(channel, options) {
4610
- this.channel = channel;
4611
- var authTransport = options.authTransport;
4612
- if (typeof runtime.getAuthorizers()[authTransport] === 'undefined') {
4613
- throw "'" + authTransport + "' is not a recognized auth transport";
4614
- }
4615
- this.type = authTransport;
4616
- this.options = options;
4617
- this.authOptions = options.auth || {};
4618
- }
4619
- PusherAuthorizer.prototype.composeQuery = function (socketId) {
4620
- var query = 'socket_id=' +
4621
- encodeURIComponent(socketId) +
4622
- '&channel_name=' +
4623
- encodeURIComponent(this.channel.name);
4624
- for (var i in this.authOptions.params) {
4625
- query +=
4626
- '&' +
4627
- encodeURIComponent(i) +
4628
- '=' +
4629
- encodeURIComponent(this.authOptions.params[i]);
4630
- }
4631
- return query;
4632
- };
4633
- PusherAuthorizer.prototype.authorize = function (socketId, callback) {
4634
- PusherAuthorizer.authorizers =
4635
- PusherAuthorizer.authorizers || runtime.getAuthorizers();
4636
- PusherAuthorizer.authorizers[this.type].call(this, runtime, socketId, callback);
4637
- };
4638
- return PusherAuthorizer;
4639
- }());
4640
- /* harmony default export */ var pusher_authorizer = (pusher_authorizer_PusherAuthorizer);
4641
-
4642
4641
  // CONCATENATED MODULE: ./src/core/timeline/timeline_sender.ts
4643
4642
 
4644
4643
  var timeline_sender_TimelineSender = (function () {
@@ -4711,6 +4710,9 @@ var channel_Channel = (function (_super) {
4711
4710
  if (eventName === 'pusher_internal:subscription_succeeded') {
4712
4711
  this.handleSubscriptionSucceededEvent(event);
4713
4712
  }
4713
+ else if (eventName === 'pusher_internal:subscription_count') {
4714
+ this.handleSubscriptionCountEvent(event);
4715
+ }
4714
4716
  else if (eventName.indexOf('pusher_internal:') !== 0) {
4715
4717
  var metadata = {};
4716
4718
  this.emit(eventName, data, metadata);
@@ -4726,6 +4728,12 @@ var channel_Channel = (function (_super) {
4726
4728
  this.emit('pusher:subscription_succeeded', event.data);
4727
4729
  }
4728
4730
  };
4731
+ Channel.prototype.handleSubscriptionCountEvent = function (event) {
4732
+ if (event.data.subscription_count) {
4733
+ this.subscriptionCount = event.data.subscription_count;
4734
+ }
4735
+ this.emit('pusher:subscription_count', event.data);
4736
+ };
4729
4737
  Channel.prototype.subscribe = function () {
4730
4738
  var _this = this;
4731
4739
  if (this.subscribed) {
@@ -4782,19 +4790,20 @@ var private_channel_extends = (undefined && undefined.__extends) || (function ()
4782
4790
  };
4783
4791
  })();
4784
4792
 
4785
-
4786
- var private_channel_PrivateChannel = (function (_super) {
4793
+ var PrivateChannel = (function (_super) {
4787
4794
  private_channel_extends(PrivateChannel, _super);
4788
4795
  function PrivateChannel() {
4789
4796
  return _super !== null && _super.apply(this, arguments) || this;
4790
4797
  }
4791
4798
  PrivateChannel.prototype.authorize = function (socketId, callback) {
4792
- var authorizer = factory.createAuthorizer(this, this.pusher.config);
4793
- return authorizer.authorize(socketId, callback);
4799
+ return this.pusher.config.channelAuthorizer({
4800
+ channelName: this.name,
4801
+ socketId: socketId
4802
+ }, callback);
4794
4803
  };
4795
4804
  return PrivateChannel;
4796
4805
  }(channels_channel));
4797
- /* harmony default export */ var private_channel = (private_channel_PrivateChannel);
4806
+ /* harmony default export */ var private_channel = (PrivateChannel);
4798
4807
 
4799
4808
  // CONCATENATED MODULE: ./src/core/channels/members.ts
4800
4809
 
@@ -4916,6 +4925,9 @@ var presence_channel_PresenceChannel = (function (_super) {
4916
4925
  case 'pusher_internal:subscription_succeeded':
4917
4926
  this.handleSubscriptionSucceededEvent(event);
4918
4927
  break;
4928
+ case 'pusher_internal:subscription_count':
4929
+ this.handleSubscriptionCountEvent(event);
4930
+ break;
4919
4931
  case 'pusher_internal:member_added':
4920
4932
  var addedMember = this.members.addMember(data);
4921
4933
  this.emit('pusher:member_added', addedMember);
@@ -5394,6 +5406,9 @@ function createChannel(name, pusher) {
5394
5406
  else if (name.indexOf('presence-') === 0) {
5395
5407
  return factory.createPresenceChannel(name, pusher);
5396
5408
  }
5409
+ else if (name.indexOf('#') === 0) {
5410
+ throw new BadChannelName('Cannot create a channel with name "' + name + '".');
5411
+ }
5397
5412
  else {
5398
5413
  return factory.createChannel(name, pusher);
5399
5414
  }
@@ -5409,7 +5424,6 @@ function createChannel(name, pusher) {
5409
5424
 
5410
5425
 
5411
5426
 
5412
-
5413
5427
  var Factory = {
5414
5428
  createChannels: function () {
5415
5429
  return new channels();
@@ -5432,12 +5446,6 @@ var Factory = {
5432
5446
  createTimelineSender: function (timeline, options) {
5433
5447
  return new timeline_sender(timeline, options);
5434
5448
  },
5435
- createAuthorizer: function (channel, options) {
5436
- if (options.authorizer) {
5437
- return options.authorizer(channel, options);
5438
- }
5439
- return new pusher_authorizer(channel, options);
5440
- },
5441
5449
  createHandshake: function (transport, callback) {
5442
5450
  return new connection_handshake(transport, callback);
5443
5451
  },
@@ -6684,14 +6692,94 @@ var strategy_builder_UnsupportedStrategy = {
6684
6692
  }
6685
6693
  };
6686
6694
 
6695
+ // CONCATENATED MODULE: ./src/core/auth/user_authenticator.ts
6696
+
6697
+
6698
+ var composeChannelQuery = function (params, authOptions) {
6699
+ var query = 'socket_id=' + encodeURIComponent(params.socketId);
6700
+ for (var i in authOptions.params) {
6701
+ query +=
6702
+ '&' +
6703
+ encodeURIComponent(i) +
6704
+ '=' +
6705
+ encodeURIComponent(authOptions.params[i]);
6706
+ }
6707
+ return query;
6708
+ };
6709
+ var UserAuthenticator = function (authOptions) {
6710
+ if (typeof runtime.getAuthorizers()[authOptions.transport] === 'undefined') {
6711
+ throw "'" + authOptions.transport + "' is not a recognized auth transport";
6712
+ }
6713
+ return function (params, callback) {
6714
+ var query = composeChannelQuery(params, authOptions);
6715
+ runtime.getAuthorizers()[authOptions.transport](runtime, query, authOptions, AuthRequestType.UserAuthentication, callback);
6716
+ };
6717
+ };
6718
+ /* harmony default export */ var user_authenticator = (UserAuthenticator);
6719
+
6720
+ // CONCATENATED MODULE: ./src/core/auth/channel_authorizer.ts
6721
+
6722
+
6723
+ var channel_authorizer_composeChannelQuery = function (params, authOptions) {
6724
+ var query = 'socket_id=' + encodeURIComponent(params.socketId);
6725
+ query += '&channel_name=' + encodeURIComponent(params.channelName);
6726
+ for (var i in authOptions.params) {
6727
+ query +=
6728
+ '&' +
6729
+ encodeURIComponent(i) +
6730
+ '=' +
6731
+ encodeURIComponent(authOptions.params[i]);
6732
+ }
6733
+ return query;
6734
+ };
6735
+ var ChannelAuthorizer = function (authOptions) {
6736
+ if (typeof runtime.getAuthorizers()[authOptions.transport] === 'undefined') {
6737
+ throw "'" + authOptions.transport + "' is not a recognized auth transport";
6738
+ }
6739
+ return function (params, callback) {
6740
+ var query = channel_authorizer_composeChannelQuery(params, authOptions);
6741
+ runtime.getAuthorizers()[authOptions.transport](runtime, query, authOptions, AuthRequestType.ChannelAuthorization, callback);
6742
+ };
6743
+ };
6744
+ /* harmony default export */ var channel_authorizer = (ChannelAuthorizer);
6745
+
6746
+ // CONCATENATED MODULE: ./src/core/auth/deprecated_channel_authorizer.ts
6747
+ var ChannelAuthorizerProxy = function (pusher, authOptions, channelAuthorizerGenerator) {
6748
+ var deprecatedAuthorizerOptions = {
6749
+ authTransport: authOptions.transport,
6750
+ authEndpoint: authOptions.endpoint,
6751
+ auth: {
6752
+ params: authOptions.params,
6753
+ headers: authOptions.headers
6754
+ }
6755
+ };
6756
+ return function (params, callback) {
6757
+ var channel = pusher.channel(params.channelName);
6758
+ var channelAuthorizer = channelAuthorizerGenerator(channel, deprecatedAuthorizerOptions);
6759
+ channelAuthorizer.authorize(params.socketId, callback);
6760
+ };
6761
+ };
6762
+
6687
6763
  // CONCATENATED MODULE: ./src/core/config.ts
6764
+ var __assign = (undefined && undefined.__assign) || function () {
6765
+ __assign = Object.assign || function(t) {
6766
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6767
+ s = arguments[i];
6768
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6769
+ t[p] = s[p];
6770
+ }
6771
+ return t;
6772
+ };
6773
+ return __assign.apply(this, arguments);
6774
+ };
6775
+
6688
6776
 
6689
6777
 
6690
- function getConfig(opts) {
6778
+
6779
+
6780
+ function getConfig(opts, pusher) {
6691
6781
  var config = {
6692
6782
  activityTimeout: opts.activityTimeout || defaults.activityTimeout,
6693
- authEndpoint: opts.authEndpoint || defaults.authEndpoint,
6694
- authTransport: opts.authTransport || defaults.authTransport,
6695
6783
  cluster: opts.cluster || defaults.cluster,
6696
6784
  httpPath: opts.httpPath || defaults.httpPath,
6697
6785
  httpPort: opts.httpPort || defaults.httpPort,
@@ -6705,12 +6793,10 @@ function getConfig(opts) {
6705
6793
  enableStats: getEnableStatsConfig(opts),
6706
6794
  httpHost: getHttpHost(opts),
6707
6795
  useTLS: shouldUseTLS(opts),
6708
- wsHost: getWebsocketHost(opts)
6796
+ wsHost: getWebsocketHost(opts),
6797
+ userAuthenticator: buildUserAuthenticator(opts),
6798
+ channelAuthorizer: buildChannelAuthorizer(opts, pusher)
6709
6799
  };
6710
- if ('auth' in opts)
6711
- config.auth = opts.auth;
6712
- if ('authorizer' in opts)
6713
- config.authorizer = opts.authorizer;
6714
6800
  if ('disabledTransports' in opts)
6715
6801
  config.disabledTransports = opts.disabledTransports;
6716
6802
  if ('enabledTransports' in opts)
@@ -6763,6 +6849,167 @@ function getEnableStatsConfig(opts) {
6763
6849
  }
6764
6850
  return false;
6765
6851
  }
6852
+ function buildUserAuthenticator(opts) {
6853
+ var userAuthentication = __assign({}, defaults.userAuthentication, opts.userAuthentication);
6854
+ if ('customHandler' in userAuthentication &&
6855
+ userAuthentication['customHandler'] != null) {
6856
+ return userAuthentication['customHandler'];
6857
+ }
6858
+ return user_authenticator(userAuthentication);
6859
+ }
6860
+ function buildChannelAuth(opts, pusher) {
6861
+ var channelAuthorization;
6862
+ if ('channelAuthorization' in opts) {
6863
+ channelAuthorization = __assign({}, defaults.channelAuthorization, opts.channelAuthorization);
6864
+ }
6865
+ else {
6866
+ channelAuthorization = {
6867
+ transport: opts.authTransport || defaults.authTransport,
6868
+ endpoint: opts.authEndpoint || defaults.authEndpoint
6869
+ };
6870
+ if ('auth' in opts) {
6871
+ if ('params' in opts.auth)
6872
+ channelAuthorization.params = opts.auth.params;
6873
+ if ('headers' in opts.auth)
6874
+ channelAuthorization.headers = opts.auth.headers;
6875
+ }
6876
+ if ('authorizer' in opts)
6877
+ channelAuthorization.customHandler = ChannelAuthorizerProxy(pusher, channelAuthorization, opts.authorizer);
6878
+ }
6879
+ return channelAuthorization;
6880
+ }
6881
+ function buildChannelAuthorizer(opts, pusher) {
6882
+ var channelAuthorization = buildChannelAuth(opts, pusher);
6883
+ if ('customHandler' in channelAuthorization &&
6884
+ channelAuthorization['customHandler'] != null) {
6885
+ return channelAuthorization['customHandler'];
6886
+ }
6887
+ return channel_authorizer(channelAuthorization);
6888
+ }
6889
+
6890
+ // CONCATENATED MODULE: ./src/core/user.ts
6891
+ var user_extends = (undefined && undefined.__extends) || (function () {
6892
+ var extendStatics = function (d, b) {
6893
+ extendStatics = Object.setPrototypeOf ||
6894
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6895
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6896
+ return extendStatics(d, b);
6897
+ };
6898
+ return function (d, b) {
6899
+ extendStatics(d, b);
6900
+ function __() { this.constructor = d; }
6901
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
6902
+ };
6903
+ })();
6904
+
6905
+
6906
+
6907
+ var user_UserFacade = (function (_super) {
6908
+ user_extends(UserFacade, _super);
6909
+ function UserFacade(pusher) {
6910
+ var _this = _super.call(this, function (eventName, data) {
6911
+ logger.debug('No callbacks on user for ' + eventName);
6912
+ }) || this;
6913
+ _this.signin_requested = false;
6914
+ _this.user_data = null;
6915
+ _this.serverToUserChannel = null;
6916
+ _this.pusher = pusher;
6917
+ _this.pusher.connection.bind('connected', function () {
6918
+ _this._signin();
6919
+ });
6920
+ _this.pusher.connection.bind('connecting', function () {
6921
+ _this._disconnect();
6922
+ });
6923
+ _this.pusher.connection.bind('disconnected', function () {
6924
+ _this._disconnect();
6925
+ });
6926
+ _this.pusher.connection.bind('message', function (event) {
6927
+ var eventName = event.event;
6928
+ if (eventName === 'pusher:signin_success') {
6929
+ _this._onSigninSuccess(event.data);
6930
+ }
6931
+ if (_this.serverToUserChannel &&
6932
+ _this.serverToUserChannel.name === event.channel) {
6933
+ _this.serverToUserChannel.handleEvent(event);
6934
+ }
6935
+ });
6936
+ return _this;
6937
+ }
6938
+ UserFacade.prototype.signin = function () {
6939
+ if (this.signin_requested) {
6940
+ return;
6941
+ }
6942
+ this.signin_requested = true;
6943
+ this._signin();
6944
+ };
6945
+ UserFacade.prototype._signin = function () {
6946
+ var _this = this;
6947
+ if (!this.signin_requested) {
6948
+ return;
6949
+ }
6950
+ if (this.pusher.connection.state !== 'connected') {
6951
+ return;
6952
+ }
6953
+ var onAuthorize = function (err, authData) {
6954
+ if (err) {
6955
+ logger.warn("Error during signin: " + err);
6956
+ return;
6957
+ }
6958
+ _this.pusher.send_event('pusher:signin', {
6959
+ auth: authData.auth,
6960
+ user_data: authData.user_data
6961
+ });
6962
+ };
6963
+ this.pusher.config.userAuthenticator({
6964
+ socketId: this.pusher.connection.socket_id
6965
+ }, onAuthorize);
6966
+ };
6967
+ UserFacade.prototype._onSigninSuccess = function (data) {
6968
+ try {
6969
+ this.user_data = JSON.parse(data.user_data);
6970
+ }
6971
+ catch (e) {
6972
+ logger.error("Failed parsing user data after signin: " + data.user_data);
6973
+ return;
6974
+ }
6975
+ if (typeof this.user_data.id !== 'string' || this.user_data.id === '') {
6976
+ logger.error("user_data doesn't contain an id. user_data: " + this.user_data);
6977
+ return;
6978
+ }
6979
+ this._subscribeChannels();
6980
+ };
6981
+ UserFacade.prototype._subscribeChannels = function () {
6982
+ var _this = this;
6983
+ var ensure_subscribed = function (channel) {
6984
+ if (channel.subscriptionPending && channel.subscriptionCancelled) {
6985
+ channel.reinstateSubscription();
6986
+ }
6987
+ else if (!channel.subscriptionPending &&
6988
+ _this.pusher.connection.state === 'connected') {
6989
+ channel.subscribe();
6990
+ }
6991
+ };
6992
+ this.serverToUserChannel = new channels_channel("#server-to-user-" + this.user_data.id, this.pusher);
6993
+ this.serverToUserChannel.bind_global(function (eventName, data) {
6994
+ if (eventName.indexOf('pusher_internal:') === 0 ||
6995
+ eventName.indexOf('pusher:') === 0) {
6996
+ return;
6997
+ }
6998
+ _this.emit(eventName, data);
6999
+ });
7000
+ ensure_subscribed(this.serverToUserChannel);
7001
+ };
7002
+ UserFacade.prototype._disconnect = function () {
7003
+ this.user_data = null;
7004
+ if (this.serverToUserChannel) {
7005
+ this.serverToUserChannel.unbind_all();
7006
+ this.serverToUserChannel.disconnect();
7007
+ this.serverToUserChannel = null;
7008
+ }
7009
+ };
7010
+ return UserFacade;
7011
+ }(dispatcher));
7012
+ /* harmony default export */ var user = (user_UserFacade);
6766
7013
 
6767
7014
  // CONCATENATED MODULE: ./src/core/pusher.ts
6768
7015
 
@@ -6777,6 +7024,7 @@ function getEnableStatsConfig(opts) {
6777
7024
 
6778
7025
 
6779
7026
 
7027
+
6780
7028
  var pusher_Pusher = (function () {
6781
7029
  function Pusher(app_key, options) {
6782
7030
  var _this = this;
@@ -6790,7 +7038,7 @@ var pusher_Pusher = (function () {
6790
7038
  logger.warn('The disableStats option is deprecated in favor of enableStats');
6791
7039
  }
6792
7040
  this.key = app_key;
6793
- this.config = getConfig(options);
7041
+ this.config = getConfig(options, this);
6794
7042
  this.channels = factory.createChannels();
6795
7043
  this.global_emitter = new dispatcher();
6796
7044
  this.sessionID = Math.floor(Math.random() * 1000000000);
@@ -6849,6 +7097,7 @@ var pusher_Pusher = (function () {
6849
7097
  });
6850
7098
  Pusher.instances.push(this);
6851
7099
  this.timeline.info({ instances: Pusher.instances.length });
7100
+ this.user = new user(this);
6852
7101
  if (Pusher.isReady) {
6853
7102
  this.connect();
6854
7103
  }
@@ -6946,6 +7195,9 @@ var pusher_Pusher = (function () {
6946
7195
  Pusher.prototype.shouldUseTLS = function () {
6947
7196
  return this.config.useTLS;
6948
7197
  };
7198
+ Pusher.prototype.signin = function () {
7199
+ this.user.signin();
7200
+ };
6949
7201
  Pusher.instances = [];
6950
7202
  Pusher.isReady = false;
6951
7203
  Pusher.logToConsole = false;