Skip to content

Commit 16e1440

Browse files
jzucker2Max Presman
authored andcommitted
Updated to include timetokens in status responses
1 parent d33419f commit 16e1440

File tree

3 files changed

+80
-362
lines changed

3 files changed

+80
-362
lines changed

src/core/components/subscription_manager.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ export default class {
5454
_channelGroups: Object;
5555
_presenceChannelGroups: Object;
5656

57-
_timetoken: number;
57+
_currentTimetoken: number;
58+
_lastTimetoken: number;
5859
_region: ?number;
5960

6061
_subscribeCall: ?Object;
@@ -87,7 +88,9 @@ export default class {
8788
this._pendingChannelSubscriptions = [];
8889
this._pendingChannelGroupSubscriptions = [];
8990

90-
this._timetoken = 0;
91+
this._currentTimetoken = 0;
92+
this._lastTimetoken = 0;
93+
9194
this._subscriptionStatusAnnounced = false;
9295

9396
this._reconnectionManager = new ReconnectionManager({ timeEndpoint });
@@ -115,7 +118,10 @@ export default class {
115118
return;
116119
}
117120

118-
if (timetoken) this._timetoken = timetoken;
121+
if (timetoken) {
122+
this._lastTimetoken = this._currentTimetoken;
123+
this._currentTimetoken = timetoken;
124+
}
119125

120126
channels.forEach((channel: string) => {
121127
this._channels[channel] = { state: {} };
@@ -152,6 +158,8 @@ export default class {
152158
this._leaveEndpoint({ channels, channelGroups }, (status) => {
153159
status.affectedChannels = channels;
154160
status.affectedChannelGroups = channelGroups;
161+
status.currentTimetoken = this._currentTimetoken;
162+
status.lastTimetoken = this._lastTimetoken;
155163
this._listenerManager.announceStatus(status);
156164
});
157165
}
@@ -161,7 +169,8 @@ export default class {
161169
Object.keys(this._presenceChannels).length === 0 &&
162170
Object.keys(this._channelGroups).length === 0 &&
163171
Object.keys(this._presenceChannelGroups).length === 0) {
164-
this._timetoken = 0;
172+
this._lastTimetoken = 0;
173+
this._currentTimetoken = 0;
165174
this._region = null;
166175
this._reconnectionManager.stopPolling();
167176
}
@@ -258,7 +267,7 @@ export default class {
258267
const subscribeArgs = {
259268
channels,
260269
channelGroups,
261-
timetoken: this._timetoken,
270+
timetoken: this._currentTimetoken,
262271
filterExpression: this._config.filterExpression,
263272
region: this._region
264273
};
@@ -279,7 +288,9 @@ export default class {
279288
this._subscriptionStatusAnnounced = true;
280289
let reconnectedAnnounce: StatusAnnouncement = {
281290
category: categoryConstants.PNReconnectedCategory,
282-
operation: status.operation
291+
operation: status.operation,
292+
lastTimetoken: this._lastTimetoken,
293+
currentTimetoken: this._currentTimetoken
283294
};
284295
this._listenerManager.announceStatus(reconnectedAnnounce);
285296
});
@@ -292,12 +303,18 @@ export default class {
292303
return;
293304
}
294305

306+
this._lastTimetoken = this._currentTimetoken;
307+
this._currentTimetoken = payload.metadata.timetoken;
308+
309+
295310
if (!this._subscriptionStatusAnnounced) {
296311
let connectedAnnounce: StatusAnnouncement = {};
297312
connectedAnnounce.category = categoryConstants.PNConnectedCategory;
298313
connectedAnnounce.operation = status.operation;
299314
connectedAnnounce.affectedChannels = this._pendingChannelSubscriptions;
300315
connectedAnnounce.affectedChannelGroups = this._pendingChannelGroupSubscriptions;
316+
connectedAnnounce.lastTimetoken = this._lastTimetoken;
317+
connectedAnnounce.currentTimetoken = this._currentTimetoken;
301318
this._subscriptionStatusAnnounced = true;
302319
this._listenerManager.announceStatus(connectedAnnounce);
303320

@@ -385,7 +402,6 @@ export default class {
385402
});
386403

387404
this._region = payload.metadata.region;
388-
this._timetoken = payload.metadata.timetoken;
389405
this._startSubscribeLoop();
390406
}
391407

src/core/flow_interfaces.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ export type StatusAnnouncement = {
162162
statusCode: number,
163163
category: string,
164164
errorData: Object,
165+
lastTimetoken: number,
166+
currentTimetoken: number,
165167

166168
// send back channel, channel groups that were affected by this operation
167169
affectedChannels: Array<String>,

0 commit comments

Comments
 (0)