|
3179 | 3179 | this.callbacks = new Map();
|
3180 | 3180 | this.setupSubscriptionWorker();
|
3181 | 3181 | }
|
| 3182 | + /** |
| 3183 | + * Terminate all ongoing long-poll requests. |
| 3184 | + */ |
| 3185 | + terminate() { |
| 3186 | + this.scheduleEventPost({ |
| 3187 | + type: 'client-unregister', |
| 3188 | + clientIdentifier: this.configuration.clientIdentifier, |
| 3189 | + subscriptionKey: this.configuration.subscriptionKey, |
| 3190 | + logVerbosity: this.configuration.logVerbosity, |
| 3191 | + }); |
| 3192 | + } |
3182 | 3193 | makeSendable(req) {
|
3183 | 3194 | // Use default request flow for non-subscribe / presence leave requests.
|
3184 | 3195 | if (!req.path.startsWith('/v2/subscribe') && !req.path.endsWith('/heartbeat') && !req.path.endsWith('/leave'))
|
|
3430 | 3441 | .join('|');
|
3431 | 3442 | if (typeof crypto !== 'undefined' && crypto.subtle) {
|
3432 | 3443 | const hash = yield crypto.subtle.digest('SHA-256', new TextEncoder().encode(accessToken));
|
3433 |
| - accessToken = String.fromCharCode(...new Uint8Array(hash)); |
| 3444 | + accessToken = String.fromCharCode(...Array.from(new Uint8Array(hash))); |
3434 | 3445 | }
|
3435 | 3446 | return [token, typeof btoa !== 'undefined' ? btoa(accessToken) : accessToken];
|
3436 | 3447 | });
|
|
3891 | 3902 | getUseRandomIVs() {
|
3892 | 3903 | return base.useRandomIVs;
|
3893 | 3904 | },
|
| 3905 | + getKeepPresenceChannelsInPresenceRequests() { |
| 3906 | + // @ts-expect-error: Access field from web-based SDK configuration. |
| 3907 | + return base.sdkFamily === 'Web' && base['subscriptionWorkerUrl']; |
| 3908 | + }, |
3894 | 3909 | setPresenceTimeout(value) {
|
3895 | 3910 | this.heartbeatInterval = value / 2 - 1;
|
3896 | 3911 | this.presenceTimeout = value;
|
|
3917 | 3932 | return base.PubNubFile;
|
3918 | 3933 | },
|
3919 | 3934 | get version() {
|
3920 |
| - return '9.1.0'; |
| 3935 | + return '9.2.0'; |
3921 | 3936 | },
|
3922 | 3937 | getVersion() {
|
3923 | 3938 | return this.version;
|
@@ -13593,10 +13608,13 @@
|
13593 | 13608 | {
|
13594 | 13609 | // Filtering out presence channels and groups.
|
13595 | 13610 | let { channels, channelGroups } = parameters;
|
13596 |
| - if (channelGroups) |
13597 |
| - channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); |
13598 |
| - if (channels) |
13599 |
| - channels = channels.filter((channel) => !channel.endsWith('-pnpres')); |
| 13611 | + // Remove `-pnpres` channels / groups if they not acceptable in current PubNub client configuration. |
| 13612 | + if (!this._configuration.getKeepPresenceChannelsInPresenceRequests()) { |
| 13613 | + if (channelGroups) |
| 13614 | + channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); |
| 13615 | + if (channels) |
| 13616 | + channels = channels.filter((channel) => !channel.endsWith('-pnpres')); |
| 13617 | + } |
13600 | 13618 | // Complete immediately request only for presence channels.
|
13601 | 13619 | if ((channelGroups !== null && channelGroups !== void 0 ? channelGroups : []).length === 0 && (channels !== null && channels !== void 0 ? channels : []).length === 0) {
|
13602 | 13620 | return callback({
|
@@ -13959,10 +13977,13 @@
|
13959 | 13977 | {
|
13960 | 13978 | // Filtering out presence channels and groups.
|
13961 | 13979 | let { channels, channelGroups } = parameters;
|
13962 |
| - if (channelGroups) |
13963 |
| - channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); |
13964 |
| - if (channels) |
13965 |
| - channels = channels.filter((channel) => !channel.endsWith('-pnpres')); |
| 13980 | + // Remove `-pnpres` channels / groups if they not acceptable in current PubNub client configuration. |
| 13981 | + if (!this._configuration.getKeepPresenceChannelsInPresenceRequests()) { |
| 13982 | + if (channelGroups) |
| 13983 | + channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); |
| 13984 | + if (channels) |
| 13985 | + channels = channels.filter((channel) => !channel.endsWith('-pnpres')); |
| 13986 | + } |
13966 | 13987 | // Complete immediately request only for presence channels.
|
13967 | 13988 | if ((channelGroups !== null && channelGroups !== void 0 ? channelGroups : []).length === 0 && (channels !== null && channels !== void 0 ? channels : []).length === 0) {
|
13968 | 13989 | const responseStatus = {
|
|
14789 | 14810 | {
|
14790 | 14811 | if (configurationCopy.subscriptionWorkerUrl) {
|
14791 | 14812 | // Inject subscription worker into transport provider stack.
|
14792 |
| - transport = new SubscriptionWorkerMiddleware({ |
| 14813 | + const middleware = new SubscriptionWorkerMiddleware({ |
14793 | 14814 | clientIdentifier: clientConfiguration._instanceId,
|
14794 | 14815 | subscriptionKey: clientConfiguration.subscribeKey,
|
14795 | 14816 | userId: clientConfiguration.getUserId(),
|
|
14803 | 14824 | tokenManager,
|
14804 | 14825 | transport,
|
14805 | 14826 | });
|
| 14827 | + transport = middleware; |
| 14828 | + window.onpagehide = (event) => { |
| 14829 | + if (!event.persisted) |
| 14830 | + middleware.terminate(); |
| 14831 | + }; |
14806 | 14832 | }
|
14807 | 14833 | }
|
14808 | 14834 | const transportMiddleware = new PubNubMiddleware({
|
|
0 commit comments