From 0194c18cf72b8384e2892f322655ed316466e7b9 Mon Sep 17 00:00:00 2001 From: douira Date: Mon, 8 Jul 2024 02:14:19 +0200 Subject: [PATCH 1/2] Don't close socket if preserveConnection is set in HocuspocusProvider Sending the CloseMessage also has the effect of closing the socket according to its description. --- packages/provider/src/HocuspocusProvider.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/provider/src/HocuspocusProvider.ts b/packages/provider/src/HocuspocusProvider.ts index ea0eef55..2a2b3a73 100644 --- a/packages/provider/src/HocuspocusProvider.ts +++ b/packages/provider/src/HocuspocusProvider.ts @@ -511,7 +511,9 @@ export class HocuspocusProvider extends EventEmitter { this.configuration.websocketProvider.off('destroy', this.configuration.onDestroy) this.configuration.websocketProvider.off('destroy', this.forwardDestroy) - this.send(CloseMessage, { documentName: this.configuration.name }) + if (!this.configuration.preserveConnection) { + this.send(CloseMessage, { documentName: this.configuration.name }); + } this.disconnect() if (typeof window === 'undefined' || !('removeEventListener' in window)) { From ce395d82e66e27024bc127e28d6a355dfeb5e9ab Mon Sep 17 00:00:00 2001 From: Jan Thurau Date: Thu, 11 Jul 2024 22:28:40 +0200 Subject: [PATCH 2/2] lint --- packages/provider/src/HocuspocusProvider.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/provider/src/HocuspocusProvider.ts b/packages/provider/src/HocuspocusProvider.ts index 2a2b3a73..5d7681fb 100644 --- a/packages/provider/src/HocuspocusProvider.ts +++ b/packages/provider/src/HocuspocusProvider.ts @@ -512,8 +512,9 @@ export class HocuspocusProvider extends EventEmitter { this.configuration.websocketProvider.off('destroy', this.forwardDestroy) if (!this.configuration.preserveConnection) { - this.send(CloseMessage, { documentName: this.configuration.name }); + this.send(CloseMessage, { documentName: this.configuration.name }) } + this.disconnect() if (typeof window === 'undefined' || !('removeEventListener' in window)) {