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
|
@@ -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
|
|
@@ -897,7 +897,7 @@ function safeJSONStringify(source) {
|
|
|
897
897
|
|
|
898
898
|
// CONCATENATED MODULE: ./src/core/defaults.ts
|
|
899
899
|
var Defaults = {
|
|
900
|
-
VERSION: "7.0
|
|
900
|
+
VERSION: "7.2.0",
|
|
901
901
|
PROTOCOL: 7,
|
|
902
902
|
wsPort: 80,
|
|
903
903
|
wssPort: 443,
|
|
@@ -913,6 +913,14 @@ var Defaults = {
|
|
|
913
913
|
pongTimeout: 30000,
|
|
914
914
|
unavailableTimeout: 10000,
|
|
915
915
|
cluster: 'mt1',
|
|
916
|
+
userAuthentication: {
|
|
917
|
+
endpoint: '/pusher/user-auth',
|
|
918
|
+
transport: 'ajax'
|
|
919
|
+
},
|
|
920
|
+
channelAuthorization: {
|
|
921
|
+
endpoint: '/pusher/auth',
|
|
922
|
+
transport: 'ajax'
|
|
923
|
+
},
|
|
916
924
|
cdn_http: "http://js.pusher.com",
|
|
917
925
|
cdn_https: "https://js.pusher.com",
|
|
918
926
|
dependency_suffix: ""
|
|
@@ -1693,42 +1701,6 @@ var handshake_Handshake = (function () {
|
|
|
1693
1701
|
}());
|
|
1694
1702
|
/* harmony default export */ var connection_handshake = (handshake_Handshake);
|
|
1695
1703
|
|
|
1696
|
-
// CONCATENATED MODULE: ./src/core/auth/pusher_authorizer.ts
|
|
1697
|
-
|
|
1698
|
-
var pusher_authorizer_PusherAuthorizer = (function () {
|
|
1699
|
-
function PusherAuthorizer(channel, options) {
|
|
1700
|
-
this.channel = channel;
|
|
1701
|
-
var authTransport = options.authTransport;
|
|
1702
|
-
if (typeof worker_runtime.getAuthorizers()[authTransport] === 'undefined') {
|
|
1703
|
-
throw "'" + authTransport + "' is not a recognized auth transport";
|
|
1704
|
-
}
|
|
1705
|
-
this.type = authTransport;
|
|
1706
|
-
this.options = options;
|
|
1707
|
-
this.authOptions = options.auth || {};
|
|
1708
|
-
}
|
|
1709
|
-
PusherAuthorizer.prototype.composeQuery = function (socketId) {
|
|
1710
|
-
var query = 'socket_id=' +
|
|
1711
|
-
encodeURIComponent(socketId) +
|
|
1712
|
-
'&channel_name=' +
|
|
1713
|
-
encodeURIComponent(this.channel.name);
|
|
1714
|
-
for (var i in this.authOptions.params) {
|
|
1715
|
-
query +=
|
|
1716
|
-
'&' +
|
|
1717
|
-
encodeURIComponent(i) +
|
|
1718
|
-
'=' +
|
|
1719
|
-
encodeURIComponent(this.authOptions.params[i]);
|
|
1720
|
-
}
|
|
1721
|
-
return query;
|
|
1722
|
-
};
|
|
1723
|
-
PusherAuthorizer.prototype.authorize = function (socketId, callback) {
|
|
1724
|
-
PusherAuthorizer.authorizers =
|
|
1725
|
-
PusherAuthorizer.authorizers || worker_runtime.getAuthorizers();
|
|
1726
|
-
PusherAuthorizer.authorizers[this.type].call(this, worker_runtime, socketId, callback);
|
|
1727
|
-
};
|
|
1728
|
-
return PusherAuthorizer;
|
|
1729
|
-
}());
|
|
1730
|
-
/* harmony default export */ var pusher_authorizer = (pusher_authorizer_PusherAuthorizer);
|
|
1731
|
-
|
|
1732
1704
|
// CONCATENATED MODULE: ./src/core/timeline/timeline_sender.ts
|
|
1733
1705
|
|
|
1734
1706
|
var timeline_sender_TimelineSender = (function () {
|
|
@@ -1771,6 +1743,17 @@ var BadEventName = (function (_super) {
|
|
|
1771
1743
|
return BadEventName;
|
|
1772
1744
|
}(Error));
|
|
1773
1745
|
|
|
1746
|
+
var BadChannelName = (function (_super) {
|
|
1747
|
+
errors_extends(BadChannelName, _super);
|
|
1748
|
+
function BadChannelName(msg) {
|
|
1749
|
+
var _newTarget = this.constructor;
|
|
1750
|
+
var _this = _super.call(this, msg) || this;
|
|
1751
|
+
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
1752
|
+
return _this;
|
|
1753
|
+
}
|
|
1754
|
+
return BadChannelName;
|
|
1755
|
+
}(Error));
|
|
1756
|
+
|
|
1774
1757
|
var RequestTimedOut = (function (_super) {
|
|
1775
1758
|
errors_extends(RequestTimedOut, _super);
|
|
1776
1759
|
function RequestTimedOut(msg) {
|
|
@@ -1855,7 +1838,10 @@ var urlStore = {
|
|
|
1855
1838
|
baseUrl: 'https://pusher.com',
|
|
1856
1839
|
urls: {
|
|
1857
1840
|
authenticationEndpoint: {
|
|
1858
|
-
path: '/docs/authenticating_users'
|
|
1841
|
+
path: '/docs/channels/server_api/authenticating_users'
|
|
1842
|
+
},
|
|
1843
|
+
authorizationEndpoint: {
|
|
1844
|
+
path: '/docs/channels/server_api/authorizing-users/'
|
|
1859
1845
|
},
|
|
1860
1846
|
javascriptQuickStart: {
|
|
1861
1847
|
path: '/docs/javascript_quick_start'
|
|
@@ -1941,6 +1927,9 @@ var channel_Channel = (function (_super) {
|
|
|
1941
1927
|
if (eventName === 'pusher_internal:subscription_succeeded') {
|
|
1942
1928
|
this.handleSubscriptionSucceededEvent(event);
|
|
1943
1929
|
}
|
|
1930
|
+
else if (eventName === 'pusher_internal:subscription_count') {
|
|
1931
|
+
this.handleSubscriptionCountEvent(event);
|
|
1932
|
+
}
|
|
1944
1933
|
else if (eventName.indexOf('pusher_internal:') !== 0) {
|
|
1945
1934
|
var metadata = {};
|
|
1946
1935
|
this.emit(eventName, data, metadata);
|
|
@@ -1956,6 +1945,12 @@ var channel_Channel = (function (_super) {
|
|
|
1956
1945
|
this.emit('pusher:subscription_succeeded', event.data);
|
|
1957
1946
|
}
|
|
1958
1947
|
};
|
|
1948
|
+
Channel.prototype.handleSubscriptionCountEvent = function (event) {
|
|
1949
|
+
if (event.data.subscription_count) {
|
|
1950
|
+
this.subscriptionCount = event.data.subscription_count;
|
|
1951
|
+
}
|
|
1952
|
+
this.emit('pusher:subscription_count', event.data);
|
|
1953
|
+
};
|
|
1959
1954
|
Channel.prototype.subscribe = function () {
|
|
1960
1955
|
var _this = this;
|
|
1961
1956
|
if (this.subscribed) {
|
|
@@ -2012,19 +2007,20 @@ var private_channel_extends = (undefined && undefined.__extends) || (function ()
|
|
|
2012
2007
|
};
|
|
2013
2008
|
})();
|
|
2014
2009
|
|
|
2015
|
-
|
|
2016
|
-
var private_channel_PrivateChannel = (function (_super) {
|
|
2010
|
+
var PrivateChannel = (function (_super) {
|
|
2017
2011
|
private_channel_extends(PrivateChannel, _super);
|
|
2018
2012
|
function PrivateChannel() {
|
|
2019
2013
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
2020
2014
|
}
|
|
2021
2015
|
PrivateChannel.prototype.authorize = function (socketId, callback) {
|
|
2022
|
-
|
|
2023
|
-
|
|
2016
|
+
return this.pusher.config.channelAuthorizer({
|
|
2017
|
+
channelName: this.name,
|
|
2018
|
+
socketId: socketId
|
|
2019
|
+
}, callback);
|
|
2024
2020
|
};
|
|
2025
2021
|
return PrivateChannel;
|
|
2026
2022
|
}(channels_channel));
|
|
2027
|
-
/* harmony default export */ var private_channel = (
|
|
2023
|
+
/* harmony default export */ var private_channel = (PrivateChannel);
|
|
2028
2024
|
|
|
2029
2025
|
// CONCATENATED MODULE: ./src/core/channels/members.ts
|
|
2030
2026
|
|
|
@@ -2146,6 +2142,9 @@ var presence_channel_PresenceChannel = (function (_super) {
|
|
|
2146
2142
|
case 'pusher_internal:subscription_succeeded':
|
|
2147
2143
|
this.handleSubscriptionSucceededEvent(event);
|
|
2148
2144
|
break;
|
|
2145
|
+
case 'pusher_internal:subscription_count':
|
|
2146
|
+
this.handleSubscriptionCountEvent(event);
|
|
2147
|
+
break;
|
|
2149
2148
|
case 'pusher_internal:member_added':
|
|
2150
2149
|
var addedMember = this.members.addMember(data);
|
|
2151
2150
|
this.emit('pusher:member_added', addedMember);
|
|
@@ -2624,6 +2623,9 @@ function createChannel(name, pusher) {
|
|
|
2624
2623
|
else if (name.indexOf('presence-') === 0) {
|
|
2625
2624
|
return factory.createPresenceChannel(name, pusher);
|
|
2626
2625
|
}
|
|
2626
|
+
else if (name.indexOf('#') === 0) {
|
|
2627
|
+
throw new BadChannelName('Cannot create a channel with name "' + name + '".');
|
|
2628
|
+
}
|
|
2627
2629
|
else {
|
|
2628
2630
|
return factory.createChannel(name, pusher);
|
|
2629
2631
|
}
|
|
@@ -2639,7 +2641,6 @@ function createChannel(name, pusher) {
|
|
|
2639
2641
|
|
|
2640
2642
|
|
|
2641
2643
|
|
|
2642
|
-
|
|
2643
2644
|
var Factory = {
|
|
2644
2645
|
createChannels: function () {
|
|
2645
2646
|
return new channels();
|
|
@@ -2662,12 +2663,6 @@ var Factory = {
|
|
|
2662
2663
|
createTimelineSender: function (timeline, options) {
|
|
2663
2664
|
return new timeline_sender(timeline, options);
|
|
2664
2665
|
},
|
|
2665
|
-
createAuthorizer: function (channel, options) {
|
|
2666
|
-
if (options.authorizer) {
|
|
2667
|
-
return options.authorizer(channel, options);
|
|
2668
|
-
}
|
|
2669
|
-
return new pusher_authorizer(channel, options);
|
|
2670
|
-
},
|
|
2671
2666
|
createHandshake: function (transport, callback) {
|
|
2672
2667
|
return new connection_handshake(transport, callback);
|
|
2673
2668
|
},
|
|
@@ -3572,14 +3567,14 @@ var net_info_Network = new NetInfo();
|
|
|
3572
3567
|
|
|
3573
3568
|
// CONCATENATED MODULE: ./src/runtimes/worker/auth/fetch_auth.ts
|
|
3574
3569
|
|
|
3575
|
-
var fetchAuth = function (context,
|
|
3570
|
+
var fetchAuth = function (context, query, authOptions, authRequestType, callback) {
|
|
3576
3571
|
var headers = new Headers();
|
|
3577
3572
|
headers.set('Content-Type', 'application/x-www-form-urlencoded');
|
|
3578
|
-
for (var headerName in
|
|
3579
|
-
headers.set(headerName,
|
|
3573
|
+
for (var headerName in authOptions.headers) {
|
|
3574
|
+
headers.set(headerName, authOptions.headers[headerName]);
|
|
3580
3575
|
}
|
|
3581
|
-
var body =
|
|
3582
|
-
var request = new Request(
|
|
3576
|
+
var body = query;
|
|
3577
|
+
var request = new Request(authOptions.endpoint, {
|
|
3583
3578
|
headers: headers,
|
|
3584
3579
|
body: body,
|
|
3585
3580
|
credentials: 'same-origin',
|
|
@@ -3591,7 +3586,7 @@ var fetchAuth = function (context, socketId, callback) {
|
|
|
3591
3586
|
if (status === 200) {
|
|
3592
3587
|
return response.text();
|
|
3593
3588
|
}
|
|
3594
|
-
throw new HTTPAuthError(200, "Could not get
|
|
3589
|
+
throw new HTTPAuthError(200, "Could not get " + authRequestType.toString() + " info from your auth endpoint, status: " + status);
|
|
3595
3590
|
})
|
|
3596
3591
|
.then(function (data) {
|
|
3597
3592
|
var parsedData;
|
|
@@ -3599,12 +3594,11 @@ var fetchAuth = function (context, socketId, callback) {
|
|
|
3599
3594
|
parsedData = JSON.parse(data);
|
|
3600
3595
|
}
|
|
3601
3596
|
catch (e) {
|
|
3602
|
-
throw new HTTPAuthError(200,
|
|
3603
|
-
data);
|
|
3597
|
+
throw new HTTPAuthError(200, "JSON returned from " + authRequestType.toString() + " endpoint was invalid, yet status code was 200. Data was: " + data);
|
|
3604
3598
|
}
|
|
3605
3599
|
callback(null, parsedData);
|
|
3606
3600
|
})["catch"](function (err) {
|
|
3607
|
-
callback(err,
|
|
3601
|
+
callback(err, null);
|
|
3608
3602
|
});
|
|
3609
3603
|
};
|
|
3610
3604
|
/* harmony default export */ var fetch_auth = (fetchAuth);
|
|
@@ -3894,14 +3888,101 @@ var strategy_builder_UnsupportedStrategy = {
|
|
|
3894
3888
|
}
|
|
3895
3889
|
};
|
|
3896
3890
|
|
|
3891
|
+
// CONCATENATED MODULE: ./src/core/auth/options.ts
|
|
3892
|
+
var AuthRequestType;
|
|
3893
|
+
(function (AuthRequestType) {
|
|
3894
|
+
AuthRequestType["UserAuthentication"] = "user-authentication";
|
|
3895
|
+
AuthRequestType["ChannelAuthorization"] = "channel-authorization";
|
|
3896
|
+
})(AuthRequestType || (AuthRequestType = {}));
|
|
3897
|
+
|
|
3898
|
+
// CONCATENATED MODULE: ./src/core/auth/user_authenticator.ts
|
|
3899
|
+
|
|
3900
|
+
|
|
3901
|
+
var composeChannelQuery = function (params, authOptions) {
|
|
3902
|
+
var query = 'socket_id=' + encodeURIComponent(params.socketId);
|
|
3903
|
+
for (var i in authOptions.params) {
|
|
3904
|
+
query +=
|
|
3905
|
+
'&' +
|
|
3906
|
+
encodeURIComponent(i) +
|
|
3907
|
+
'=' +
|
|
3908
|
+
encodeURIComponent(authOptions.params[i]);
|
|
3909
|
+
}
|
|
3910
|
+
return query;
|
|
3911
|
+
};
|
|
3912
|
+
var UserAuthenticator = function (authOptions) {
|
|
3913
|
+
if (typeof worker_runtime.getAuthorizers()[authOptions.transport] === 'undefined') {
|
|
3914
|
+
throw "'" + authOptions.transport + "' is not a recognized auth transport";
|
|
3915
|
+
}
|
|
3916
|
+
return function (params, callback) {
|
|
3917
|
+
var query = composeChannelQuery(params, authOptions);
|
|
3918
|
+
worker_runtime.getAuthorizers()[authOptions.transport](worker_runtime, query, authOptions, AuthRequestType.UserAuthentication, callback);
|
|
3919
|
+
};
|
|
3920
|
+
};
|
|
3921
|
+
/* harmony default export */ var user_authenticator = (UserAuthenticator);
|
|
3922
|
+
|
|
3923
|
+
// CONCATENATED MODULE: ./src/core/auth/channel_authorizer.ts
|
|
3924
|
+
|
|
3925
|
+
|
|
3926
|
+
var channel_authorizer_composeChannelQuery = function (params, authOptions) {
|
|
3927
|
+
var query = 'socket_id=' + encodeURIComponent(params.socketId);
|
|
3928
|
+
query += '&channel_name=' + encodeURIComponent(params.channelName);
|
|
3929
|
+
for (var i in authOptions.params) {
|
|
3930
|
+
query +=
|
|
3931
|
+
'&' +
|
|
3932
|
+
encodeURIComponent(i) +
|
|
3933
|
+
'=' +
|
|
3934
|
+
encodeURIComponent(authOptions.params[i]);
|
|
3935
|
+
}
|
|
3936
|
+
return query;
|
|
3937
|
+
};
|
|
3938
|
+
var ChannelAuthorizer = function (authOptions) {
|
|
3939
|
+
if (typeof worker_runtime.getAuthorizers()[authOptions.transport] === 'undefined') {
|
|
3940
|
+
throw "'" + authOptions.transport + "' is not a recognized auth transport";
|
|
3941
|
+
}
|
|
3942
|
+
return function (params, callback) {
|
|
3943
|
+
var query = channel_authorizer_composeChannelQuery(params, authOptions);
|
|
3944
|
+
worker_runtime.getAuthorizers()[authOptions.transport](worker_runtime, query, authOptions, AuthRequestType.ChannelAuthorization, callback);
|
|
3945
|
+
};
|
|
3946
|
+
};
|
|
3947
|
+
/* harmony default export */ var channel_authorizer = (ChannelAuthorizer);
|
|
3948
|
+
|
|
3949
|
+
// CONCATENATED MODULE: ./src/core/auth/deprecated_channel_authorizer.ts
|
|
3950
|
+
var ChannelAuthorizerProxy = function (pusher, authOptions, channelAuthorizerGenerator) {
|
|
3951
|
+
var deprecatedAuthorizerOptions = {
|
|
3952
|
+
authTransport: authOptions.transport,
|
|
3953
|
+
authEndpoint: authOptions.endpoint,
|
|
3954
|
+
auth: {
|
|
3955
|
+
params: authOptions.params,
|
|
3956
|
+
headers: authOptions.headers
|
|
3957
|
+
}
|
|
3958
|
+
};
|
|
3959
|
+
return function (params, callback) {
|
|
3960
|
+
var channel = pusher.channel(params.channelName);
|
|
3961
|
+
var channelAuthorizer = channelAuthorizerGenerator(channel, deprecatedAuthorizerOptions);
|
|
3962
|
+
channelAuthorizer.authorize(params.socketId, callback);
|
|
3963
|
+
};
|
|
3964
|
+
};
|
|
3965
|
+
|
|
3897
3966
|
// CONCATENATED MODULE: ./src/core/config.ts
|
|
3967
|
+
var __assign = (undefined && undefined.__assign) || function () {
|
|
3968
|
+
__assign = Object.assign || function(t) {
|
|
3969
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
3970
|
+
s = arguments[i];
|
|
3971
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
3972
|
+
t[p] = s[p];
|
|
3973
|
+
}
|
|
3974
|
+
return t;
|
|
3975
|
+
};
|
|
3976
|
+
return __assign.apply(this, arguments);
|
|
3977
|
+
};
|
|
3898
3978
|
|
|
3899
3979
|
|
|
3900
|
-
|
|
3980
|
+
|
|
3981
|
+
|
|
3982
|
+
|
|
3983
|
+
function getConfig(opts, pusher) {
|
|
3901
3984
|
var config = {
|
|
3902
3985
|
activityTimeout: opts.activityTimeout || defaults.activityTimeout,
|
|
3903
|
-
authEndpoint: opts.authEndpoint || defaults.authEndpoint,
|
|
3904
|
-
authTransport: opts.authTransport || defaults.authTransport,
|
|
3905
3986
|
cluster: opts.cluster || defaults.cluster,
|
|
3906
3987
|
httpPath: opts.httpPath || defaults.httpPath,
|
|
3907
3988
|
httpPort: opts.httpPort || defaults.httpPort,
|
|
@@ -3915,12 +3996,10 @@ function getConfig(opts) {
|
|
|
3915
3996
|
enableStats: getEnableStatsConfig(opts),
|
|
3916
3997
|
httpHost: getHttpHost(opts),
|
|
3917
3998
|
useTLS: shouldUseTLS(opts),
|
|
3918
|
-
wsHost: getWebsocketHost(opts)
|
|
3999
|
+
wsHost: getWebsocketHost(opts),
|
|
4000
|
+
userAuthenticator: buildUserAuthenticator(opts),
|
|
4001
|
+
channelAuthorizer: buildChannelAuthorizer(opts, pusher)
|
|
3919
4002
|
};
|
|
3920
|
-
if ('auth' in opts)
|
|
3921
|
-
config.auth = opts.auth;
|
|
3922
|
-
if ('authorizer' in opts)
|
|
3923
|
-
config.authorizer = opts.authorizer;
|
|
3924
4003
|
if ('disabledTransports' in opts)
|
|
3925
4004
|
config.disabledTransports = opts.disabledTransports;
|
|
3926
4005
|
if ('enabledTransports' in opts)
|
|
@@ -3973,6 +4052,167 @@ function getEnableStatsConfig(opts) {
|
|
|
3973
4052
|
}
|
|
3974
4053
|
return false;
|
|
3975
4054
|
}
|
|
4055
|
+
function buildUserAuthenticator(opts) {
|
|
4056
|
+
var userAuthentication = __assign({}, defaults.userAuthentication, opts.userAuthentication);
|
|
4057
|
+
if ('customHandler' in userAuthentication &&
|
|
4058
|
+
userAuthentication['customHandler'] != null) {
|
|
4059
|
+
return userAuthentication['customHandler'];
|
|
4060
|
+
}
|
|
4061
|
+
return user_authenticator(userAuthentication);
|
|
4062
|
+
}
|
|
4063
|
+
function buildChannelAuth(opts, pusher) {
|
|
4064
|
+
var channelAuthorization;
|
|
4065
|
+
if ('channelAuthorization' in opts) {
|
|
4066
|
+
channelAuthorization = __assign({}, defaults.channelAuthorization, opts.channelAuthorization);
|
|
4067
|
+
}
|
|
4068
|
+
else {
|
|
4069
|
+
channelAuthorization = {
|
|
4070
|
+
transport: opts.authTransport || defaults.authTransport,
|
|
4071
|
+
endpoint: opts.authEndpoint || defaults.authEndpoint
|
|
4072
|
+
};
|
|
4073
|
+
if ('auth' in opts) {
|
|
4074
|
+
if ('params' in opts.auth)
|
|
4075
|
+
channelAuthorization.params = opts.auth.params;
|
|
4076
|
+
if ('headers' in opts.auth)
|
|
4077
|
+
channelAuthorization.headers = opts.auth.headers;
|
|
4078
|
+
}
|
|
4079
|
+
if ('authorizer' in opts)
|
|
4080
|
+
channelAuthorization.customHandler = ChannelAuthorizerProxy(pusher, channelAuthorization, opts.authorizer);
|
|
4081
|
+
}
|
|
4082
|
+
return channelAuthorization;
|
|
4083
|
+
}
|
|
4084
|
+
function buildChannelAuthorizer(opts, pusher) {
|
|
4085
|
+
var channelAuthorization = buildChannelAuth(opts, pusher);
|
|
4086
|
+
if ('customHandler' in channelAuthorization &&
|
|
4087
|
+
channelAuthorization['customHandler'] != null) {
|
|
4088
|
+
return channelAuthorization['customHandler'];
|
|
4089
|
+
}
|
|
4090
|
+
return channel_authorizer(channelAuthorization);
|
|
4091
|
+
}
|
|
4092
|
+
|
|
4093
|
+
// CONCATENATED MODULE: ./src/core/user.ts
|
|
4094
|
+
var user_extends = (undefined && undefined.__extends) || (function () {
|
|
4095
|
+
var extendStatics = function (d, b) {
|
|
4096
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4097
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
4098
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
4099
|
+
return extendStatics(d, b);
|
|
4100
|
+
};
|
|
4101
|
+
return function (d, b) {
|
|
4102
|
+
extendStatics(d, b);
|
|
4103
|
+
function __() { this.constructor = d; }
|
|
4104
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
4105
|
+
};
|
|
4106
|
+
})();
|
|
4107
|
+
|
|
4108
|
+
|
|
4109
|
+
|
|
4110
|
+
var user_UserFacade = (function (_super) {
|
|
4111
|
+
user_extends(UserFacade, _super);
|
|
4112
|
+
function UserFacade(pusher) {
|
|
4113
|
+
var _this = _super.call(this, function (eventName, data) {
|
|
4114
|
+
logger.debug('No callbacks on user for ' + eventName);
|
|
4115
|
+
}) || this;
|
|
4116
|
+
_this.signin_requested = false;
|
|
4117
|
+
_this.user_data = null;
|
|
4118
|
+
_this.serverToUserChannel = null;
|
|
4119
|
+
_this.pusher = pusher;
|
|
4120
|
+
_this.pusher.connection.bind('connected', function () {
|
|
4121
|
+
_this._signin();
|
|
4122
|
+
});
|
|
4123
|
+
_this.pusher.connection.bind('connecting', function () {
|
|
4124
|
+
_this._disconnect();
|
|
4125
|
+
});
|
|
4126
|
+
_this.pusher.connection.bind('disconnected', function () {
|
|
4127
|
+
_this._disconnect();
|
|
4128
|
+
});
|
|
4129
|
+
_this.pusher.connection.bind('message', function (event) {
|
|
4130
|
+
var eventName = event.event;
|
|
4131
|
+
if (eventName === 'pusher:signin_success') {
|
|
4132
|
+
_this._onSigninSuccess(event.data);
|
|
4133
|
+
}
|
|
4134
|
+
if (_this.serverToUserChannel &&
|
|
4135
|
+
_this.serverToUserChannel.name === event.channel) {
|
|
4136
|
+
_this.serverToUserChannel.handleEvent(event);
|
|
4137
|
+
}
|
|
4138
|
+
});
|
|
4139
|
+
return _this;
|
|
4140
|
+
}
|
|
4141
|
+
UserFacade.prototype.signin = function () {
|
|
4142
|
+
if (this.signin_requested) {
|
|
4143
|
+
return;
|
|
4144
|
+
}
|
|
4145
|
+
this.signin_requested = true;
|
|
4146
|
+
this._signin();
|
|
4147
|
+
};
|
|
4148
|
+
UserFacade.prototype._signin = function () {
|
|
4149
|
+
var _this = this;
|
|
4150
|
+
if (!this.signin_requested) {
|
|
4151
|
+
return;
|
|
4152
|
+
}
|
|
4153
|
+
if (this.pusher.connection.state !== 'connected') {
|
|
4154
|
+
return;
|
|
4155
|
+
}
|
|
4156
|
+
var onAuthorize = function (err, authData) {
|
|
4157
|
+
if (err) {
|
|
4158
|
+
logger.warn("Error during signin: " + err);
|
|
4159
|
+
return;
|
|
4160
|
+
}
|
|
4161
|
+
_this.pusher.send_event('pusher:signin', {
|
|
4162
|
+
auth: authData.auth,
|
|
4163
|
+
user_data: authData.user_data
|
|
4164
|
+
});
|
|
4165
|
+
};
|
|
4166
|
+
this.pusher.config.userAuthenticator({
|
|
4167
|
+
socketId: this.pusher.connection.socket_id
|
|
4168
|
+
}, onAuthorize);
|
|
4169
|
+
};
|
|
4170
|
+
UserFacade.prototype._onSigninSuccess = function (data) {
|
|
4171
|
+
try {
|
|
4172
|
+
this.user_data = JSON.parse(data.user_data);
|
|
4173
|
+
}
|
|
4174
|
+
catch (e) {
|
|
4175
|
+
logger.error("Failed parsing user data after signin: " + data.user_data);
|
|
4176
|
+
return;
|
|
4177
|
+
}
|
|
4178
|
+
if (typeof this.user_data.id !== 'string' || this.user_data.id === '') {
|
|
4179
|
+
logger.error("user_data doesn't contain an id. user_data: " + this.user_data);
|
|
4180
|
+
return;
|
|
4181
|
+
}
|
|
4182
|
+
this._subscribeChannels();
|
|
4183
|
+
};
|
|
4184
|
+
UserFacade.prototype._subscribeChannels = function () {
|
|
4185
|
+
var _this = this;
|
|
4186
|
+
var ensure_subscribed = function (channel) {
|
|
4187
|
+
if (channel.subscriptionPending && channel.subscriptionCancelled) {
|
|
4188
|
+
channel.reinstateSubscription();
|
|
4189
|
+
}
|
|
4190
|
+
else if (!channel.subscriptionPending &&
|
|
4191
|
+
_this.pusher.connection.state === 'connected') {
|
|
4192
|
+
channel.subscribe();
|
|
4193
|
+
}
|
|
4194
|
+
};
|
|
4195
|
+
this.serverToUserChannel = new channels_channel("#server-to-user-" + this.user_data.id, this.pusher);
|
|
4196
|
+
this.serverToUserChannel.bind_global(function (eventName, data) {
|
|
4197
|
+
if (eventName.indexOf('pusher_internal:') === 0 ||
|
|
4198
|
+
eventName.indexOf('pusher:') === 0) {
|
|
4199
|
+
return;
|
|
4200
|
+
}
|
|
4201
|
+
_this.emit(eventName, data);
|
|
4202
|
+
});
|
|
4203
|
+
ensure_subscribed(this.serverToUserChannel);
|
|
4204
|
+
};
|
|
4205
|
+
UserFacade.prototype._disconnect = function () {
|
|
4206
|
+
this.user_data = null;
|
|
4207
|
+
if (this.serverToUserChannel) {
|
|
4208
|
+
this.serverToUserChannel.unbind_all();
|
|
4209
|
+
this.serverToUserChannel.disconnect();
|
|
4210
|
+
this.serverToUserChannel = null;
|
|
4211
|
+
}
|
|
4212
|
+
};
|
|
4213
|
+
return UserFacade;
|
|
4214
|
+
}(dispatcher));
|
|
4215
|
+
/* harmony default export */ var user = (user_UserFacade);
|
|
3976
4216
|
|
|
3977
4217
|
// CONCATENATED MODULE: ./src/core/pusher.ts
|
|
3978
4218
|
|
|
@@ -3987,6 +4227,7 @@ function getEnableStatsConfig(opts) {
|
|
|
3987
4227
|
|
|
3988
4228
|
|
|
3989
4229
|
|
|
4230
|
+
|
|
3990
4231
|
var pusher_Pusher = (function () {
|
|
3991
4232
|
function Pusher(app_key, options) {
|
|
3992
4233
|
var _this = this;
|
|
@@ -4000,7 +4241,7 @@ var pusher_Pusher = (function () {
|
|
|
4000
4241
|
logger.warn('The disableStats option is deprecated in favor of enableStats');
|
|
4001
4242
|
}
|
|
4002
4243
|
this.key = app_key;
|
|
4003
|
-
this.config = getConfig(options);
|
|
4244
|
+
this.config = getConfig(options, this);
|
|
4004
4245
|
this.channels = factory.createChannels();
|
|
4005
4246
|
this.global_emitter = new dispatcher();
|
|
4006
4247
|
this.sessionID = Math.floor(Math.random() * 1000000000);
|
|
@@ -4059,6 +4300,7 @@ var pusher_Pusher = (function () {
|
|
|
4059
4300
|
});
|
|
4060
4301
|
Pusher.instances.push(this);
|
|
4061
4302
|
this.timeline.info({ instances: Pusher.instances.length });
|
|
4303
|
+
this.user = new user(this);
|
|
4062
4304
|
if (Pusher.isReady) {
|
|
4063
4305
|
this.connect();
|
|
4064
4306
|
}
|
|
@@ -4156,6 +4398,9 @@ var pusher_Pusher = (function () {
|
|
|
4156
4398
|
Pusher.prototype.shouldUseTLS = function () {
|
|
4157
4399
|
return this.config.useTLS;
|
|
4158
4400
|
};
|
|
4401
|
+
Pusher.prototype.signin = function () {
|
|
4402
|
+
this.user.signin();
|
|
4403
|
+
};
|
|
4159
4404
|
Pusher.instances = [];
|
|
4160
4405
|
Pusher.isReady = false;
|
|
4161
4406
|
Pusher.logToConsole = false;
|