|
2916 | 2916 | message = 'Network issues'; |
2917 | 2917 | } |
2918 | 2918 | else if (errorName === 'TypeError') { |
2919 | | - category = StatusCategory$1.PNBadRequestCategory; |
| 2919 | + if (message.indexOf('Load failed') !== -1 || message.indexOf('Failed to fetch') != -1) |
| 2920 | + category = StatusCategory$1.PNNetworkIssuesCategory; |
| 2921 | + else |
| 2922 | + category = StatusCategory$1.PNBadRequestCategory; |
2920 | 2923 | } |
2921 | 2924 | else if (errorName === 'FetchError') { |
2922 | 2925 | const errorCode = error.code; |
|
3948 | 3951 | return base.PubNubFile; |
3949 | 3952 | }, |
3950 | 3953 | get version() { |
3951 | | - return '8.3.1'; |
| 3954 | + return '8.3.2'; |
3952 | 3955 | }, |
3953 | 3956 | getVersion() { |
3954 | 3957 | return this.version; |
|
9892 | 9895 | */ |
9893 | 9896 | subscribe(subscribeParameters) { |
9894 | 9897 | const timetoken = subscribeParameters === null || subscribeParameters === void 0 ? void 0 : subscribeParameters.timetoken; |
| 9898 | + this.pubnub.registerSubscribeCapable(this); |
9895 | 9899 | this.pubnub.subscribe(Object.assign({ channels: this.channelNames, channelGroups: this.groupNames }, (timetoken !== null && timetoken !== '' && { timetoken: timetoken }))); |
9896 | 9900 | } |
9897 | 9901 | /** |
9898 | 9902 | * Stop real-time events processing. |
9899 | 9903 | */ |
9900 | 9904 | unsubscribe() { |
| 9905 | + this.pubnub.unregisterSubscribeCapable(this); |
| 9906 | + const { channels, channelGroups } = this.pubnub.getSubscribeCapableEntities(); |
| 9907 | + // Identify channels and groups from which PubNub client can safely unsubscribe. |
| 9908 | + const filteredChannelGroups = this.groupNames.filter((cg) => !channelGroups.includes(cg)); |
| 9909 | + const filteredChannels = this.channelNames.filter((ch) => !channels.includes(ch)); |
| 9910 | + if (filteredChannels.length === 0 && filteredChannelGroups.length === 0) |
| 9911 | + return; |
9901 | 9912 | this.pubnub.unsubscribe({ |
9902 | | - channels: this.channelNames, |
9903 | | - channelGroups: this.groupNames, |
| 9913 | + channels: filteredChannels, |
| 9914 | + channelGroups: filteredChannelGroups, |
9904 | 9915 | }); |
9905 | 9916 | } |
9906 | 9917 | /** |
|
12566 | 12577 | // Prepare for real-time events announcement. |
12567 | 12578 | this.listenerManager = new ListenerManager(); |
12568 | 12579 | this.eventEmitter = new EventEmitter(this.listenerManager); |
| 12580 | + this.subscribeCapable = new Set(); |
12569 | 12581 | if (this._configuration.enableEventEngine) { |
12570 | 12582 | { |
12571 | 12583 | let heartbeatInterval = this._configuration.getHeartbeatInterval(); |
|
12998 | 13010 | * @param [isOffline] - Whether `offline` presence should be notified or not. |
12999 | 13011 | */ |
13000 | 13012 | destroy(isOffline) { |
| 13013 | + var _a; |
13001 | 13014 | { |
| 13015 | + (_a = this.subscribeCapable) === null || _a === void 0 ? void 0 : _a.clear(); |
13002 | 13016 | if (this.subscriptionManager) { |
13003 | 13017 | this.subscriptionManager.unsubscribeAll(isOffline); |
13004 | 13018 | this.subscriptionManager.disconnect(); |
|
13127 | 13141 | } |
13128 | 13142 | return []; |
13129 | 13143 | } |
| 13144 | + /** |
| 13145 | + * Register subscribe capable object with active subscription. |
| 13146 | + * |
| 13147 | + * @param subscribeCapable - {@link Subscription} or {@link SubscriptionSet} object. |
| 13148 | + * |
| 13149 | + * @internal |
| 13150 | + */ |
| 13151 | + registerSubscribeCapable(subscribeCapable) { |
| 13152 | + { |
| 13153 | + if (!this.subscribeCapable || this.subscribeCapable.has(subscribeCapable)) |
| 13154 | + return; |
| 13155 | + this.subscribeCapable.add(subscribeCapable); |
| 13156 | + } |
| 13157 | + } |
| 13158 | + /** |
| 13159 | + * Unregister subscribe capable object with inactive subscription. |
| 13160 | + * |
| 13161 | + * @param subscribeCapable - {@link Subscription} or {@link SubscriptionSet} object. |
| 13162 | + * |
| 13163 | + * @internal |
| 13164 | + */ |
| 13165 | + unregisterSubscribeCapable(subscribeCapable) { |
| 13166 | + { |
| 13167 | + if (!this.subscribeCapable || !this.subscribeCapable.has(subscribeCapable)) |
| 13168 | + return; |
| 13169 | + this.subscribeCapable.delete(subscribeCapable); |
| 13170 | + } |
| 13171 | + } |
| 13172 | + /** |
| 13173 | + * Retrieve list of subscribe capable entities currently used in subscription. |
| 13174 | + * |
| 13175 | + * @returns Channels and channel groups currently used in subscription. |
| 13176 | + * |
| 13177 | + * @internal |
| 13178 | + */ |
| 13179 | + getSubscribeCapableEntities() { |
| 13180 | + { |
| 13181 | + const entities = { channels: [], channelGroups: [] }; |
| 13182 | + if (!this.subscribeCapable) |
| 13183 | + return entities; |
| 13184 | + for (const subscribeCapable of this.subscribeCapable) { |
| 13185 | + entities.channelGroups.push(...subscribeCapable.channelGroups); |
| 13186 | + entities.channels.push(...subscribeCapable.channels); |
| 13187 | + } |
| 13188 | + return entities; |
| 13189 | + } |
| 13190 | + } |
13130 | 13191 | /** |
13131 | 13192 | * Subscribe to specified channels and groups real-time events. |
13132 | 13193 | * |
|
13205 | 13266 | * Unsubscribe from all channels and groups. |
13206 | 13267 | */ |
13207 | 13268 | unsubscribeAll() { |
| 13269 | + var _a; |
13208 | 13270 | { |
| 13271 | + (_a = this.subscribeCapable) === null || _a === void 0 ? void 0 : _a.clear(); |
13209 | 13272 | if (this.subscriptionManager) |
13210 | 13273 | this.subscriptionManager.unsubscribeAll(); |
13211 | 13274 | else if (this.eventEngine) |
|
0 commit comments