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.
- package/CHANGELOG.md +18 -0
- package/README.md +27 -87
- package/dist/node/pusher.js +325 -73
- package/dist/node/pusher.js.map +1 -1
- package/dist/react-native/pusher.js +2 -2
- package/dist/react-native/pusher.js.map +1 -1
- package/dist/web/pusher-with-encryption.js +330 -78
- package/dist/web/pusher-with-encryption.js.map +1 -1
- package/dist/web/pusher-with-encryption.min.js +2 -2
- package/dist/web/pusher-with-encryption.min.js.map +1 -1
- package/dist/web/pusher.js +330 -78
- package/dist/web/pusher.js.map +1 -1
- package/dist/web/pusher.min.js +2 -2
- package/dist/web/pusher.min.js.map +1 -1
- package/dist/worker/pusher-with-encryption.worker.js +314 -69
- package/dist/worker/pusher-with-encryption.worker.js.map +1 -1
- package/dist/worker/pusher-with-encryption.worker.min.js +2 -2
- package/dist/worker/pusher-with-encryption.worker.min.js.map +1 -1
- package/dist/worker/pusher.worker.js +314 -69
- package/dist/worker/pusher.worker.js.map +1 -1
- package/dist/worker/pusher.worker.min.js +2 -2
- package/dist/worker/pusher.worker.min.js.map +1 -1
- package/index.d.ts +8 -3
- package/package.json +2 -2
- package/spec/config/karma/config.worker.js +3 -0
- package/spec/config/karma/integration.js +4 -2
- package/spec/javascripts/helpers/mocks.js +41 -8
- package/spec/javascripts/helpers/worker/mock-dom-dependencies.js +1 -0
- package/spec/javascripts/integration/core/cluster_config_spec.js +8 -0
- package/spec/javascripts/integration/core/timeout_configuration_spec.js +1 -0
- package/spec/javascripts/integration/index.worker.js +12 -1
- package/spec/javascripts/unit/core/channels/channel_spec.js +25 -0
- package/spec/javascripts/unit/core/channels/encrypted_channel_spec.js +64 -66
- package/spec/javascripts/unit/core/channels/presence_channel_spec.js +51 -41
- package/spec/javascripts/unit/core/channels/private_channel_spec.js +8 -46
- package/spec/javascripts/unit/core/config_spec.js +307 -7
- package/spec/javascripts/unit/core/connection/connection_manager_spec.js +1 -0
- package/spec/javascripts/unit/core/http/http_socket_spec.js +1 -0
- package/spec/javascripts/unit/core/logger_spec.js +21 -20
- package/spec/javascripts/unit/core/pusher_spec.js +67 -39
- package/spec/javascripts/unit/core/pusher_with_encryption_spec.js +2 -0
- package/spec/javascripts/unit/core/strategies/cached_strategy_spec.js +1 -0
- package/spec/javascripts/unit/core/strategies/delayed_strategy_spec.js +1 -0
- package/spec/javascripts/unit/core/strategies/sequential_strategy_spec.js +1 -0
- package/spec/javascripts/unit/core/strategies/transport_strategy_spec.js +1 -0
- package/spec/javascripts/unit/core/transports/assistant_to_the_transport_manager_spec.js +1 -0
- package/spec/javascripts/unit/core/user_spec.js +295 -0
- package/spec/javascripts/unit/core/utils/periodic_timer_spec.js +4 -1
- package/spec/javascripts/unit/core/utils/timers_spec.js +6 -0
- package/spec/javascripts/unit/core/utils/url_store_spec.js +1 -1
- package/spec/javascripts/unit/core_with_runtime/auth/channel_authorizer_spec.js +55 -0
- package/spec/javascripts/unit/core_with_runtime/auth/deprecated_channel_authorizer_spec.js +48 -0
- package/spec/javascripts/unit/core_with_runtime/auth/user_authorizer_spec.js +52 -0
- package/spec/javascripts/unit/core_with_runtime/readme.md +5 -0
- package/spec/javascripts/unit/index.node.js +3 -0
- package/spec/javascripts/unit/index.web.js +3 -0
- package/spec/javascripts/unit/index.worker.js +3 -0
- package/spec/javascripts/unit/web/pusher_authorizer_spec.js +15 -16
- package/spec/javascripts/unit/web/transports/hosts_and_ports_spec.js +1 -0
- package/spec/javascripts/unit/worker/channel_authorizer_spec.js +110 -0
- package/src/core/auth/auth_transports.ts +8 -1
- package/src/core/auth/channel_authorizer.ts +53 -0
- package/src/core/auth/deprecated_channel_authorizer.ts +58 -0
- package/src/core/auth/options.ts +52 -17
- package/src/core/auth/user_authenticator.ts +51 -0
- package/src/core/channels/channel.ts +17 -3
- package/src/core/channels/channels.ts +4 -0
- package/src/core/channels/encrypted_channel.ts +26 -20
- package/src/core/channels/presence_channel.ts +5 -2
- package/src/core/channels/private_channel.ts +9 -4
- package/src/core/config.ts +76 -11
- package/src/core/defaults.ts +15 -0
- package/src/core/errors.ts +9 -0
- package/src/core/options.ts +18 -5
- package/src/core/pusher.ts +9 -1
- package/src/core/user.ts +143 -0
- package/src/core/utils/factory.ts +1 -10
- package/src/core/utils/url_store.ts +4 -1
- package/src/runtimes/isomorphic/auth/xhr_auth.ts +32 -19
- package/src/runtimes/web/auth/jsonp_auth.ts +13 -7
- package/src/runtimes/worker/auth/fetch_auth.ts +17 -12
- package/types/src/core/auth/auth_transports.d.ts +2 -1
- package/types/src/core/auth/channel_authorizer.d.ts +3 -0
- package/types/src/core/auth/deprecated_channel_authorizer.d.ts +18 -0
- package/types/src/core/auth/options.d.ts +34 -15
- package/types/src/core/auth/user_authenticator.d.ts +3 -0
- package/types/src/core/channels/channel.d.ts +4 -2
- package/types/src/core/channels/encrypted_channel.d.ts +2 -2
- package/types/src/core/channels/private_channel.d.ts +2 -2
- package/types/src/core/config.d.ts +4 -6
- package/types/src/core/defaults.d.ts +3 -0
- package/types/src/core/errors.d.ts +3 -0
- package/types/src/core/options.d.ts +6 -3
- package/types/src/core/pusher.d.ts +3 -0
- package/types/src/core/user.d.ts +15 -0
- package/types/src/core/utils/factory.d.ts +0 -2
- package/types/src/runtimes/isomorphic/auth/xhr_auth.d.ts +1 -1
- package/worker/with-encryption/index.js +1 -1
- package/spec/javascripts/unit/core/pusher_authorizer_spec.js +0 -160
- package/spec/javascripts/unit/worker/pusher_authorizer_spec.js +0 -111
- package/src/core/auth/pusher_authorizer.ts +0 -64
- package/types/index.d.ts +0 -15
- package/types/src/core/auth/pusher_authorizer.d.ts +0 -13
- package/types/src/core/index.d.ts +0 -6
- package/types/src/runtimes/react-native/tweetnacl-dummy.d.ts +0 -5
- package/types/src/runtimes/react-native/tweetnacl-util-dummy.d.ts +0 -7
package/dist/web/pusher.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Pusher JavaScript Library v7.0
|
|
2
|
+
* Pusher JavaScript Library v7.2.0
|
|
3
3
|
* https://pusher.com/
|
|
4
4
|
*
|
|
5
5
|
* Copyright 2020, Pusher
|
|
@@ -593,7 +593,7 @@ var ScriptReceivers = new ScriptReceiverFactory('_pusher_script_', 'Pusher.Scrip
|
|
|
593
593
|
|
|
594
594
|
// CONCATENATED MODULE: ./src/core/defaults.ts
|
|
595
595
|
var Defaults = {
|
|
596
|
-
VERSION: "7.0
|
|
596
|
+
VERSION: "7.2.0",
|
|
597
597
|
PROTOCOL: 7,
|
|
598
598
|
wsPort: 80,
|
|
599
599
|
wssPort: 443,
|
|
@@ -609,6 +609,14 @@ var Defaults = {
|
|
|
609
609
|
pongTimeout: 30000,
|
|
610
610
|
unavailableTimeout: 10000,
|
|
611
611
|
cluster: 'mt1',
|
|
612
|
+
userAuthentication: {
|
|
613
|
+
endpoint: '/pusher/user-auth',
|
|
614
|
+
transport: 'ajax'
|
|
615
|
+
},
|
|
616
|
+
channelAuthorization: {
|
|
617
|
+
endpoint: '/pusher/auth',
|
|
618
|
+
transport: 'ajax'
|
|
619
|
+
},
|
|
612
620
|
cdn_http: "http://js.pusher.com",
|
|
613
621
|
cdn_https: "https://js.pusher.com",
|
|
614
622
|
dependency_suffix: ""
|
|
@@ -686,7 +694,10 @@ var urlStore = {
|
|
|
686
694
|
baseUrl: 'https://pusher.com',
|
|
687
695
|
urls: {
|
|
688
696
|
authenticationEndpoint: {
|
|
689
|
-
path: '/docs/authenticating_users'
|
|
697
|
+
path: '/docs/channels/server_api/authenticating_users'
|
|
698
|
+
},
|
|
699
|
+
authorizationEndpoint: {
|
|
700
|
+
path: '/docs/channels/server_api/authorizing-users/'
|
|
690
701
|
},
|
|
691
702
|
javascriptQuickStart: {
|
|
692
703
|
path: '/docs/javascript_quick_start'
|
|
@@ -717,6 +728,13 @@ var buildLogSuffix = function (key) {
|
|
|
717
728
|
};
|
|
718
729
|
/* harmony default export */ var url_store = ({ buildLogSuffix: buildLogSuffix });
|
|
719
730
|
|
|
731
|
+
// CONCATENATED MODULE: ./src/core/auth/options.ts
|
|
732
|
+
var AuthRequestType;
|
|
733
|
+
(function (AuthRequestType) {
|
|
734
|
+
AuthRequestType["UserAuthentication"] = "user-authentication";
|
|
735
|
+
AuthRequestType["ChannelAuthorization"] = "channel-authorization";
|
|
736
|
+
})(AuthRequestType || (AuthRequestType = {}));
|
|
737
|
+
|
|
720
738
|
// CONCATENATED MODULE: ./src/core/errors.ts
|
|
721
739
|
var __extends = (undefined && undefined.__extends) || (function () {
|
|
722
740
|
var extendStatics = function (d, b) {
|
|
@@ -742,6 +760,17 @@ var BadEventName = (function (_super) {
|
|
|
742
760
|
return BadEventName;
|
|
743
761
|
}(Error));
|
|
744
762
|
|
|
763
|
+
var BadChannelName = (function (_super) {
|
|
764
|
+
__extends(BadChannelName, _super);
|
|
765
|
+
function BadChannelName(msg) {
|
|
766
|
+
var _newTarget = this.constructor;
|
|
767
|
+
var _this = _super.call(this, msg) || this;
|
|
768
|
+
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
769
|
+
return _this;
|
|
770
|
+
}
|
|
771
|
+
return BadChannelName;
|
|
772
|
+
}(Error));
|
|
773
|
+
|
|
745
774
|
var RequestTimedOut = (function (_super) {
|
|
746
775
|
__extends(RequestTimedOut, _super);
|
|
747
776
|
function RequestTimedOut(msg) {
|
|
@@ -825,13 +854,13 @@ var HTTPAuthError = (function (_super) {
|
|
|
825
854
|
|
|
826
855
|
|
|
827
856
|
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
xhr = runtime.createXHR();
|
|
831
|
-
xhr.open('POST',
|
|
857
|
+
|
|
858
|
+
var ajax = function (context, query, authOptions, authRequestType, callback) {
|
|
859
|
+
var xhr = runtime.createXHR();
|
|
860
|
+
xhr.open('POST', authOptions.endpoint, true);
|
|
832
861
|
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
833
|
-
for (var headerName in
|
|
834
|
-
xhr.setRequestHeader(headerName,
|
|
862
|
+
for (var headerName in authOptions.headers) {
|
|
863
|
+
xhr.setRequestHeader(headerName, authOptions.headers[headerName]);
|
|
835
864
|
}
|
|
836
865
|
xhr.onreadystatechange = function () {
|
|
837
866
|
if (xhr.readyState === 4) {
|
|
@@ -843,22 +872,28 @@ var ajax = function (context, socketId, callback) {
|
|
|
843
872
|
parsed = true;
|
|
844
873
|
}
|
|
845
874
|
catch (e) {
|
|
846
|
-
callback(new HTTPAuthError(200,
|
|
847
|
-
xhr.responseText), { auth: '' });
|
|
875
|
+
callback(new HTTPAuthError(200, "JSON returned from " + authRequestType.toString() + " endpoint was invalid, yet status code was 200. Data was: " + xhr.responseText), null);
|
|
848
876
|
}
|
|
849
877
|
if (parsed) {
|
|
850
878
|
callback(null, data);
|
|
851
879
|
}
|
|
852
880
|
}
|
|
853
881
|
else {
|
|
854
|
-
var suffix =
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
882
|
+
var suffix = '';
|
|
883
|
+
switch (authRequestType) {
|
|
884
|
+
case AuthRequestType.UserAuthentication:
|
|
885
|
+
suffix = url_store.buildLogSuffix('authenticationEndpoint');
|
|
886
|
+
break;
|
|
887
|
+
case AuthRequestType.ChannelAuthorization:
|
|
888
|
+
suffix = "Clients must be authenticated to join private or presence channels. " + url_store.buildLogSuffix('authorizationEndpoint');
|
|
889
|
+
break;
|
|
890
|
+
}
|
|
891
|
+
callback(new HTTPAuthError(xhr.status, "Unable to retrieve auth string from " + authRequestType.toString() + " endpoint - " +
|
|
892
|
+
("received status: " + xhr.status + " from " + authOptions.endpoint + ". " + suffix)), null);
|
|
858
893
|
}
|
|
859
894
|
}
|
|
860
895
|
};
|
|
861
|
-
xhr.send(
|
|
896
|
+
xhr.send(query);
|
|
862
897
|
return xhr;
|
|
863
898
|
};
|
|
864
899
|
/* harmony default export */ var xhr_auth = (ajax);
|
|
@@ -1265,9 +1300,9 @@ var logger_Logger = (function () {
|
|
|
1265
1300
|
|
|
1266
1301
|
// CONCATENATED MODULE: ./src/runtimes/web/auth/jsonp_auth.ts
|
|
1267
1302
|
|
|
1268
|
-
var jsonp = function (context,
|
|
1269
|
-
if (
|
|
1270
|
-
logger.warn(
|
|
1303
|
+
var jsonp = function (context, query, authOptions, authRequestType, callback) {
|
|
1304
|
+
if (authOptions.headers !== undefined) {
|
|
1305
|
+
logger.warn("To send headers with the " + authRequestType.toString() + " request, you must use AJAX, rather than JSONP.");
|
|
1271
1306
|
}
|
|
1272
1307
|
var callbackName = context.nextAuthCallbackID.toString();
|
|
1273
1308
|
context.nextAuthCallbackID++;
|
|
@@ -1278,11 +1313,11 @@ var jsonp = function (context, socketId, callback) {
|
|
|
1278
1313
|
};
|
|
1279
1314
|
var callback_name = "Pusher.auth_callbacks['" + callbackName + "']";
|
|
1280
1315
|
script.src =
|
|
1281
|
-
|
|
1316
|
+
authOptions.endpoint +
|
|
1282
1317
|
'?callback=' +
|
|
1283
1318
|
encodeURIComponent(callback_name) +
|
|
1284
1319
|
'&' +
|
|
1285
|
-
|
|
1320
|
+
query;
|
|
1286
1321
|
var head = document.getElementsByTagName('head')[0] || document.documentElement;
|
|
1287
1322
|
head.insertBefore(script, head.firstChild);
|
|
1288
1323
|
};
|
|
@@ -2201,42 +2236,6 @@ var handshake_Handshake = (function () {
|
|
|
2201
2236
|
}());
|
|
2202
2237
|
/* harmony default export */ var connection_handshake = (handshake_Handshake);
|
|
2203
2238
|
|
|
2204
|
-
// CONCATENATED MODULE: ./src/core/auth/pusher_authorizer.ts
|
|
2205
|
-
|
|
2206
|
-
var pusher_authorizer_PusherAuthorizer = (function () {
|
|
2207
|
-
function PusherAuthorizer(channel, options) {
|
|
2208
|
-
this.channel = channel;
|
|
2209
|
-
var authTransport = options.authTransport;
|
|
2210
|
-
if (typeof runtime.getAuthorizers()[authTransport] === 'undefined') {
|
|
2211
|
-
throw "'" + authTransport + "' is not a recognized auth transport";
|
|
2212
|
-
}
|
|
2213
|
-
this.type = authTransport;
|
|
2214
|
-
this.options = options;
|
|
2215
|
-
this.authOptions = options.auth || {};
|
|
2216
|
-
}
|
|
2217
|
-
PusherAuthorizer.prototype.composeQuery = function (socketId) {
|
|
2218
|
-
var query = 'socket_id=' +
|
|
2219
|
-
encodeURIComponent(socketId) +
|
|
2220
|
-
'&channel_name=' +
|
|
2221
|
-
encodeURIComponent(this.channel.name);
|
|
2222
|
-
for (var i in this.authOptions.params) {
|
|
2223
|
-
query +=
|
|
2224
|
-
'&' +
|
|
2225
|
-
encodeURIComponent(i) +
|
|
2226
|
-
'=' +
|
|
2227
|
-
encodeURIComponent(this.authOptions.params[i]);
|
|
2228
|
-
}
|
|
2229
|
-
return query;
|
|
2230
|
-
};
|
|
2231
|
-
PusherAuthorizer.prototype.authorize = function (socketId, callback) {
|
|
2232
|
-
PusherAuthorizer.authorizers =
|
|
2233
|
-
PusherAuthorizer.authorizers || runtime.getAuthorizers();
|
|
2234
|
-
PusherAuthorizer.authorizers[this.type].call(this, runtime, socketId, callback);
|
|
2235
|
-
};
|
|
2236
|
-
return PusherAuthorizer;
|
|
2237
|
-
}());
|
|
2238
|
-
/* harmony default export */ var pusher_authorizer = (pusher_authorizer_PusherAuthorizer);
|
|
2239
|
-
|
|
2240
2239
|
// CONCATENATED MODULE: ./src/core/timeline/timeline_sender.ts
|
|
2241
2240
|
|
|
2242
2241
|
var timeline_sender_TimelineSender = (function () {
|
|
@@ -2309,6 +2308,9 @@ var channel_Channel = (function (_super) {
|
|
|
2309
2308
|
if (eventName === 'pusher_internal:subscription_succeeded') {
|
|
2310
2309
|
this.handleSubscriptionSucceededEvent(event);
|
|
2311
2310
|
}
|
|
2311
|
+
else if (eventName === 'pusher_internal:subscription_count') {
|
|
2312
|
+
this.handleSubscriptionCountEvent(event);
|
|
2313
|
+
}
|
|
2312
2314
|
else if (eventName.indexOf('pusher_internal:') !== 0) {
|
|
2313
2315
|
var metadata = {};
|
|
2314
2316
|
this.emit(eventName, data, metadata);
|
|
@@ -2324,6 +2326,12 @@ var channel_Channel = (function (_super) {
|
|
|
2324
2326
|
this.emit('pusher:subscription_succeeded', event.data);
|
|
2325
2327
|
}
|
|
2326
2328
|
};
|
|
2329
|
+
Channel.prototype.handleSubscriptionCountEvent = function (event) {
|
|
2330
|
+
if (event.data.subscription_count) {
|
|
2331
|
+
this.subscriptionCount = event.data.subscription_count;
|
|
2332
|
+
}
|
|
2333
|
+
this.emit('pusher:subscription_count', event.data);
|
|
2334
|
+
};
|
|
2327
2335
|
Channel.prototype.subscribe = function () {
|
|
2328
2336
|
var _this = this;
|
|
2329
2337
|
if (this.subscribed) {
|
|
@@ -2380,19 +2388,20 @@ var private_channel_extends = (undefined && undefined.__extends) || (function ()
|
|
|
2380
2388
|
};
|
|
2381
2389
|
})();
|
|
2382
2390
|
|
|
2383
|
-
|
|
2384
|
-
var private_channel_PrivateChannel = (function (_super) {
|
|
2391
|
+
var PrivateChannel = (function (_super) {
|
|
2385
2392
|
private_channel_extends(PrivateChannel, _super);
|
|
2386
2393
|
function PrivateChannel() {
|
|
2387
2394
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
2388
2395
|
}
|
|
2389
2396
|
PrivateChannel.prototype.authorize = function (socketId, callback) {
|
|
2390
|
-
|
|
2391
|
-
|
|
2397
|
+
return this.pusher.config.channelAuthorizer({
|
|
2398
|
+
channelName: this.name,
|
|
2399
|
+
socketId: socketId
|
|
2400
|
+
}, callback);
|
|
2392
2401
|
};
|
|
2393
2402
|
return PrivateChannel;
|
|
2394
2403
|
}(channels_channel));
|
|
2395
|
-
/* harmony default export */ var private_channel = (
|
|
2404
|
+
/* harmony default export */ var private_channel = (PrivateChannel);
|
|
2396
2405
|
|
|
2397
2406
|
// CONCATENATED MODULE: ./src/core/channels/members.ts
|
|
2398
2407
|
|
|
@@ -2514,6 +2523,9 @@ var presence_channel_PresenceChannel = (function (_super) {
|
|
|
2514
2523
|
case 'pusher_internal:subscription_succeeded':
|
|
2515
2524
|
this.handleSubscriptionSucceededEvent(event);
|
|
2516
2525
|
break;
|
|
2526
|
+
case 'pusher_internal:subscription_count':
|
|
2527
|
+
this.handleSubscriptionCountEvent(event);
|
|
2528
|
+
break;
|
|
2517
2529
|
case 'pusher_internal:member_added':
|
|
2518
2530
|
var addedMember = this.members.addMember(data);
|
|
2519
2531
|
this.emit('pusher:member_added', addedMember);
|
|
@@ -2992,6 +3004,9 @@ function createChannel(name, pusher) {
|
|
|
2992
3004
|
else if (name.indexOf('presence-') === 0) {
|
|
2993
3005
|
return factory.createPresenceChannel(name, pusher);
|
|
2994
3006
|
}
|
|
3007
|
+
else if (name.indexOf('#') === 0) {
|
|
3008
|
+
throw new BadChannelName('Cannot create a channel with name "' + name + '".');
|
|
3009
|
+
}
|
|
2995
3010
|
else {
|
|
2996
3011
|
return factory.createChannel(name, pusher);
|
|
2997
3012
|
}
|
|
@@ -3007,7 +3022,6 @@ function createChannel(name, pusher) {
|
|
|
3007
3022
|
|
|
3008
3023
|
|
|
3009
3024
|
|
|
3010
|
-
|
|
3011
3025
|
var Factory = {
|
|
3012
3026
|
createChannels: function () {
|
|
3013
3027
|
return new channels();
|
|
@@ -3030,12 +3044,6 @@ var Factory = {
|
|
|
3030
3044
|
createTimelineSender: function (timeline, options) {
|
|
3031
3045
|
return new timeline_sender(timeline, options);
|
|
3032
3046
|
},
|
|
3033
|
-
createAuthorizer: function (channel, options) {
|
|
3034
|
-
if (options.authorizer) {
|
|
3035
|
-
return options.authorizer(channel, options);
|
|
3036
|
-
}
|
|
3037
|
-
return new pusher_authorizer(channel, options);
|
|
3038
|
-
},
|
|
3039
3047
|
createHandshake: function (transport, callback) {
|
|
3040
3048
|
return new connection_handshake(transport, callback);
|
|
3041
3049
|
},
|
|
@@ -4282,14 +4290,94 @@ var strategy_builder_UnsupportedStrategy = {
|
|
|
4282
4290
|
}
|
|
4283
4291
|
};
|
|
4284
4292
|
|
|
4293
|
+
// CONCATENATED MODULE: ./src/core/auth/user_authenticator.ts
|
|
4294
|
+
|
|
4295
|
+
|
|
4296
|
+
var composeChannelQuery = function (params, authOptions) {
|
|
4297
|
+
var query = 'socket_id=' + encodeURIComponent(params.socketId);
|
|
4298
|
+
for (var i in authOptions.params) {
|
|
4299
|
+
query +=
|
|
4300
|
+
'&' +
|
|
4301
|
+
encodeURIComponent(i) +
|
|
4302
|
+
'=' +
|
|
4303
|
+
encodeURIComponent(authOptions.params[i]);
|
|
4304
|
+
}
|
|
4305
|
+
return query;
|
|
4306
|
+
};
|
|
4307
|
+
var UserAuthenticator = function (authOptions) {
|
|
4308
|
+
if (typeof runtime.getAuthorizers()[authOptions.transport] === 'undefined') {
|
|
4309
|
+
throw "'" + authOptions.transport + "' is not a recognized auth transport";
|
|
4310
|
+
}
|
|
4311
|
+
return function (params, callback) {
|
|
4312
|
+
var query = composeChannelQuery(params, authOptions);
|
|
4313
|
+
runtime.getAuthorizers()[authOptions.transport](runtime, query, authOptions, AuthRequestType.UserAuthentication, callback);
|
|
4314
|
+
};
|
|
4315
|
+
};
|
|
4316
|
+
/* harmony default export */ var user_authenticator = (UserAuthenticator);
|
|
4317
|
+
|
|
4318
|
+
// CONCATENATED MODULE: ./src/core/auth/channel_authorizer.ts
|
|
4319
|
+
|
|
4320
|
+
|
|
4321
|
+
var channel_authorizer_composeChannelQuery = function (params, authOptions) {
|
|
4322
|
+
var query = 'socket_id=' + encodeURIComponent(params.socketId);
|
|
4323
|
+
query += '&channel_name=' + encodeURIComponent(params.channelName);
|
|
4324
|
+
for (var i in authOptions.params) {
|
|
4325
|
+
query +=
|
|
4326
|
+
'&' +
|
|
4327
|
+
encodeURIComponent(i) +
|
|
4328
|
+
'=' +
|
|
4329
|
+
encodeURIComponent(authOptions.params[i]);
|
|
4330
|
+
}
|
|
4331
|
+
return query;
|
|
4332
|
+
};
|
|
4333
|
+
var ChannelAuthorizer = function (authOptions) {
|
|
4334
|
+
if (typeof runtime.getAuthorizers()[authOptions.transport] === 'undefined') {
|
|
4335
|
+
throw "'" + authOptions.transport + "' is not a recognized auth transport";
|
|
4336
|
+
}
|
|
4337
|
+
return function (params, callback) {
|
|
4338
|
+
var query = channel_authorizer_composeChannelQuery(params, authOptions);
|
|
4339
|
+
runtime.getAuthorizers()[authOptions.transport](runtime, query, authOptions, AuthRequestType.ChannelAuthorization, callback);
|
|
4340
|
+
};
|
|
4341
|
+
};
|
|
4342
|
+
/* harmony default export */ var channel_authorizer = (ChannelAuthorizer);
|
|
4343
|
+
|
|
4344
|
+
// CONCATENATED MODULE: ./src/core/auth/deprecated_channel_authorizer.ts
|
|
4345
|
+
var ChannelAuthorizerProxy = function (pusher, authOptions, channelAuthorizerGenerator) {
|
|
4346
|
+
var deprecatedAuthorizerOptions = {
|
|
4347
|
+
authTransport: authOptions.transport,
|
|
4348
|
+
authEndpoint: authOptions.endpoint,
|
|
4349
|
+
auth: {
|
|
4350
|
+
params: authOptions.params,
|
|
4351
|
+
headers: authOptions.headers
|
|
4352
|
+
}
|
|
4353
|
+
};
|
|
4354
|
+
return function (params, callback) {
|
|
4355
|
+
var channel = pusher.channel(params.channelName);
|
|
4356
|
+
var channelAuthorizer = channelAuthorizerGenerator(channel, deprecatedAuthorizerOptions);
|
|
4357
|
+
channelAuthorizer.authorize(params.socketId, callback);
|
|
4358
|
+
};
|
|
4359
|
+
};
|
|
4360
|
+
|
|
4285
4361
|
// CONCATENATED MODULE: ./src/core/config.ts
|
|
4362
|
+
var __assign = (undefined && undefined.__assign) || function () {
|
|
4363
|
+
__assign = Object.assign || function(t) {
|
|
4364
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4365
|
+
s = arguments[i];
|
|
4366
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
4367
|
+
t[p] = s[p];
|
|
4368
|
+
}
|
|
4369
|
+
return t;
|
|
4370
|
+
};
|
|
4371
|
+
return __assign.apply(this, arguments);
|
|
4372
|
+
};
|
|
4373
|
+
|
|
4286
4374
|
|
|
4287
4375
|
|
|
4288
|
-
|
|
4376
|
+
|
|
4377
|
+
|
|
4378
|
+
function getConfig(opts, pusher) {
|
|
4289
4379
|
var config = {
|
|
4290
4380
|
activityTimeout: opts.activityTimeout || defaults.activityTimeout,
|
|
4291
|
-
authEndpoint: opts.authEndpoint || defaults.authEndpoint,
|
|
4292
|
-
authTransport: opts.authTransport || defaults.authTransport,
|
|
4293
4381
|
cluster: opts.cluster || defaults.cluster,
|
|
4294
4382
|
httpPath: opts.httpPath || defaults.httpPath,
|
|
4295
4383
|
httpPort: opts.httpPort || defaults.httpPort,
|
|
@@ -4303,12 +4391,10 @@ function getConfig(opts) {
|
|
|
4303
4391
|
enableStats: getEnableStatsConfig(opts),
|
|
4304
4392
|
httpHost: getHttpHost(opts),
|
|
4305
4393
|
useTLS: shouldUseTLS(opts),
|
|
4306
|
-
wsHost: getWebsocketHost(opts)
|
|
4394
|
+
wsHost: getWebsocketHost(opts),
|
|
4395
|
+
userAuthenticator: buildUserAuthenticator(opts),
|
|
4396
|
+
channelAuthorizer: buildChannelAuthorizer(opts, pusher)
|
|
4307
4397
|
};
|
|
4308
|
-
if ('auth' in opts)
|
|
4309
|
-
config.auth = opts.auth;
|
|
4310
|
-
if ('authorizer' in opts)
|
|
4311
|
-
config.authorizer = opts.authorizer;
|
|
4312
4398
|
if ('disabledTransports' in opts)
|
|
4313
4399
|
config.disabledTransports = opts.disabledTransports;
|
|
4314
4400
|
if ('enabledTransports' in opts)
|
|
@@ -4361,6 +4447,167 @@ function getEnableStatsConfig(opts) {
|
|
|
4361
4447
|
}
|
|
4362
4448
|
return false;
|
|
4363
4449
|
}
|
|
4450
|
+
function buildUserAuthenticator(opts) {
|
|
4451
|
+
var userAuthentication = __assign({}, defaults.userAuthentication, opts.userAuthentication);
|
|
4452
|
+
if ('customHandler' in userAuthentication &&
|
|
4453
|
+
userAuthentication['customHandler'] != null) {
|
|
4454
|
+
return userAuthentication['customHandler'];
|
|
4455
|
+
}
|
|
4456
|
+
return user_authenticator(userAuthentication);
|
|
4457
|
+
}
|
|
4458
|
+
function buildChannelAuth(opts, pusher) {
|
|
4459
|
+
var channelAuthorization;
|
|
4460
|
+
if ('channelAuthorization' in opts) {
|
|
4461
|
+
channelAuthorization = __assign({}, defaults.channelAuthorization, opts.channelAuthorization);
|
|
4462
|
+
}
|
|
4463
|
+
else {
|
|
4464
|
+
channelAuthorization = {
|
|
4465
|
+
transport: opts.authTransport || defaults.authTransport,
|
|
4466
|
+
endpoint: opts.authEndpoint || defaults.authEndpoint
|
|
4467
|
+
};
|
|
4468
|
+
if ('auth' in opts) {
|
|
4469
|
+
if ('params' in opts.auth)
|
|
4470
|
+
channelAuthorization.params = opts.auth.params;
|
|
4471
|
+
if ('headers' in opts.auth)
|
|
4472
|
+
channelAuthorization.headers = opts.auth.headers;
|
|
4473
|
+
}
|
|
4474
|
+
if ('authorizer' in opts)
|
|
4475
|
+
channelAuthorization.customHandler = ChannelAuthorizerProxy(pusher, channelAuthorization, opts.authorizer);
|
|
4476
|
+
}
|
|
4477
|
+
return channelAuthorization;
|
|
4478
|
+
}
|
|
4479
|
+
function buildChannelAuthorizer(opts, pusher) {
|
|
4480
|
+
var channelAuthorization = buildChannelAuth(opts, pusher);
|
|
4481
|
+
if ('customHandler' in channelAuthorization &&
|
|
4482
|
+
channelAuthorization['customHandler'] != null) {
|
|
4483
|
+
return channelAuthorization['customHandler'];
|
|
4484
|
+
}
|
|
4485
|
+
return channel_authorizer(channelAuthorization);
|
|
4486
|
+
}
|
|
4487
|
+
|
|
4488
|
+
// CONCATENATED MODULE: ./src/core/user.ts
|
|
4489
|
+
var user_extends = (undefined && undefined.__extends) || (function () {
|
|
4490
|
+
var extendStatics = function (d, b) {
|
|
4491
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4492
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
4493
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
4494
|
+
return extendStatics(d, b);
|
|
4495
|
+
};
|
|
4496
|
+
return function (d, b) {
|
|
4497
|
+
extendStatics(d, b);
|
|
4498
|
+
function __() { this.constructor = d; }
|
|
4499
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
4500
|
+
};
|
|
4501
|
+
})();
|
|
4502
|
+
|
|
4503
|
+
|
|
4504
|
+
|
|
4505
|
+
var user_UserFacade = (function (_super) {
|
|
4506
|
+
user_extends(UserFacade, _super);
|
|
4507
|
+
function UserFacade(pusher) {
|
|
4508
|
+
var _this = _super.call(this, function (eventName, data) {
|
|
4509
|
+
logger.debug('No callbacks on user for ' + eventName);
|
|
4510
|
+
}) || this;
|
|
4511
|
+
_this.signin_requested = false;
|
|
4512
|
+
_this.user_data = null;
|
|
4513
|
+
_this.serverToUserChannel = null;
|
|
4514
|
+
_this.pusher = pusher;
|
|
4515
|
+
_this.pusher.connection.bind('connected', function () {
|
|
4516
|
+
_this._signin();
|
|
4517
|
+
});
|
|
4518
|
+
_this.pusher.connection.bind('connecting', function () {
|
|
4519
|
+
_this._disconnect();
|
|
4520
|
+
});
|
|
4521
|
+
_this.pusher.connection.bind('disconnected', function () {
|
|
4522
|
+
_this._disconnect();
|
|
4523
|
+
});
|
|
4524
|
+
_this.pusher.connection.bind('message', function (event) {
|
|
4525
|
+
var eventName = event.event;
|
|
4526
|
+
if (eventName === 'pusher:signin_success') {
|
|
4527
|
+
_this._onSigninSuccess(event.data);
|
|
4528
|
+
}
|
|
4529
|
+
if (_this.serverToUserChannel &&
|
|
4530
|
+
_this.serverToUserChannel.name === event.channel) {
|
|
4531
|
+
_this.serverToUserChannel.handleEvent(event);
|
|
4532
|
+
}
|
|
4533
|
+
});
|
|
4534
|
+
return _this;
|
|
4535
|
+
}
|
|
4536
|
+
UserFacade.prototype.signin = function () {
|
|
4537
|
+
if (this.signin_requested) {
|
|
4538
|
+
return;
|
|
4539
|
+
}
|
|
4540
|
+
this.signin_requested = true;
|
|
4541
|
+
this._signin();
|
|
4542
|
+
};
|
|
4543
|
+
UserFacade.prototype._signin = function () {
|
|
4544
|
+
var _this = this;
|
|
4545
|
+
if (!this.signin_requested) {
|
|
4546
|
+
return;
|
|
4547
|
+
}
|
|
4548
|
+
if (this.pusher.connection.state !== 'connected') {
|
|
4549
|
+
return;
|
|
4550
|
+
}
|
|
4551
|
+
var onAuthorize = function (err, authData) {
|
|
4552
|
+
if (err) {
|
|
4553
|
+
logger.warn("Error during signin: " + err);
|
|
4554
|
+
return;
|
|
4555
|
+
}
|
|
4556
|
+
_this.pusher.send_event('pusher:signin', {
|
|
4557
|
+
auth: authData.auth,
|
|
4558
|
+
user_data: authData.user_data
|
|
4559
|
+
});
|
|
4560
|
+
};
|
|
4561
|
+
this.pusher.config.userAuthenticator({
|
|
4562
|
+
socketId: this.pusher.connection.socket_id
|
|
4563
|
+
}, onAuthorize);
|
|
4564
|
+
};
|
|
4565
|
+
UserFacade.prototype._onSigninSuccess = function (data) {
|
|
4566
|
+
try {
|
|
4567
|
+
this.user_data = JSON.parse(data.user_data);
|
|
4568
|
+
}
|
|
4569
|
+
catch (e) {
|
|
4570
|
+
logger.error("Failed parsing user data after signin: " + data.user_data);
|
|
4571
|
+
return;
|
|
4572
|
+
}
|
|
4573
|
+
if (typeof this.user_data.id !== 'string' || this.user_data.id === '') {
|
|
4574
|
+
logger.error("user_data doesn't contain an id. user_data: " + this.user_data);
|
|
4575
|
+
return;
|
|
4576
|
+
}
|
|
4577
|
+
this._subscribeChannels();
|
|
4578
|
+
};
|
|
4579
|
+
UserFacade.prototype._subscribeChannels = function () {
|
|
4580
|
+
var _this = this;
|
|
4581
|
+
var ensure_subscribed = function (channel) {
|
|
4582
|
+
if (channel.subscriptionPending && channel.subscriptionCancelled) {
|
|
4583
|
+
channel.reinstateSubscription();
|
|
4584
|
+
}
|
|
4585
|
+
else if (!channel.subscriptionPending &&
|
|
4586
|
+
_this.pusher.connection.state === 'connected') {
|
|
4587
|
+
channel.subscribe();
|
|
4588
|
+
}
|
|
4589
|
+
};
|
|
4590
|
+
this.serverToUserChannel = new channels_channel("#server-to-user-" + this.user_data.id, this.pusher);
|
|
4591
|
+
this.serverToUserChannel.bind_global(function (eventName, data) {
|
|
4592
|
+
if (eventName.indexOf('pusher_internal:') === 0 ||
|
|
4593
|
+
eventName.indexOf('pusher:') === 0) {
|
|
4594
|
+
return;
|
|
4595
|
+
}
|
|
4596
|
+
_this.emit(eventName, data);
|
|
4597
|
+
});
|
|
4598
|
+
ensure_subscribed(this.serverToUserChannel);
|
|
4599
|
+
};
|
|
4600
|
+
UserFacade.prototype._disconnect = function () {
|
|
4601
|
+
this.user_data = null;
|
|
4602
|
+
if (this.serverToUserChannel) {
|
|
4603
|
+
this.serverToUserChannel.unbind_all();
|
|
4604
|
+
this.serverToUserChannel.disconnect();
|
|
4605
|
+
this.serverToUserChannel = null;
|
|
4606
|
+
}
|
|
4607
|
+
};
|
|
4608
|
+
return UserFacade;
|
|
4609
|
+
}(dispatcher));
|
|
4610
|
+
/* harmony default export */ var user = (user_UserFacade);
|
|
4364
4611
|
|
|
4365
4612
|
// CONCATENATED MODULE: ./src/core/pusher.ts
|
|
4366
4613
|
|
|
@@ -4375,6 +4622,7 @@ function getEnableStatsConfig(opts) {
|
|
|
4375
4622
|
|
|
4376
4623
|
|
|
4377
4624
|
|
|
4625
|
+
|
|
4378
4626
|
var pusher_Pusher = (function () {
|
|
4379
4627
|
function Pusher(app_key, options) {
|
|
4380
4628
|
var _this = this;
|
|
@@ -4388,7 +4636,7 @@ var pusher_Pusher = (function () {
|
|
|
4388
4636
|
logger.warn('The disableStats option is deprecated in favor of enableStats');
|
|
4389
4637
|
}
|
|
4390
4638
|
this.key = app_key;
|
|
4391
|
-
this.config = getConfig(options);
|
|
4639
|
+
this.config = getConfig(options, this);
|
|
4392
4640
|
this.channels = factory.createChannels();
|
|
4393
4641
|
this.global_emitter = new dispatcher();
|
|
4394
4642
|
this.sessionID = Math.floor(Math.random() * 1000000000);
|
|
@@ -4447,6 +4695,7 @@ var pusher_Pusher = (function () {
|
|
|
4447
4695
|
});
|
|
4448
4696
|
Pusher.instances.push(this);
|
|
4449
4697
|
this.timeline.info({ instances: Pusher.instances.length });
|
|
4698
|
+
this.user = new user(this);
|
|
4450
4699
|
if (Pusher.isReady) {
|
|
4451
4700
|
this.connect();
|
|
4452
4701
|
}
|
|
@@ -4544,6 +4793,9 @@ var pusher_Pusher = (function () {
|
|
|
4544
4793
|
Pusher.prototype.shouldUseTLS = function () {
|
|
4545
4794
|
return this.config.useTLS;
|
|
4546
4795
|
};
|
|
4796
|
+
Pusher.prototype.signin = function () {
|
|
4797
|
+
this.user.signin();
|
|
4798
|
+
};
|
|
4547
4799
|
Pusher.instances = [];
|
|
4548
4800
|
Pusher.isReady = false;
|
|
4549
4801
|
Pusher.logToConsole = false;
|