@hocuspocus/provider 2.12.3 → 2.13.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.
- package/dist/hocuspocus-provider.cjs +12 -7
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +12 -7
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +3 -2
- package/dist/packages/server/src/Hocuspocus.d.ts +2 -0
- package/package.json +2 -2
- package/src/HocuspocusProvider.ts +15 -7
|
@@ -89,7 +89,7 @@ export declare class HocuspocusProvider extends EventEmitter {
|
|
|
89
89
|
isConnected: boolean;
|
|
90
90
|
constructor(configuration: HocuspocusProviderConfiguration);
|
|
91
91
|
boundBroadcastChannelSubscriber: (data: ArrayBuffer) => void;
|
|
92
|
-
|
|
92
|
+
boundPageHide: () => void;
|
|
93
93
|
boundOnOpen: (event: Event) => Promise<void>;
|
|
94
94
|
boundOnClose: (event: CloseEvent) => void;
|
|
95
95
|
boundOnStatus: ({ status }: onStatusParameters) => void;
|
|
@@ -103,10 +103,11 @@ export declare class HocuspocusProvider extends EventEmitter {
|
|
|
103
103
|
get document(): Y.Doc;
|
|
104
104
|
get awareness(): Awareness | null;
|
|
105
105
|
get hasUnsyncedChanges(): boolean;
|
|
106
|
+
private resetUnsyncedChanges;
|
|
106
107
|
incrementUnsyncedChanges(): void;
|
|
107
108
|
decrementUnsyncedChanges(): void;
|
|
108
109
|
forceSync(): void;
|
|
109
|
-
|
|
110
|
+
pageHide(): void;
|
|
110
111
|
registerEventListeners(): void;
|
|
111
112
|
sendStateless(payload: string): void;
|
|
112
113
|
documentUpdateHandler(update: Uint8Array, origin: any): void;
|
|
@@ -26,6 +26,7 @@ export declare const defaultConfiguration: {
|
|
|
26
26
|
*/
|
|
27
27
|
export declare class Hocuspocus {
|
|
28
28
|
configuration: Configuration;
|
|
29
|
+
loadingDocuments: Map<string, Promise<Document>>;
|
|
29
30
|
documents: Map<string, Document>;
|
|
30
31
|
server?: HocuspocusServer;
|
|
31
32
|
debugger: Debugger;
|
|
@@ -87,6 +88,7 @@ export declare class Hocuspocus {
|
|
|
87
88
|
* Create a new document by the given request
|
|
88
89
|
*/
|
|
89
90
|
createDocument(documentName: string, request: Partial<Pick<IncomingMessage, 'headers' | 'url'>>, socketId: string, connection: ConnectionConfiguration, context?: any): Promise<Document>;
|
|
91
|
+
loadDocument(documentName: string, request: Partial<Pick<IncomingMessage, 'headers' | 'url'>>, socketId: string, connection: ConnectionConfiguration, context?: any): Promise<Document>;
|
|
90
92
|
storeDocumentHooks(document: Document, hookPayload: onStoreDocumentPayload): Promise<void>;
|
|
91
93
|
/**
|
|
92
94
|
* Run the given hook on all configured extensions.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hocuspocus/provider",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.13.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.
|
|
32
|
+
"@hocuspocus/common": "^2.13.1",
|
|
33
33
|
"@lifeomic/attempt": "^3.0.2",
|
|
34
34
|
"lib0": "^0.2.87",
|
|
35
35
|
"ws": "^8.14.2"
|
|
@@ -231,7 +231,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
231
231
|
|
|
232
232
|
boundBroadcastChannelSubscriber = this.broadcastChannelSubscriber.bind(this)
|
|
233
233
|
|
|
234
|
-
|
|
234
|
+
boundPageHide = this.pageHide.bind(this)
|
|
235
235
|
|
|
236
236
|
boundOnOpen = this.onOpen.bind(this)
|
|
237
237
|
|
|
@@ -282,6 +282,11 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
282
282
|
return this.unsyncedChanges > 0
|
|
283
283
|
}
|
|
284
284
|
|
|
285
|
+
private resetUnsyncedChanges() {
|
|
286
|
+
this.unsyncedChanges = 1
|
|
287
|
+
this.emit('unsyncedChanges', this.unsyncedChanges)
|
|
288
|
+
}
|
|
289
|
+
|
|
285
290
|
incrementUnsyncedChanges() {
|
|
286
291
|
this.unsyncedChanges += 1
|
|
287
292
|
this.emit('unsyncedChanges', this.unsyncedChanges)
|
|
@@ -296,12 +301,14 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
296
301
|
}
|
|
297
302
|
|
|
298
303
|
forceSync() {
|
|
304
|
+
this.resetUnsyncedChanges()
|
|
305
|
+
|
|
299
306
|
this.send(SyncStepOneMessage, { document: this.document, documentName: this.configuration.name })
|
|
300
307
|
}
|
|
301
308
|
|
|
302
|
-
|
|
309
|
+
pageHide() {
|
|
303
310
|
if (this.awareness) {
|
|
304
|
-
removeAwarenessStates(this.awareness, [this.document.clientID], '
|
|
311
|
+
removeAwarenessStates(this.awareness, [this.document.clientID], 'page hide')
|
|
305
312
|
}
|
|
306
313
|
}
|
|
307
314
|
|
|
@@ -310,7 +317,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
310
317
|
return
|
|
311
318
|
}
|
|
312
319
|
|
|
313
|
-
window.addEventListener('
|
|
320
|
+
window.addEventListener('pagehide', this.boundPageHide)
|
|
314
321
|
}
|
|
315
322
|
|
|
316
323
|
sendStateless(payload: string) {
|
|
@@ -364,7 +371,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
364
371
|
return !!this.configuration.token && !this.isAuthenticated
|
|
365
372
|
}
|
|
366
373
|
|
|
367
|
-
// not needed, but provides backward compatibility with e.g.
|
|
374
|
+
// not needed, but provides backward compatibility with e.g. lexical/yjs
|
|
368
375
|
async connect() {
|
|
369
376
|
if (this.configuration.broadcast) {
|
|
370
377
|
this.subscribeToBroadcastChannel()
|
|
@@ -420,7 +427,8 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
420
427
|
}
|
|
421
428
|
|
|
422
429
|
startSync() {
|
|
423
|
-
this.
|
|
430
|
+
this.resetUnsyncedChanges()
|
|
431
|
+
|
|
424
432
|
this.send(SyncStepOneMessage, { document: this.document, documentName: this.configuration.name })
|
|
425
433
|
|
|
426
434
|
if (this.awareness && this.awareness.getLocalState() !== null) {
|
|
@@ -510,7 +518,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
510
518
|
return
|
|
511
519
|
}
|
|
512
520
|
|
|
513
|
-
window.removeEventListener('
|
|
521
|
+
window.removeEventListener('pagehide', this.boundPageHide)
|
|
514
522
|
}
|
|
515
523
|
|
|
516
524
|
permissionDeniedHandler(reason: string) {
|