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
package/dist/web/pusher.js
CHANGED
|
@@ -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
|
|
@@ -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.
|
|
596
|
+
VERSION: "7.4.0",
|
|
597
597
|
PROTOCOL: 7,
|
|
598
598
|
wsPort: 80,
|
|
599
599
|
wssPort: 443,
|
|
@@ -2473,6 +2473,41 @@ var presence_channel_extends = (undefined && undefined.__extends) || (function (
|
|
|
2473
2473
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
2474
2474
|
};
|
|
2475
2475
|
})();
|
|
2476
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2477
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
2478
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
2479
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
2480
|
+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
2481
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2482
|
+
});
|
|
2483
|
+
};
|
|
2484
|
+
var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
|
|
2485
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
2486
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
2487
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
2488
|
+
function step(op) {
|
|
2489
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
2490
|
+
while (_) try {
|
|
2491
|
+
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;
|
|
2492
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
2493
|
+
switch (op[0]) {
|
|
2494
|
+
case 0: case 1: t = op; break;
|
|
2495
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
2496
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
2497
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
2498
|
+
default:
|
|
2499
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
2500
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
2501
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
2502
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
2503
|
+
if (t[2]) _.ops.pop();
|
|
2504
|
+
_.trys.pop(); continue;
|
|
2505
|
+
}
|
|
2506
|
+
op = body.call(thisArg, _);
|
|
2507
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
2508
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
2509
|
+
}
|
|
2510
|
+
};
|
|
2476
2511
|
|
|
2477
2512
|
|
|
2478
2513
|
|
|
@@ -2486,21 +2521,38 @@ var presence_channel_PresenceChannel = (function (_super) {
|
|
|
2486
2521
|
}
|
|
2487
2522
|
PresenceChannel.prototype.authorize = function (socketId, callback) {
|
|
2488
2523
|
var _this = this;
|
|
2489
|
-
_super.prototype.authorize.call(this, socketId, function (error, authData) {
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2524
|
+
_super.prototype.authorize.call(this, socketId, function (error, authData) { return __awaiter(_this, void 0, void 0, function () {
|
|
2525
|
+
var channelData, suffix;
|
|
2526
|
+
return __generator(this, function (_a) {
|
|
2527
|
+
switch (_a.label) {
|
|
2528
|
+
case 0:
|
|
2529
|
+
if (!!error) return [3, 3];
|
|
2530
|
+
authData = authData;
|
|
2531
|
+
if (!(authData.channel_data != null)) return [3, 1];
|
|
2532
|
+
channelData = JSON.parse(authData.channel_data);
|
|
2533
|
+
this.members.setMyID(channelData.user_id);
|
|
2534
|
+
return [3, 3];
|
|
2535
|
+
case 1: return [4, this.pusher.user.signinDonePromise];
|
|
2536
|
+
case 2:
|
|
2537
|
+
_a.sent();
|
|
2538
|
+
if (this.pusher.user.user_data != null) {
|
|
2539
|
+
this.members.setMyID(this.pusher.user.user_data.id);
|
|
2540
|
+
}
|
|
2541
|
+
else {
|
|
2542
|
+
suffix = url_store.buildLogSuffix('authorizationEndpoint');
|
|
2543
|
+
logger.error("Invalid auth response for channel '" + this.name + "', " +
|
|
2544
|
+
("expected 'channel_data' field. " + suffix + ", ") +
|
|
2545
|
+
"or the user should be signed in.");
|
|
2546
|
+
callback('Invalid auth response');
|
|
2547
|
+
return [2];
|
|
2548
|
+
}
|
|
2549
|
+
_a.label = 3;
|
|
2550
|
+
case 3:
|
|
2551
|
+
callback(error, authData);
|
|
2552
|
+
return [2];
|
|
2498
2553
|
}
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
}
|
|
2502
|
-
callback(error, authData);
|
|
2503
|
-
});
|
|
2554
|
+
});
|
|
2555
|
+
}); });
|
|
2504
2556
|
};
|
|
2505
2557
|
PresenceChannel.prototype.handleEvent = function (event) {
|
|
2506
2558
|
var eventName = event.event;
|
|
@@ -4485,6 +4537,17 @@ function buildChannelAuthorizer(opts, pusher) {
|
|
|
4485
4537
|
return channel_authorizer(channelAuthorization);
|
|
4486
4538
|
}
|
|
4487
4539
|
|
|
4540
|
+
// CONCATENATED MODULE: ./src/core/utils/flat_promise.ts
|
|
4541
|
+
function flatPromise() {
|
|
4542
|
+
var resolve, reject;
|
|
4543
|
+
var promise = new Promise(function (res, rej) {
|
|
4544
|
+
resolve = res;
|
|
4545
|
+
reject = rej;
|
|
4546
|
+
});
|
|
4547
|
+
return { promise: promise, resolve: resolve, reject: reject };
|
|
4548
|
+
}
|
|
4549
|
+
/* harmony default export */ var flat_promise = (flatPromise);
|
|
4550
|
+
|
|
4488
4551
|
// CONCATENATED MODULE: ./src/core/user.ts
|
|
4489
4552
|
var user_extends = (undefined && undefined.__extends) || (function () {
|
|
4490
4553
|
var extendStatics = function (d, b) {
|
|
@@ -4502,6 +4565,7 @@ var user_extends = (undefined && undefined.__extends) || (function () {
|
|
|
4502
4565
|
|
|
4503
4566
|
|
|
4504
4567
|
|
|
4568
|
+
|
|
4505
4569
|
var user_UserFacade = (function (_super) {
|
|
4506
4570
|
user_extends(UserFacade, _super);
|
|
4507
4571
|
function UserFacade(pusher) {
|
|
@@ -4511,15 +4575,29 @@ var user_UserFacade = (function (_super) {
|
|
|
4511
4575
|
_this.signin_requested = false;
|
|
4512
4576
|
_this.user_data = null;
|
|
4513
4577
|
_this.serverToUserChannel = null;
|
|
4578
|
+
_this.signinDonePromise = null;
|
|
4579
|
+
_this._signinDoneResolve = null;
|
|
4580
|
+
_this._onAuthorize = function (err, authData) {
|
|
4581
|
+
if (err) {
|
|
4582
|
+
logger.warn("Error during signin: " + err);
|
|
4583
|
+
_this._cleanup();
|
|
4584
|
+
return;
|
|
4585
|
+
}
|
|
4586
|
+
_this.pusher.send_event('pusher:signin', {
|
|
4587
|
+
auth: authData.auth,
|
|
4588
|
+
user_data: authData.user_data
|
|
4589
|
+
});
|
|
4590
|
+
};
|
|
4514
4591
|
_this.pusher = pusher;
|
|
4515
|
-
_this.pusher.connection.bind('
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4592
|
+
_this.pusher.connection.bind('state_change', function (_a) {
|
|
4593
|
+
var previous = _a.previous, current = _a.current;
|
|
4594
|
+
if (previous !== 'connected' && current === 'connected') {
|
|
4595
|
+
_this._signin();
|
|
4596
|
+
}
|
|
4597
|
+
if (previous === 'connected' && current !== 'connected') {
|
|
4598
|
+
_this._cleanup();
|
|
4599
|
+
_this._newSigninPromiseIfNeeded();
|
|
4600
|
+
}
|
|
4523
4601
|
});
|
|
4524
4602
|
_this.pusher.connection.bind('message', function (event) {
|
|
4525
4603
|
var eventName = event.event;
|
|
@@ -4541,26 +4619,16 @@ var user_UserFacade = (function (_super) {
|
|
|
4541
4619
|
this._signin();
|
|
4542
4620
|
};
|
|
4543
4621
|
UserFacade.prototype._signin = function () {
|
|
4544
|
-
var _this = this;
|
|
4545
4622
|
if (!this.signin_requested) {
|
|
4546
4623
|
return;
|
|
4547
4624
|
}
|
|
4625
|
+
this._newSigninPromiseIfNeeded();
|
|
4548
4626
|
if (this.pusher.connection.state !== 'connected') {
|
|
4549
4627
|
return;
|
|
4550
4628
|
}
|
|
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
4629
|
this.pusher.config.userAuthenticator({
|
|
4562
4630
|
socketId: this.pusher.connection.socket_id
|
|
4563
|
-
},
|
|
4631
|
+
}, this._onAuthorize);
|
|
4564
4632
|
};
|
|
4565
4633
|
UserFacade.prototype._onSigninSuccess = function (data) {
|
|
4566
4634
|
try {
|
|
@@ -4568,12 +4636,15 @@ var user_UserFacade = (function (_super) {
|
|
|
4568
4636
|
}
|
|
4569
4637
|
catch (e) {
|
|
4570
4638
|
logger.error("Failed parsing user data after signin: " + data.user_data);
|
|
4639
|
+
this._cleanup();
|
|
4571
4640
|
return;
|
|
4572
4641
|
}
|
|
4573
4642
|
if (typeof this.user_data.id !== 'string' || this.user_data.id === '') {
|
|
4574
4643
|
logger.error("user_data doesn't contain an id. user_data: " + this.user_data);
|
|
4644
|
+
this._cleanup();
|
|
4575
4645
|
return;
|
|
4576
4646
|
}
|
|
4647
|
+
this._signinDoneResolve();
|
|
4577
4648
|
this._subscribeChannels();
|
|
4578
4649
|
};
|
|
4579
4650
|
UserFacade.prototype._subscribeChannels = function () {
|
|
@@ -4597,13 +4668,32 @@ var user_UserFacade = (function (_super) {
|
|
|
4597
4668
|
});
|
|
4598
4669
|
ensure_subscribed(this.serverToUserChannel);
|
|
4599
4670
|
};
|
|
4600
|
-
UserFacade.prototype.
|
|
4671
|
+
UserFacade.prototype._cleanup = function () {
|
|
4601
4672
|
this.user_data = null;
|
|
4602
4673
|
if (this.serverToUserChannel) {
|
|
4603
4674
|
this.serverToUserChannel.unbind_all();
|
|
4604
4675
|
this.serverToUserChannel.disconnect();
|
|
4605
4676
|
this.serverToUserChannel = null;
|
|
4606
4677
|
}
|
|
4678
|
+
if (this.signin_requested) {
|
|
4679
|
+
this._signinDoneResolve();
|
|
4680
|
+
}
|
|
4681
|
+
};
|
|
4682
|
+
UserFacade.prototype._newSigninPromiseIfNeeded = function () {
|
|
4683
|
+
if (!this.signin_requested) {
|
|
4684
|
+
return;
|
|
4685
|
+
}
|
|
4686
|
+
if (this.signinDonePromise && !this.signinDonePromise.done) {
|
|
4687
|
+
return;
|
|
4688
|
+
}
|
|
4689
|
+
var _a = flat_promise(), promise = _a.promise, resolve = _a.resolve, _ = _a.reject;
|
|
4690
|
+
promise.done = false;
|
|
4691
|
+
var setDone = function () {
|
|
4692
|
+
promise.done = true;
|
|
4693
|
+
};
|
|
4694
|
+
promise.then(setDone)["catch"](setDone);
|
|
4695
|
+
this.signinDonePromise = promise;
|
|
4696
|
+
this._signinDoneResolve = resolve;
|
|
4607
4697
|
};
|
|
4608
4698
|
return UserFacade;
|
|
4609
4699
|
}(dispatcher));
|