|
5436 | 5436 | return base.PubNubFile; |
5437 | 5437 | }, |
5438 | 5438 | get version() { |
5439 | | - return '10.2.1'; |
| 5439 | + return '10.2.5'; |
5440 | 5440 | }, |
5441 | 5441 | getVersion() { |
5442 | 5442 | return this.version; |
|
5913 | 5913 | } |
5914 | 5914 | if (this.transport !== 'fetch') |
5915 | 5915 | return; |
5916 | | - // Keeping reference on current `window.fetch` function. |
5917 | | - WebTransport.originalFetch = fetch.bind(window); |
| 5916 | + // Storing reference on original `fetch` function implementation as protection against APM lib monkey patching. |
| 5917 | + WebTransport.originalFetch = WebTransport.getOriginalFetch(); |
5918 | 5918 | // Check whether `fetch` has been monkey patched or not. |
5919 | | - if (this.isFetchMonkeyPatched()) { |
5920 | | - WebTransport.originalFetch = WebTransport.getOriginalFetch(); |
| 5919 | + if (this.isFetchMonkeyPatched()) |
5921 | 5920 | logger.warn('WebTransport', "Native Web Fetch API 'fetch' function monkey patched."); |
5922 | | - if (!this.isFetchMonkeyPatched(WebTransport.originalFetch)) { |
5923 | | - logger.info('WebTransport', "Use native Web Fetch API 'fetch' implementation from iframe as APM workaround."); |
5924 | | - } |
5925 | | - else { |
5926 | | - logger.warn('WebTransport', 'Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation'); |
5927 | | - } |
5928 | | - } |
5929 | 5921 | } |
5930 | 5922 | makeSendable(req) { |
5931 | 5923 | const abortController = new AbortController(); |
|
8160 | 8152 | if (platforms.includes('fcm')) { |
8161 | 8153 | const fcmPayload = this.fcm.toObject(); |
8162 | 8154 | if (fcmPayload && Object.keys(fcmPayload).length) |
8163 | | - payload.pn_gcm = fcmPayload; |
| 8155 | + payload.pn_fcm = fcmPayload; |
8164 | 8156 | } |
8165 | 8157 | if (Object.keys(payload).length && this._debugging) |
8166 | 8158 | payload.pn_debug = true; |
|
9574 | 9566 | return subscriptionTimetokenFromReference(currentTimetoken, referenceTimetoken !== null && referenceTimetoken !== void 0 ? referenceTimetoken : '0'); |
9575 | 9567 | } |
9576 | 9568 | subscribe({ channels, channelGroups, timetoken, withPresence, }) { |
| 9569 | + var _a; |
| 9570 | + // check if the channels and groups are already subscribed |
| 9571 | + const hasNewChannels = channels === null || channels === void 0 ? void 0 : channels.some((channel) => !this.channels.includes(channel)); |
| 9572 | + const hasNewGroups = channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.some((group) => !this.groups.includes(group)); |
| 9573 | + const hasNewSubscriptions = hasNewChannels || hasNewGroups; |
9577 | 9574 | this.channels = [...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])]; |
9578 | 9575 | this.groups = [...this.groups, ...(channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])]; |
9579 | 9576 | if (withPresence) { |
|
9584 | 9581 | this.engine.transition(restore(Array.from(new Set([...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])])), Array.from(new Set([...this.groups, ...(channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])])), timetoken)); |
9585 | 9582 | } |
9586 | 9583 | else { |
9587 | | - this.engine.transition(subscriptionChange(Array.from(new Set([...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])])), Array.from(new Set([...this.groups, ...(channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])])))); |
| 9584 | + if (hasNewSubscriptions) { |
| 9585 | + this.engine.transition(subscriptionChange(Array.from(new Set([...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])])), Array.from(new Set([...this.groups, ...(channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])])))); |
| 9586 | + } |
| 9587 | + else { |
| 9588 | + this.dependencies.config |
| 9589 | + .logger() |
| 9590 | + .debug('EventEngine', 'Skipping state transition - all channels/groups already subscribed. Emitting SubscriptionChanged event.'); |
| 9591 | + // Get current timetoken from state context |
| 9592 | + const currentState = this.engine.currentState; |
| 9593 | + const currentContext = this.engine.currentContext; |
| 9594 | + let currentTimetoken = '0'; |
| 9595 | + if ((currentState === null || currentState === void 0 ? void 0 : currentState.label) === ReceivingState.label && currentContext) { |
| 9596 | + const receivingContext = currentContext; |
| 9597 | + currentTimetoken = (_a = receivingContext.cursor) === null || _a === void 0 ? void 0 : _a.timetoken; |
| 9598 | + } |
| 9599 | + // Manually emit SubscriptionChanged status event |
| 9600 | + this.dependencies.emitStatus({ |
| 9601 | + category: StatusCategory$1.PNSubscriptionChangedCategory, |
| 9602 | + affectedChannels: Array.from(new Set(this.channels)), |
| 9603 | + affectedChannelGroups: Array.from(new Set(this.groups)), |
| 9604 | + currentTimetoken, |
| 9605 | + }); |
| 9606 | + } |
9588 | 9607 | } |
9589 | 9608 | if (this.dependencies.join) { |
9590 | 9609 | this.dependencies.join({ |
|
0 commit comments