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
|
|
@@ -897,7 +897,7 @@ function safeJSONStringify(source) {
|
|
|
897
897
|
|
|
898
898
|
// CONCATENATED MODULE: ./src/core/defaults.ts
|
|
899
899
|
var Defaults = {
|
|
900
|
-
VERSION: "7.
|
|
900
|
+
VERSION: "7.4.0",
|
|
901
901
|
PROTOCOL: 7,
|
|
902
902
|
wsPort: 80,
|
|
903
903
|
wssPort: 443,
|
|
@@ -2092,6 +2092,41 @@ var presence_channel_extends = (undefined && undefined.__extends) || (function (
|
|
|
2092
2092
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
2093
2093
|
};
|
|
2094
2094
|
})();
|
|
2095
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2096
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
2097
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
2098
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
2099
|
+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
2100
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2101
|
+
});
|
|
2102
|
+
};
|
|
2103
|
+
var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
|
|
2104
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
2105
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
2106
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
2107
|
+
function step(op) {
|
|
2108
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
2109
|
+
while (_) try {
|
|
2110
|
+
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;
|
|
2111
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
2112
|
+
switch (op[0]) {
|
|
2113
|
+
case 0: case 1: t = op; break;
|
|
2114
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
2115
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
2116
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
2117
|
+
default:
|
|
2118
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
2119
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
2120
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
2121
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
2122
|
+
if (t[2]) _.ops.pop();
|
|
2123
|
+
_.trys.pop(); continue;
|
|
2124
|
+
}
|
|
2125
|
+
op = body.call(thisArg, _);
|
|
2126
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
2127
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
2128
|
+
}
|
|
2129
|
+
};
|
|
2095
2130
|
|
|
2096
2131
|
|
|
2097
2132
|
|
|
@@ -2105,21 +2140,38 @@ var presence_channel_PresenceChannel = (function (_super) {
|
|
|
2105
2140
|
}
|
|
2106
2141
|
PresenceChannel.prototype.authorize = function (socketId, callback) {
|
|
2107
2142
|
var _this = this;
|
|
2108
|
-
_super.prototype.authorize.call(this, socketId, function (error, authData) {
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2143
|
+
_super.prototype.authorize.call(this, socketId, function (error, authData) { return __awaiter(_this, void 0, void 0, function () {
|
|
2144
|
+
var channelData, suffix;
|
|
2145
|
+
return __generator(this, function (_a) {
|
|
2146
|
+
switch (_a.label) {
|
|
2147
|
+
case 0:
|
|
2148
|
+
if (!!error) return [3, 3];
|
|
2149
|
+
authData = authData;
|
|
2150
|
+
if (!(authData.channel_data != null)) return [3, 1];
|
|
2151
|
+
channelData = JSON.parse(authData.channel_data);
|
|
2152
|
+
this.members.setMyID(channelData.user_id);
|
|
2153
|
+
return [3, 3];
|
|
2154
|
+
case 1: return [4, this.pusher.user.signinDonePromise];
|
|
2155
|
+
case 2:
|
|
2156
|
+
_a.sent();
|
|
2157
|
+
if (this.pusher.user.user_data != null) {
|
|
2158
|
+
this.members.setMyID(this.pusher.user.user_data.id);
|
|
2159
|
+
}
|
|
2160
|
+
else {
|
|
2161
|
+
suffix = url_store.buildLogSuffix('authorizationEndpoint');
|
|
2162
|
+
logger.error("Invalid auth response for channel '" + this.name + "', " +
|
|
2163
|
+
("expected 'channel_data' field. " + suffix + ", ") +
|
|
2164
|
+
"or the user should be signed in.");
|
|
2165
|
+
callback('Invalid auth response');
|
|
2166
|
+
return [2];
|
|
2167
|
+
}
|
|
2168
|
+
_a.label = 3;
|
|
2169
|
+
case 3:
|
|
2170
|
+
callback(error, authData);
|
|
2171
|
+
return [2];
|
|
2117
2172
|
}
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
}
|
|
2121
|
-
callback(error, authData);
|
|
2122
|
-
});
|
|
2173
|
+
});
|
|
2174
|
+
}); });
|
|
2123
2175
|
};
|
|
2124
2176
|
PresenceChannel.prototype.handleEvent = function (event) {
|
|
2125
2177
|
var eventName = event.event;
|
|
@@ -4090,6 +4142,17 @@ function buildChannelAuthorizer(opts, pusher) {
|
|
|
4090
4142
|
return channel_authorizer(channelAuthorization);
|
|
4091
4143
|
}
|
|
4092
4144
|
|
|
4145
|
+
// CONCATENATED MODULE: ./src/core/utils/flat_promise.ts
|
|
4146
|
+
function flatPromise() {
|
|
4147
|
+
var resolve, reject;
|
|
4148
|
+
var promise = new Promise(function (res, rej) {
|
|
4149
|
+
resolve = res;
|
|
4150
|
+
reject = rej;
|
|
4151
|
+
});
|
|
4152
|
+
return { promise: promise, resolve: resolve, reject: reject };
|
|
4153
|
+
}
|
|
4154
|
+
/* harmony default export */ var flat_promise = (flatPromise);
|
|
4155
|
+
|
|
4093
4156
|
// CONCATENATED MODULE: ./src/core/user.ts
|
|
4094
4157
|
var user_extends = (undefined && undefined.__extends) || (function () {
|
|
4095
4158
|
var extendStatics = function (d, b) {
|
|
@@ -4107,6 +4170,7 @@ var user_extends = (undefined && undefined.__extends) || (function () {
|
|
|
4107
4170
|
|
|
4108
4171
|
|
|
4109
4172
|
|
|
4173
|
+
|
|
4110
4174
|
var user_UserFacade = (function (_super) {
|
|
4111
4175
|
user_extends(UserFacade, _super);
|
|
4112
4176
|
function UserFacade(pusher) {
|
|
@@ -4116,15 +4180,29 @@ var user_UserFacade = (function (_super) {
|
|
|
4116
4180
|
_this.signin_requested = false;
|
|
4117
4181
|
_this.user_data = null;
|
|
4118
4182
|
_this.serverToUserChannel = null;
|
|
4183
|
+
_this.signinDonePromise = null;
|
|
4184
|
+
_this._signinDoneResolve = null;
|
|
4185
|
+
_this._onAuthorize = function (err, authData) {
|
|
4186
|
+
if (err) {
|
|
4187
|
+
logger.warn("Error during signin: " + err);
|
|
4188
|
+
_this._cleanup();
|
|
4189
|
+
return;
|
|
4190
|
+
}
|
|
4191
|
+
_this.pusher.send_event('pusher:signin', {
|
|
4192
|
+
auth: authData.auth,
|
|
4193
|
+
user_data: authData.user_data
|
|
4194
|
+
});
|
|
4195
|
+
};
|
|
4119
4196
|
_this.pusher = pusher;
|
|
4120
|
-
_this.pusher.connection.bind('
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4197
|
+
_this.pusher.connection.bind('state_change', function (_a) {
|
|
4198
|
+
var previous = _a.previous, current = _a.current;
|
|
4199
|
+
if (previous !== 'connected' && current === 'connected') {
|
|
4200
|
+
_this._signin();
|
|
4201
|
+
}
|
|
4202
|
+
if (previous === 'connected' && current !== 'connected') {
|
|
4203
|
+
_this._cleanup();
|
|
4204
|
+
_this._newSigninPromiseIfNeeded();
|
|
4205
|
+
}
|
|
4128
4206
|
});
|
|
4129
4207
|
_this.pusher.connection.bind('message', function (event) {
|
|
4130
4208
|
var eventName = event.event;
|
|
@@ -4146,26 +4224,16 @@ var user_UserFacade = (function (_super) {
|
|
|
4146
4224
|
this._signin();
|
|
4147
4225
|
};
|
|
4148
4226
|
UserFacade.prototype._signin = function () {
|
|
4149
|
-
var _this = this;
|
|
4150
4227
|
if (!this.signin_requested) {
|
|
4151
4228
|
return;
|
|
4152
4229
|
}
|
|
4230
|
+
this._newSigninPromiseIfNeeded();
|
|
4153
4231
|
if (this.pusher.connection.state !== 'connected') {
|
|
4154
4232
|
return;
|
|
4155
4233
|
}
|
|
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
4234
|
this.pusher.config.userAuthenticator({
|
|
4167
4235
|
socketId: this.pusher.connection.socket_id
|
|
4168
|
-
},
|
|
4236
|
+
}, this._onAuthorize);
|
|
4169
4237
|
};
|
|
4170
4238
|
UserFacade.prototype._onSigninSuccess = function (data) {
|
|
4171
4239
|
try {
|
|
@@ -4173,12 +4241,15 @@ var user_UserFacade = (function (_super) {
|
|
|
4173
4241
|
}
|
|
4174
4242
|
catch (e) {
|
|
4175
4243
|
logger.error("Failed parsing user data after signin: " + data.user_data);
|
|
4244
|
+
this._cleanup();
|
|
4176
4245
|
return;
|
|
4177
4246
|
}
|
|
4178
4247
|
if (typeof this.user_data.id !== 'string' || this.user_data.id === '') {
|
|
4179
4248
|
logger.error("user_data doesn't contain an id. user_data: " + this.user_data);
|
|
4249
|
+
this._cleanup();
|
|
4180
4250
|
return;
|
|
4181
4251
|
}
|
|
4252
|
+
this._signinDoneResolve();
|
|
4182
4253
|
this._subscribeChannels();
|
|
4183
4254
|
};
|
|
4184
4255
|
UserFacade.prototype._subscribeChannels = function () {
|
|
@@ -4202,13 +4273,32 @@ var user_UserFacade = (function (_super) {
|
|
|
4202
4273
|
});
|
|
4203
4274
|
ensure_subscribed(this.serverToUserChannel);
|
|
4204
4275
|
};
|
|
4205
|
-
UserFacade.prototype.
|
|
4276
|
+
UserFacade.prototype._cleanup = function () {
|
|
4206
4277
|
this.user_data = null;
|
|
4207
4278
|
if (this.serverToUserChannel) {
|
|
4208
4279
|
this.serverToUserChannel.unbind_all();
|
|
4209
4280
|
this.serverToUserChannel.disconnect();
|
|
4210
4281
|
this.serverToUserChannel = null;
|
|
4211
4282
|
}
|
|
4283
|
+
if (this.signin_requested) {
|
|
4284
|
+
this._signinDoneResolve();
|
|
4285
|
+
}
|
|
4286
|
+
};
|
|
4287
|
+
UserFacade.prototype._newSigninPromiseIfNeeded = function () {
|
|
4288
|
+
if (!this.signin_requested) {
|
|
4289
|
+
return;
|
|
4290
|
+
}
|
|
4291
|
+
if (this.signinDonePromise && !this.signinDonePromise.done) {
|
|
4292
|
+
return;
|
|
4293
|
+
}
|
|
4294
|
+
var _a = flat_promise(), promise = _a.promise, resolve = _a.resolve, _ = _a.reject;
|
|
4295
|
+
promise.done = false;
|
|
4296
|
+
var setDone = function () {
|
|
4297
|
+
promise.done = true;
|
|
4298
|
+
};
|
|
4299
|
+
promise.then(setDone)["catch"](setDone);
|
|
4300
|
+
this.signinDonePromise = promise;
|
|
4301
|
+
this._signinDoneResolve = resolve;
|
|
4212
4302
|
};
|
|
4213
4303
|
return UserFacade;
|
|
4214
4304
|
}(dispatcher));
|