pusher-js 7.3.0 → 7.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/release.yml +1 -1
- package/.github/workflows/release_pr.yml +1 -1
- package/.github/workflows/run-tests.yml +2 -2
- package/.gitmodules +1 -1
- package/CHANGELOG.md +4 -0
- package/README.md +10 -30
- package/dist/node/pusher.js +127 -37
- 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 +127 -37
- 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 +127 -37
- 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 +127 -37
- 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 +127 -37
- 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/package.json +5 -4
- package/spec/javascripts/helpers/timers/promises.js +9 -0
- package/spec/javascripts/unit/core/channels/presence_channel_spec.js +85 -16
- package/spec/javascripts/unit/core/user_spec.js +13 -6
- package/src/core/channels/presence_channel.ts +21 -12
- package/src/core/http/http_socket.ts +3 -1
- package/src/core/pusher.ts +1 -1
- package/src/core/user.ts +65 -27
- package/src/core/utils/flat_promise.ts +10 -0
- package/src/runtimes/interface.ts +1 -0
- package/src/runtimes/node/runtime.ts +5 -0
- package/src/runtimes/react-native/runtime.ts +5 -0
- package/src/runtimes/web/runtime.ts +14 -0
- package/src/runtimes/worker/runtime.ts +14 -0
- package/types/src/core/strategies/transport_strategy.d.ts +3 -0
- package/types/src/core/user.d.ts +5 -1
- package/types/src/core/utils/flat_promise.d.ts +6 -0
- package/types/src/runtimes/interface.d.ts +1 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Pusher JavaScript Library v7.
|
|
2
|
+
* Pusher JavaScript Library v7.4.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.
|
|
2998
|
+
VERSION: "7.4.0",
|
|
2999
2999
|
PROTOCOL: 7,
|
|
3000
3000
|
wsPort: 80,
|
|
3001
3001
|
wssPort: 443,
|
|
@@ -4875,6 +4875,41 @@ var presence_channel_extends = (undefined && undefined.__extends) || (function (
|
|
|
4875
4875
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
4876
4876
|
};
|
|
4877
4877
|
})();
|
|
4878
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4879
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4880
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
4881
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
4882
|
+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
4883
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
4884
|
+
});
|
|
4885
|
+
};
|
|
4886
|
+
var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
|
|
4887
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4888
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
4889
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
4890
|
+
function step(op) {
|
|
4891
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
4892
|
+
while (_) try {
|
|
4893
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
4894
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
4895
|
+
switch (op[0]) {
|
|
4896
|
+
case 0: case 1: t = op; break;
|
|
4897
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
4898
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
4899
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
4900
|
+
default:
|
|
4901
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
4902
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
4903
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
4904
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
4905
|
+
if (t[2]) _.ops.pop();
|
|
4906
|
+
_.trys.pop(); continue;
|
|
4907
|
+
}
|
|
4908
|
+
op = body.call(thisArg, _);
|
|
4909
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
4910
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
4911
|
+
}
|
|
4912
|
+
};
|
|
4878
4913
|
|
|
4879
4914
|
|
|
4880
4915
|
|
|
@@ -4888,21 +4923,38 @@ var presence_channel_PresenceChannel = (function (_super) {
|
|
|
4888
4923
|
}
|
|
4889
4924
|
PresenceChannel.prototype.authorize = function (socketId, callback) {
|
|
4890
4925
|
var _this = this;
|
|
4891
|
-
_super.prototype.authorize.call(this, socketId, function (error, authData) {
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4926
|
+
_super.prototype.authorize.call(this, socketId, function (error, authData) { return __awaiter(_this, void 0, void 0, function () {
|
|
4927
|
+
var channelData, suffix;
|
|
4928
|
+
return __generator(this, function (_a) {
|
|
4929
|
+
switch (_a.label) {
|
|
4930
|
+
case 0:
|
|
4931
|
+
if (!!error) return [3, 3];
|
|
4932
|
+
authData = authData;
|
|
4933
|
+
if (!(authData.channel_data != null)) return [3, 1];
|
|
4934
|
+
channelData = JSON.parse(authData.channel_data);
|
|
4935
|
+
this.members.setMyID(channelData.user_id);
|
|
4936
|
+
return [3, 3];
|
|
4937
|
+
case 1: return [4, this.pusher.user.signinDonePromise];
|
|
4938
|
+
case 2:
|
|
4939
|
+
_a.sent();
|
|
4940
|
+
if (this.pusher.user.user_data != null) {
|
|
4941
|
+
this.members.setMyID(this.pusher.user.user_data.id);
|
|
4942
|
+
}
|
|
4943
|
+
else {
|
|
4944
|
+
suffix = url_store.buildLogSuffix('authorizationEndpoint');
|
|
4945
|
+
logger.error("Invalid auth response for channel '" + this.name + "', " +
|
|
4946
|
+
("expected 'channel_data' field. " + suffix + ", ") +
|
|
4947
|
+
"or the user should be signed in.");
|
|
4948
|
+
callback('Invalid auth response');
|
|
4949
|
+
return [2];
|
|
4950
|
+
}
|
|
4951
|
+
_a.label = 3;
|
|
4952
|
+
case 3:
|
|
4953
|
+
callback(error, authData);
|
|
4954
|
+
return [2];
|
|
4900
4955
|
}
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
}
|
|
4904
|
-
callback(error, authData);
|
|
4905
|
-
});
|
|
4956
|
+
});
|
|
4957
|
+
}); });
|
|
4906
4958
|
};
|
|
4907
4959
|
PresenceChannel.prototype.handleEvent = function (event) {
|
|
4908
4960
|
var eventName = event.event;
|
|
@@ -6887,6 +6939,17 @@ function buildChannelAuthorizer(opts, pusher) {
|
|
|
6887
6939
|
return channel_authorizer(channelAuthorization);
|
|
6888
6940
|
}
|
|
6889
6941
|
|
|
6942
|
+
// CONCATENATED MODULE: ./src/core/utils/flat_promise.ts
|
|
6943
|
+
function flatPromise() {
|
|
6944
|
+
var resolve, reject;
|
|
6945
|
+
var promise = new Promise(function (res, rej) {
|
|
6946
|
+
resolve = res;
|
|
6947
|
+
reject = rej;
|
|
6948
|
+
});
|
|
6949
|
+
return { promise: promise, resolve: resolve, reject: reject };
|
|
6950
|
+
}
|
|
6951
|
+
/* harmony default export */ var flat_promise = (flatPromise);
|
|
6952
|
+
|
|
6890
6953
|
// CONCATENATED MODULE: ./src/core/user.ts
|
|
6891
6954
|
var user_extends = (undefined && undefined.__extends) || (function () {
|
|
6892
6955
|
var extendStatics = function (d, b) {
|
|
@@ -6904,6 +6967,7 @@ var user_extends = (undefined && undefined.__extends) || (function () {
|
|
|
6904
6967
|
|
|
6905
6968
|
|
|
6906
6969
|
|
|
6970
|
+
|
|
6907
6971
|
var user_UserFacade = (function (_super) {
|
|
6908
6972
|
user_extends(UserFacade, _super);
|
|
6909
6973
|
function UserFacade(pusher) {
|
|
@@ -6913,15 +6977,29 @@ var user_UserFacade = (function (_super) {
|
|
|
6913
6977
|
_this.signin_requested = false;
|
|
6914
6978
|
_this.user_data = null;
|
|
6915
6979
|
_this.serverToUserChannel = null;
|
|
6980
|
+
_this.signinDonePromise = null;
|
|
6981
|
+
_this._signinDoneResolve = null;
|
|
6982
|
+
_this._onAuthorize = function (err, authData) {
|
|
6983
|
+
if (err) {
|
|
6984
|
+
logger.warn("Error during signin: " + err);
|
|
6985
|
+
_this._cleanup();
|
|
6986
|
+
return;
|
|
6987
|
+
}
|
|
6988
|
+
_this.pusher.send_event('pusher:signin', {
|
|
6989
|
+
auth: authData.auth,
|
|
6990
|
+
user_data: authData.user_data
|
|
6991
|
+
});
|
|
6992
|
+
};
|
|
6916
6993
|
_this.pusher = pusher;
|
|
6917
|
-
_this.pusher.connection.bind('
|
|
6918
|
-
|
|
6919
|
-
|
|
6920
|
-
|
|
6921
|
-
|
|
6922
|
-
|
|
6923
|
-
|
|
6924
|
-
|
|
6994
|
+
_this.pusher.connection.bind('state_change', function (_a) {
|
|
6995
|
+
var previous = _a.previous, current = _a.current;
|
|
6996
|
+
if (previous !== 'connected' && current === 'connected') {
|
|
6997
|
+
_this._signin();
|
|
6998
|
+
}
|
|
6999
|
+
if (previous === 'connected' && current !== 'connected') {
|
|
7000
|
+
_this._cleanup();
|
|
7001
|
+
_this._newSigninPromiseIfNeeded();
|
|
7002
|
+
}
|
|
6925
7003
|
});
|
|
6926
7004
|
_this.pusher.connection.bind('message', function (event) {
|
|
6927
7005
|
var eventName = event.event;
|
|
@@ -6943,26 +7021,16 @@ var user_UserFacade = (function (_super) {
|
|
|
6943
7021
|
this._signin();
|
|
6944
7022
|
};
|
|
6945
7023
|
UserFacade.prototype._signin = function () {
|
|
6946
|
-
var _this = this;
|
|
6947
7024
|
if (!this.signin_requested) {
|
|
6948
7025
|
return;
|
|
6949
7026
|
}
|
|
7027
|
+
this._newSigninPromiseIfNeeded();
|
|
6950
7028
|
if (this.pusher.connection.state !== 'connected') {
|
|
6951
7029
|
return;
|
|
6952
7030
|
}
|
|
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
7031
|
this.pusher.config.userAuthenticator({
|
|
6964
7032
|
socketId: this.pusher.connection.socket_id
|
|
6965
|
-
},
|
|
7033
|
+
}, this._onAuthorize);
|
|
6966
7034
|
};
|
|
6967
7035
|
UserFacade.prototype._onSigninSuccess = function (data) {
|
|
6968
7036
|
try {
|
|
@@ -6970,12 +7038,15 @@ var user_UserFacade = (function (_super) {
|
|
|
6970
7038
|
}
|
|
6971
7039
|
catch (e) {
|
|
6972
7040
|
logger.error("Failed parsing user data after signin: " + data.user_data);
|
|
7041
|
+
this._cleanup();
|
|
6973
7042
|
return;
|
|
6974
7043
|
}
|
|
6975
7044
|
if (typeof this.user_data.id !== 'string' || this.user_data.id === '') {
|
|
6976
7045
|
logger.error("user_data doesn't contain an id. user_data: " + this.user_data);
|
|
7046
|
+
this._cleanup();
|
|
6977
7047
|
return;
|
|
6978
7048
|
}
|
|
7049
|
+
this._signinDoneResolve();
|
|
6979
7050
|
this._subscribeChannels();
|
|
6980
7051
|
};
|
|
6981
7052
|
UserFacade.prototype._subscribeChannels = function () {
|
|
@@ -6999,13 +7070,32 @@ var user_UserFacade = (function (_super) {
|
|
|
6999
7070
|
});
|
|
7000
7071
|
ensure_subscribed(this.serverToUserChannel);
|
|
7001
7072
|
};
|
|
7002
|
-
UserFacade.prototype.
|
|
7073
|
+
UserFacade.prototype._cleanup = function () {
|
|
7003
7074
|
this.user_data = null;
|
|
7004
7075
|
if (this.serverToUserChannel) {
|
|
7005
7076
|
this.serverToUserChannel.unbind_all();
|
|
7006
7077
|
this.serverToUserChannel.disconnect();
|
|
7007
7078
|
this.serverToUserChannel = null;
|
|
7008
7079
|
}
|
|
7080
|
+
if (this.signin_requested) {
|
|
7081
|
+
this._signinDoneResolve();
|
|
7082
|
+
}
|
|
7083
|
+
};
|
|
7084
|
+
UserFacade.prototype._newSigninPromiseIfNeeded = function () {
|
|
7085
|
+
if (!this.signin_requested) {
|
|
7086
|
+
return;
|
|
7087
|
+
}
|
|
7088
|
+
if (this.signinDonePromise && !this.signinDonePromise.done) {
|
|
7089
|
+
return;
|
|
7090
|
+
}
|
|
7091
|
+
var _a = flat_promise(), promise = _a.promise, resolve = _a.resolve, _ = _a.reject;
|
|
7092
|
+
promise.done = false;
|
|
7093
|
+
var setDone = function () {
|
|
7094
|
+
promise.done = true;
|
|
7095
|
+
};
|
|
7096
|
+
promise.then(setDone)["catch"](setDone);
|
|
7097
|
+
this.signinDonePromise = promise;
|
|
7098
|
+
this._signinDoneResolve = resolve;
|
|
7009
7099
|
};
|
|
7010
7100
|
return UserFacade;
|
|
7011
7101
|
}(dispatcher));
|