Skip to content

Commit

Permalink
[#204] cancel any pending submit requests on realtime disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
ganigeorgiev committed Jun 1, 2023
1 parent b263cec commit 728c647
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.15.1

- Cancel any pending submit requests on realtime disconnect ([#204](https://github.com/pocketbase/js-sdk/issues/204)).


## 0.15.0

- Added `fields` to the optional query parameters for limiting the returned API fields (_available with PocketBase v0.16.0_).
Expand Down
1 change: 1 addition & 0 deletions dist/pocketbase.cjs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ declare class RealtimeService extends BaseService {
unsubscribeByTopicAndListener(topic: string, listener: EventListener): Promise<void>;
private hasSubscriptionListeners;
private submitSubscriptions;
private getSubscriptionsCancelKey;
private getNonEmptySubscriptionTopics;
private addAllSubscriptionListeners;
private removeAllSubscriptionListeners;
Expand Down
2 changes: 1 addition & 1 deletion dist/pocketbase.cjs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.cjs.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/pocketbase.es.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ declare class RealtimeService extends BaseService {
unsubscribeByTopicAndListener(topic: string, listener: EventListener): Promise<void>;
private hasSubscriptionListeners;
private submitSubscriptions;
private getSubscriptionsCancelKey;
private getNonEmptySubscriptionTopics;
private addAllSubscriptionListeners;
private removeAllSubscriptionListeners;
Expand Down
2 changes: 1 addition & 1 deletion dist/pocketbase.es.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.mjs.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/pocketbase.iife.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ declare class RealtimeService extends BaseService {
unsubscribeByTopicAndListener(topic: string, listener: EventListener): Promise<void>;
private hasSubscriptionListeners;
private submitSubscriptions;
private getSubscriptionsCancelKey;
private getNonEmptySubscriptionTopics;
private addAllSubscriptionListeners;
private removeAllSubscriptionListeners;
Expand Down
2 changes: 1 addition & 1 deletion dist/pocketbase.iife.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.iife.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/pocketbase.umd.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ declare class RealtimeService extends BaseService {
unsubscribeByTopicAndListener(topic: string, listener: EventListener): Promise<void>;
private hasSubscriptionListeners;
private submitSubscriptions;
private getSubscriptionsCancelKey;
private getNonEmptySubscriptionTopics;
private addAllSubscriptionListeners;
private removeAllSubscriptionListeners;
Expand Down
2 changes: 1 addition & 1 deletion dist/pocketbase.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.umd.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.15.0",
"version": "0.15.1",
"name": "pocketbase",
"description": "PocketBase JavaScript SDK",
"author": "Gani Georgiev",
Expand Down
7 changes: 6 additions & 1 deletion src/services/RealtimeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export default class RealtimeService extends BaseService {
'subscriptions': this.lastSentTopics,
},
'params': {
'$cancelKey': "realtime_" + this.clientId,
'$cancelKey': this.getSubscriptionsCancelKey(),
},
}).catch((err) => {
if (err?.isAbort) {
Expand All @@ -237,6 +237,10 @@ export default class RealtimeService extends BaseService {
});
}

private getSubscriptionsCancelKey(): string {
return "realtime_" + this.clientId;
}

private getNonEmptySubscriptionTopics(): Array<string> {
const result : Array<string> = [];

Expand Down Expand Up @@ -387,6 +391,7 @@ export default class RealtimeService extends BaseService {
clearTimeout(this.connectTimeoutId);
clearTimeout(this.reconnectTimeoutId);
this.removeAllSubscriptionListeners();
this.client.cancelRequest(this.getSubscriptionsCancelKey());
this.eventSource?.close();
this.eventSource = null;
this.clientId = "";
Expand Down

0 comments on commit 728c647

Please sign in to comment.