@hocuspocus/provider 2.7.1 → 2.8.0

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.
@@ -1,4 +1,3 @@
1
- import * as mutex from 'lib0/mutex';
2
1
  import type { MessageEvent } from 'ws';
3
2
  import { Event } from 'ws';
4
3
  import EventEmitter from './EventEmitter.js';
@@ -85,7 +84,6 @@ export interface CompleteHocuspocusProviderWebsocketConfiguration {
85
84
  export declare class HocuspocusProviderWebsocket extends EventEmitter {
86
85
  private messageQueue;
87
86
  configuration: CompleteHocuspocusProviderWebsocketConfiguration;
88
- subscribedToBroadcastChannel: boolean;
89
87
  webSocket: HocusPocusWebSocket | null;
90
88
  webSocketHandlers: {
91
89
  [key: string]: any;
@@ -94,7 +92,6 @@ export declare class HocuspocusProviderWebsocket extends EventEmitter {
94
92
  status: WebSocketStatus;
95
93
  lastMessageReceived: number;
96
94
  identifier: number;
97
- mux: mutex.mutex;
98
95
  intervals: any;
99
96
  connectionAttempt: {
100
97
  resolve: (value?: any) => void;
@@ -108,7 +105,6 @@ export declare class HocuspocusProviderWebsocket extends EventEmitter {
108
105
  attach(provider: HocuspocusProvider): void;
109
106
  detach(provider: HocuspocusProvider): void;
110
107
  setConfiguration(configuration?: Partial<HocuspocusProviderWebsocketConfiguration>): void;
111
- boundConnect: () => Promise<unknown>;
112
108
  cancelWebsocketRetry?: () => void;
113
109
  connect(): Promise<unknown>;
114
110
  attachWebSocketListeners(ws: HocusPocusWebSocket, reject: Function): void;
@@ -19,6 +19,7 @@ export declare const defaultConfiguration: {
19
19
  gcFilter: () => boolean;
20
20
  };
21
21
  unloadImmediately: boolean;
22
+ stopOnSignals: boolean;
22
23
  };
23
24
  /**
24
25
  * Hocuspocus Server
@@ -28,7 +29,7 @@ export declare class Hocuspocus {
28
29
  documents: Map<string, Document>;
29
30
  server?: HocuspocusServer;
30
31
  debugger: Debugger;
31
- debounce: (id: string, func: Function, debounce: number, maxDebounce: number) => void;
32
+ debounce: (id: string, func: Function, debounce: number, maxDebounce: number) => any;
32
33
  constructor(configuration?: Partial<Configuration>);
33
34
  /**
34
35
  * Configure the server
@@ -116,6 +116,12 @@ export interface Configuration extends Extension {
116
116
  * your onStoreDocument is rate-limited.
117
117
  */
118
118
  unloadImmediately: boolean;
119
+ /**
120
+ * the server will gracefully stop if SIGINT, SIGQUIT or SIGTERM is received.
121
+ *
122
+ * Set this to false if you don't want that.
123
+ */
124
+ stopOnSignals: boolean;
119
125
  /**
120
126
  * options to pass to the ydoc document
121
127
  */
@@ -1 +1 @@
1
- export declare const useDebounce: () => (id: string, func: Function, debounce: number, maxDebounce: number) => void;
1
+ export declare const useDebounce: () => (id: string, func: Function, debounce: number, maxDebounce: number) => any;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hocuspocus/provider",
3
- "version": "2.7.1",
3
+ "version": "2.8.0",
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.7.1",
32
+ "@hocuspocus/common": "^2.8.0",
33
33
  "@lifeomic/attempt": "^3.0.2",
34
34
  "lib0": "^0.2.47",
35
35
  "ws": "^8.14.2"
@@ -373,13 +373,17 @@ export class HocuspocusProvider extends EventEmitter {
373
373
  disconnect() {
374
374
  this.disconnectBroadcastChannel()
375
375
  this.configuration.websocketProvider.detach(this)
376
+ this.isConnected = false
377
+
376
378
  if (!this.configuration.preserveConnection) {
377
379
  this.configuration.websocketProvider.disconnect()
378
380
  }
381
+
379
382
  }
380
383
 
381
384
  async onOpen(event: Event) {
382
385
  this.isAuthenticated = false
386
+ this.isConnected = true
383
387
 
384
388
  this.emit('open', { event })
385
389
 
@@ -475,8 +479,6 @@ export class HocuspocusProvider extends EventEmitter {
475
479
  removeAwarenessStates(this.awareness, [this.document.clientID], 'provider destroy')
476
480
  }
477
481
 
478
- this.disconnect()
479
-
480
482
  this.awareness?.off('update', this.awarenessUpdateHandler)
481
483
  this.document.off('update', this.documentUpdateHandler)
482
484
 
@@ -496,7 +498,7 @@ export class HocuspocusProvider extends EventEmitter {
496
498
  this.configuration.websocketProvider.off('destroy', this.forwardDestroy)
497
499
 
498
500
  this.send(CloseMessage, { documentName: this.configuration.name })
499
- this.isConnected = false
501
+ this.disconnect()
500
502
 
501
503
  if (typeof window === 'undefined') {
502
504
  return
@@ -2,7 +2,6 @@ import {
2
2
  Forbidden, MessageTooBig, Unauthorized, WsReadyStates,
3
3
  } from '@hocuspocus/common'
4
4
  import { retry } from '@lifeomic/attempt'
5
- import * as mutex from 'lib0/mutex'
6
5
  import * as time from 'lib0/time'
7
6
  import * as url from 'lib0/url'
8
7
  import type { MessageEvent } from 'ws'
@@ -143,8 +142,6 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
143
142
  providerMap: new Map(),
144
143
  }
145
144
 
146
- subscribedToBroadcastChannel = false
147
-
148
145
  webSocket: HocusPocusWebSocket | null = null
149
146
 
150
147
  webSocketHandlers: { [key: string]: any } = {}
@@ -157,8 +154,6 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
157
154
 
158
155
  identifier = 0
159
156
 
160
- mux = mutex.createMutex()
161
-
162
157
  intervals: any = {
163
158
  forceSync: null,
164
159
  connectionChecker: null,
@@ -247,8 +242,6 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
247
242
  this.configuration = { ...this.configuration, ...configuration }
248
243
  }
249
244
 
250
- boundConnect = this.connect.bind(this)
251
-
252
245
  cancelWebsocketRetry?: () => void
253
246
 
254
247
  async connect() {