Skip to content

Commit fb78249

Browse files
authored
Merge pull request #121 from kuzzleio/hotfix-120-onDone-callback-lost-if-offline
[MASTER] Hotfix #120 store onDone callbacks to recover from connection loss
2 parents 90b3e75 + ff8eb62 commit fb78249

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
*__note:__ the # at the end of lines are the pull request numbers on GitHub*
22

3+
# 2.1.4
4+
5+
* Fix `onDone` callbacks being lost when subscribing in a `disconnected` state #121
6+
37
# 2.1.3
48

59
* https://github.com/kuzzleio/sdk-javascript/releases/tag/2.1.3

dist/kuzzle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/kuzzle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kuzzle-sdk",
3-
"version": "2.1.3",
3+
"version": "2.1.4",
44
"description": "Official Javascript SDK for Kuzzle",
55
"author": "The Kuzzle Team <support@kuzzle.io>",
66
"repository": {

src/kuzzleRoom.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ function KuzzleRoom(kuzzleDataCollection, options) {
4545
value: null,
4646
writable: true
4747
},
48+
onDoneCB: {
49+
value: null,
50+
writable: true
51+
},
4852
queue: {
4953
value: [],
5054
writable: true
@@ -166,13 +170,17 @@ KuzzleRoom.prototype.renew = function (filters, notificationCB, cb) {
166170
filters = null;
167171
}
168172

173+
if (!cb) {
174+
cb = self.onDoneCB;
175+
}
176+
169177
self.kuzzle.callbackRequired('KuzzleRoom.renew', notificationCB);
170178

171179
/*
172180
Skip subscription renewal if another one was performed a moment before
173181
*/
174182
if (self.lastRenewal && (now - self.lastRenewal) <= self.renewalDelay) {
175-
return;
183+
return cb && cb(new Error('Subscription already renewed less than ' + self.renewalDelay + 'ms ago'));
176184
}
177185

178186
if (filters) {
@@ -185,6 +193,7 @@ KuzzleRoom.prototype.renew = function (filters, notificationCB, cb) {
185193
*/
186194
if (self.kuzzle.state !== 'connected') {
187195
self.callback = notificationCB;
196+
self.onDoneCB = cb;
188197
self.kuzzle.subscriptions.pending[self.id] = self;
189198
return;
190199
}
@@ -198,6 +207,7 @@ KuzzleRoom.prototype.renew = function (filters, notificationCB, cb) {
198207
self.roomId = null;
199208
self.subscribing = true;
200209
self.callback = notificationCB;
210+
self.onDoneCB = cb;
201211
self.kuzzle.subscriptions.pending[self.id] = self;
202212

203213
subscribeQuery.body = self.filters;

0 commit comments

Comments
 (0)