Skip to content

Commit ebf99d5

Browse files
author
Max Presman
committed
improve unsubscribe
1 parent 814df85 commit ebf99d5

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/core/components/subscription_manager.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,35 @@ export default class {
157157

158158
adaptUnsubscribeChange(args: UnsubscribeArgs, isOffline: boolean) {
159159
const { channels = [], channelGroups = [] } = args;
160+
let performUnsubscribe = false;
160161

161162
channels.forEach((channel) => {
162-
if (channel in this._channels) delete this._channels[channel];
163-
if (channel in this._presenceChannels) delete this._presenceChannels[channel];
163+
if (channel in this._channels) {
164+
delete this._channels[channel];
165+
performUnsubscribe = true;
166+
}
167+
if (channel in this._presenceChannels) {
168+
delete this._presenceChannels[channel];
169+
performUnsubscribe = true;
170+
}
164171
});
165172

166173
channelGroups.forEach((channelGroup) => {
167-
if (channelGroup in this._channelGroups) delete this._channelGroups[channelGroup];
168-
if (channelGroup in this._presenceChannelGroups) delete this._channelGroups[channelGroup];
174+
if (channelGroup in this._channelGroups) {
175+
delete this._channelGroups[channelGroup];
176+
performUnsubscribe = true;
177+
}
178+
if (channelGroup in this._presenceChannelGroups) {
179+
delete this._channelGroups[channelGroup];
180+
performUnsubscribe = true;
181+
}
169182
});
170183

184+
// no-op if there are no channels and cg's to unsubscribe from.
185+
if (!performUnsubscribe) {
186+
return;
187+
}
188+
171189
if (this._config.suppressLeaveEvents === false && !isOffline) {
172190
this._leaveEndpoint({ channels, channelGroups }, (status) => {
173191
status.affectedChannels = channels;

src/core/pubnub-common.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -134,27 +134,27 @@ export default class {
134134
this.removeListener = listenerManager.removeListener.bind(listenerManager);
135135
this.removeAllListeners = listenerManager.removeAllListeners.bind(listenerManager);
136136

137-
/** channel groups **/
137+
/* channel groups */
138138
this.channelGroups = {
139139
listGroups: endpointCreator.bind(this, modules, listChannelGroupsConfig),
140140
listChannels: endpointCreator.bind(this, modules, listChannelsInChannelGroupConfig),
141141
addChannels: endpointCreator.bind(this, modules, addChannelsChannelGroupConfig),
142142
removeChannels: endpointCreator.bind(this, modules, removeChannelsChannelGroupConfig),
143143
deleteGroup: endpointCreator.bind(this, modules, deleteChannelGroupConfig)
144144
};
145-
/** push **/
145+
/* push */
146146
this.push = {
147147
addChannels: endpointCreator.bind(this, modules, addPushChannelsConfig),
148148
removeChannels: endpointCreator.bind(this, modules, removePushChannelsConfig),
149149
deleteDevice: endpointCreator.bind(this, modules, removeDevicePushConfig),
150150
listChannels: endpointCreator.bind(this, modules, listPushChannelsConfig)
151151
};
152-
/** presence **/
152+
/* presence */
153153
this.hereNow = endpointCreator.bind(this, modules, presenceHereNowConfig);
154154
this.whereNow = endpointCreator.bind(this, modules, presenceWhereNowEndpointConfig);
155155
this.getState = endpointCreator.bind(this, modules, presenceGetStateConfig);
156156
this.setState = subscriptionManager.adaptStateChange.bind(subscriptionManager);
157-
/** PAM **/
157+
/* PAM */
158158
this.grant = endpointCreator.bind(this, modules, grantEndpointConfig);
159159
this.audit = endpointCreator.bind(this, modules, auditEndpointConfig);
160160
//
@@ -195,14 +195,16 @@ export default class {
195195
this.encrypt = crypto.encrypt.bind(crypto);
196196
this.decrypt = crypto.decrypt.bind(crypto);
197197

198-
/** config **/
198+
/* config */
199199
this.getAuthKey = modules.config.getAuthKey.bind(modules.config);
200200
this.setAuthKey = modules.config.setAuthKey.bind(modules.config);
201201
this.setCipherKey = modules.config.setCipherKey.bind(modules.config);
202202
this.getUUID = modules.config.getUUID.bind(modules.config);
203203
this.setUUID = modules.config.setUUID.bind(modules.config);
204204
this.getFilterExpression = modules.config.getFilterExpression.bind(modules.config);
205205
this.setFilterExpression = modules.config.setFilterExpression.bind(modules.config);
206+
207+
this.setHeartbeatInterval = modules.config.setHeartbeatInterval.bind(modules.config);
206208
}
207209

208210

0 commit comments

Comments
 (0)