@hocuspocus/provider 2.3.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -105,6 +105,7 @@ export declare class HocuspocusProviderWebsocket extends EventEmitter {
105
105
  resolveConnectionAttempt(): void;
106
106
  stopConnectionAttempt(): void;
107
107
  rejectConnectionAttempt(): void;
108
+ closeTries: number;
108
109
  checkConnection(): void;
109
110
  registerEventListeners(): void;
110
111
  get serverUrl(): string;
@@ -1,7 +1,8 @@
1
1
  import { Encoder } from 'lib0/encoding';
2
- import type { CloseEvent, Event, MessageEvent } from 'ws';
2
+ import type { Event, MessageEvent } from 'ws';
3
3
  import { Awareness } from 'y-protocols/awareness';
4
4
  import * as Y from 'yjs';
5
+ import { CloseEvent } from '@hocuspocus/common';
5
6
  import { IncomingMessage } from './IncomingMessage.js';
6
7
  import { OutgoingMessage } from './OutgoingMessage.js';
7
8
  import { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hocuspocus/provider",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "hocuspocus provider",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
@@ -29,7 +29,7 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@hocuspocus/common": "^2.3.0",
32
+ "@hocuspocus/common": "^2.3.1",
33
33
  "@lifeomic/attempt": "^3.0.2",
34
34
  "lib0": "^0.2.47",
35
35
  "ws": "^7.5.9"
@@ -350,6 +350,8 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
350
350
  this.connectionAttempt = null
351
351
  }
352
352
 
353
+ closeTries = 0
354
+
353
355
  checkConnection() {
354
356
  // Don’t check the connection when it’s not even established
355
357
  if (this.status !== WebSocketStatus.Connected) {
@@ -368,8 +370,21 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
368
370
 
369
371
  // No message received in a long time, not even your own
370
372
  // Awareness updates, which are updated every 15 seconds.
371
- this.webSocket?.close()
372
- this.messageQueue = []
373
+ this.closeTries += 1
374
+ // https://bugs.webkit.org/show_bug.cgi?id=247943
375
+ if (this.closeTries > 2) {
376
+ this.onClose({
377
+ event: {
378
+ code: 4408,
379
+ reason: 'forced',
380
+ },
381
+ })
382
+ this.closeTries = 0
383
+ } else {
384
+ this.webSocket?.close()
385
+ this.messageQueue = []
386
+ }
387
+
373
388
  }
374
389
 
375
390
  registerEventListeners() {
@@ -419,6 +434,7 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
419
434
  }
420
435
 
421
436
  onClose({ event }: onCloseParameters) {
437
+ this.closeTries = 0
422
438
  this.webSocket = null
423
439
 
424
440
  if (this.status === WebSocketStatus.Connected) {
package/src/types.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { Encoder } from 'lib0/encoding'
2
- import type { CloseEvent, Event, MessageEvent } from 'ws'
2
+ import type { Event, MessageEvent } from 'ws'
3
3
  import { Awareness } from 'y-protocols/awareness'
4
4
  import * as Y from 'yjs'
5
+ import { CloseEvent } from '@hocuspocus/common'
5
6
  import { IncomingMessage } from './IncomingMessage.js'
6
7
  import { OutgoingMessage } from './OutgoingMessage.js'
7
8
  import { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage.js'