|
4394 | 4394 | */ |
4395 | 4395 | const adjustedTimetokenBy = (timetoken, value, increment) => { |
4396 | 4396 | // Normalize value to the PubNub's high-precision time format. |
| 4397 | + if (value.startsWith('-')) { |
| 4398 | + value = value.replace('-', ''); |
| 4399 | + increment = false; |
| 4400 | + } |
4397 | 4401 | value = value.padStart(17, '0'); |
4398 | 4402 | const secA = timetoken.slice(0, 10); |
4399 | 4403 | const tickA = timetoken.slice(10, 17); |
|
4415 | 4419 | else if (seconds < 0) |
4416 | 4420 | ticks *= -1; |
4417 | 4421 | } |
| 4422 | + else if (seconds < 0 && ticks > 0) { |
| 4423 | + seconds += 1; |
| 4424 | + ticks = 10000000 - ticks; |
| 4425 | + } |
4418 | 4426 | return seconds !== 0 ? `${seconds}${`${ticks}`.padStart(7, '0')}` : `${ticks}`; |
4419 | 4427 | }; |
4420 | 4428 | /** |
|
5325 | 5333 | return base.PubNubFile; |
5326 | 5334 | }, |
5327 | 5335 | get version() { |
5328 | | - return '9.8.0'; |
| 5336 | + return '9.8.1'; |
5329 | 5337 | }, |
5330 | 5338 | getVersion() { |
5331 | 5339 | return this.version; |
@@ -10795,25 +10803,24 @@ |
10795 | 10803 | * @internal |
10796 | 10804 | */ |
10797 | 10805 | handleEvent(cursor, event) { |
10798 | | - var _a; |
10799 | | - if (!this.state.isSubscribed) |
| 10806 | + var _a, _b; |
| 10807 | + if (!this.state.isSubscribed || |
| 10808 | + !this.state.subscriptionInput.contains((_a = event.data.subscription) !== null && _a !== void 0 ? _a : event.data.channel)) |
10800 | 10809 | return; |
10801 | 10810 | if (this.parentSetsCount > 0) { |
10802 | 10811 | // Creating from whole payload (not only for published messages). |
10803 | 10812 | const fingerprint = messageFingerprint(event.data); |
10804 | 10813 | if (this.handledUpdates.includes(fingerprint)) { |
10805 | | - this.state.client.logger.trace(this.subscriptionType, `Message (${fingerprint}) already handled by ${this.id}. Ignoring.`); |
| 10814 | + this.state.client.logger.trace(this.subscriptionType, `Event (${fingerprint}) already handled by ${this.id}. Ignoring.`); |
10806 | 10815 | return; |
10807 | 10816 | } |
10808 | | - else |
10809 | | - console.log(`${this.id} handled (${fingerprint})`); |
10810 | 10817 | // Update a list of tracked messages and shrink it if too big. |
10811 | 10818 | this.handledUpdates.push(fingerprint); |
10812 | 10819 | if (this.handledUpdates.length > 10) |
10813 | 10820 | this.handledUpdates.shift(); |
10814 | 10821 | } |
10815 | 10822 | // Check whether an event is not designated for this subscription set. |
10816 | | - if (!this.state.subscriptionInput.contains((_a = event.data.subscription) !== null && _a !== void 0 ? _a : event.data.channel)) |
| 10823 | + if (!this.state.subscriptionInput.contains((_b = event.data.subscription) !== null && _b !== void 0 ? _b : event.data.channel)) |
10817 | 10824 | return; |
10818 | 10825 | super.handleEvent(cursor, event); |
10819 | 10826 | } |
|
16233 | 16240 | */ |
16234 | 16241 | disconnect(isOffline = false) { |
16235 | 16242 | { |
16236 | | - this.logger.debug('PubNub', `Disconnect (while offline? ${!!isOffline ? 'yes' : 'no'}`); |
| 16243 | + this.logger.debug('PubNub', `Disconnect (while offline? ${!!isOffline ? 'yes' : 'no'})`); |
16237 | 16244 | if (this.subscriptionManager) |
16238 | 16245 | this.subscriptionManager.disconnect(); |
16239 | 16246 | else if (this.eventEngine) |
|
17694 | 17701 | this._globalSubscriptionSet.handleEvent(cursor, event); |
17695 | 17702 | (_a = this.eventDispatcher) === null || _a === void 0 ? void 0 : _a.handleEvent(event); |
17696 | 17703 | Object.values(this.eventHandleCapable).forEach((eventHandleCapable) => { |
17697 | | - eventHandleCapable.handleEvent(cursor, event); |
| 17704 | + if (eventHandleCapable !== this._globalSubscriptionSet) |
| 17705 | + eventHandleCapable.handleEvent(cursor, event); |
17698 | 17706 | }); |
17699 | 17707 | } |
17700 | 17708 | } |
@@ -18103,10 +18111,12 @@ |
18103 | 18111 | authenticationChangeHandler = (auth) => middleware.onTokenChange(auth); |
18104 | 18112 | userIdChangeHandler = (userId) => middleware.onUserIdChange(userId); |
18105 | 18113 | transport = middleware; |
18106 | | - window.onpagehide = (event) => { |
18107 | | - if (!event.persisted) |
18108 | | - middleware.terminate(); |
18109 | | - }; |
| 18114 | + if (configurationCopy.subscriptionWorkerUnsubscribeOfflineClients) { |
| 18115 | + window.addEventListener('pagehide', (event) => { |
| 18116 | + if (!event.persisted) |
| 18117 | + middleware.terminate(); |
| 18118 | + }, { once: true }); |
| 18119 | + } |
18110 | 18120 | } |
18111 | 18121 | catch (e) { |
18112 | 18122 | clientConfiguration.logger().error('PubNub', () => ({ |
|
0 commit comments