@hocuspocus/provider 2.13.5 → 3.0.0-rc.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.
- package/dist/hocuspocus-provider.cjs +11079 -992
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +11064 -955
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/common/src/auth.d.ts +1 -1
- package/dist/packages/extension-database/src/Database.d.ts +1 -1
- package/dist/packages/extension-logger/src/Logger.d.ts +1 -1
- package/dist/packages/extension-redis/src/Redis.d.ts +4 -3
- package/dist/packages/extension-sqlite/src/SQLite.d.ts +2 -1
- package/dist/packages/extension-throttle/src/index.d.ts +2 -3
- package/dist/packages/extension-webhook/src/index.d.ts +3 -4
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +4 -13
- package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +5 -5
- package/dist/packages/provider/src/IncomingMessage.d.ts +3 -3
- package/dist/packages/provider/src/MessageReceiver.d.ts +2 -2
- package/dist/packages/provider/src/MessageSender.d.ts +2 -2
- package/dist/packages/provider/src/OutgoingMessage.d.ts +2 -2
- package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +2 -1
- package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +2 -1
- package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +2 -1
- package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +2 -1
- package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +2 -1
- package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +2 -1
- package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +2 -1
- package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +2 -1
- package/dist/packages/provider/src/TiptapCollabProvider.d.ts +2 -1
- package/dist/packages/provider/src/TiptapCollabProviderWebsocket.d.ts +2 -1
- package/dist/packages/provider/src/types.d.ts +12 -12
- package/dist/packages/server/src/ClientConnection.d.ts +6 -7
- package/dist/packages/server/src/Connection.d.ts +7 -9
- package/dist/packages/server/src/DirectConnection.d.ts +1 -1
- package/dist/packages/server/src/Document.d.ts +5 -5
- package/dist/packages/server/src/Hocuspocus.d.ts +6 -27
- package/dist/packages/server/src/IncomingMessage.d.ts +3 -3
- package/dist/packages/server/src/MessageReceiver.d.ts +4 -4
- package/dist/packages/server/src/OutgoingMessage.d.ts +3 -3
- package/dist/packages/server/src/Server.d.ts +22 -3
- package/dist/packages/server/src/index.d.ts +1 -0
- package/dist/packages/server/src/types.d.ts +7 -24
- package/dist/packages/server/src/util/getParameters.d.ts +1 -3
- package/dist/packages/transformer/src/Prosemirror.d.ts +1 -1
- package/dist/packages/transformer/src/Tiptap.d.ts +3 -3
- package/dist/packages/transformer/src/types.d.ts +1 -1
- package/dist/tests/utils/newHocuspocus.d.ts +2 -2
- package/dist/tests/utils/newHocuspocusProvider.d.ts +2 -2
- package/dist/tests/utils/newHocuspocusProviderWebsocket.d.ts +4 -3
- package/dist/tests/utils/retryableAssertion.d.ts +1 -1
- package/package.json +2 -2
- package/src/EventEmitter.ts +3 -1
- package/src/HocuspocusProvider.ts +107 -107
- package/src/HocuspocusProviderWebsocket.ts +9 -10
- package/src/IncomingMessage.ts +5 -3
- package/src/MessageReceiver.ts +2 -2
- package/src/MessageSender.ts +3 -2
- package/src/OutgoingMessage.ts +3 -2
- package/src/OutgoingMessages/AuthenticationMessage.ts +2 -1
- package/src/OutgoingMessages/AwarenessMessage.ts +2 -1
- package/src/OutgoingMessages/CloseMessage.ts +2 -1
- package/src/OutgoingMessages/QueryAwarenessMessage.ts +2 -1
- package/src/OutgoingMessages/StatelessMessage.ts +2 -1
- package/src/OutgoingMessages/SyncStepOneMessage.ts +2 -1
- package/src/OutgoingMessages/SyncStepTwoMessage.ts +2 -1
- package/src/OutgoingMessages/UpdateMessage.ts +2 -1
- package/src/TiptapCollabProvider.ts +2 -1
- package/src/TiptapCollabProviderWebsocket.ts +3 -2
- package/src/types.ts +12 -12
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Doc } from 'yjs';
|
|
2
|
-
import { Extensions } from '@tiptap/core';
|
|
3
|
-
import { Transformer } from './types.js';
|
|
1
|
+
import type { Doc } from 'yjs';
|
|
2
|
+
import type { Extensions } from '@tiptap/core';
|
|
3
|
+
import type { Transformer } from './types.js';
|
|
4
4
|
export declare class Tiptap implements Transformer {
|
|
5
5
|
defaultExtensions: Extensions;
|
|
6
6
|
extensions(extensions: Extensions): Tiptap;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const newHocuspocus: (options?: Partial<
|
|
1
|
+
import type { ServerConfiguration } from '@hocuspocus/server';
|
|
2
|
+
export declare const newHocuspocus: (options?: Partial<ServerConfiguration>) => Promise<import("@hocuspocus/server").Hocuspocus>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { HocuspocusProvider, HocuspocusProviderConfiguration, HocuspocusProviderWebsocketConfiguration } from '@hocuspocus/provider';
|
|
2
|
-
import { Hocuspocus } from '@hocuspocus/server';
|
|
1
|
+
import { HocuspocusProvider, type HocuspocusProviderConfiguration, type HocuspocusProviderWebsocketConfiguration } from '@hocuspocus/provider';
|
|
2
|
+
import type { Hocuspocus } from '@hocuspocus/server';
|
|
3
3
|
export declare const newHocuspocusProvider: (server: Hocuspocus, options?: Partial<HocuspocusProviderConfiguration>, websocketOptions?: Partial<HocuspocusProviderWebsocketConfiguration>) => HocuspocusProvider;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import type { HocuspocusProviderWebsocketConfiguration } from '@hocuspocus/provider';
|
|
2
|
+
import { HocuspocusProviderWebsocket } from '@hocuspocus/provider';
|
|
3
|
+
import type { Hocuspocus } from '@hocuspocus/server';
|
|
4
|
+
export declare const newHocuspocusProviderWebsocket: (hocuspocus: Hocuspocus, options?: Partial<Omit<HocuspocusProviderWebsocketConfiguration, "url">>) => HocuspocusProviderWebsocket;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ExecutionContext } from 'ava';
|
|
1
|
+
import type { ExecutionContext } from 'ava';
|
|
2
2
|
export declare const retryableAssertion: (t: ExecutionContext, recoverableTry: (tt: ExecutionContext) => void) => Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hocuspocus/provider",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-rc.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": "^
|
|
32
|
+
"@hocuspocus/common": "^3.0.0-rc.0",
|
|
33
33
|
"@lifeomic/attempt": "^3.0.2",
|
|
34
34
|
"lib0": "^0.2.87",
|
|
35
35
|
"ws": "^8.17.1"
|
package/src/EventEmitter.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export default class EventEmitter {
|
|
2
|
-
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
3
3
|
public callbacks: { [key: string]: Function[] } = {}
|
|
4
4
|
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
5
6
|
public on(event: string, fn: Function): this {
|
|
6
7
|
if (!this.callbacks[event]) {
|
|
7
8
|
this.callbacks[event] = []
|
|
@@ -22,6 +23,7 @@ export default class EventEmitter {
|
|
|
22
23
|
return this
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
25
27
|
public off(event: string, fn?: Function): this {
|
|
26
28
|
const callbacks = this.callbacks[event]
|
|
27
29
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { awarenessStatesToArray } from '@hocuspocus/common'
|
|
2
|
-
import * as bc from 'lib0/broadcastchannel'
|
|
3
2
|
import * as mutex from 'lib0/mutex'
|
|
4
3
|
import type { CloseEvent, Event, MessageEvent } from 'ws'
|
|
5
4
|
import { Awareness, removeAwarenessStates } from 'y-protocols/awareness'
|
|
6
5
|
import * as Y from 'yjs'
|
|
7
6
|
import EventEmitter from './EventEmitter.js'
|
|
7
|
+
import type {
|
|
8
|
+
CompleteHocuspocusProviderWebsocketConfiguration} from './HocuspocusProviderWebsocket.js'
|
|
8
9
|
import {
|
|
9
|
-
CompleteHocuspocusProviderWebsocketConfiguration,
|
|
10
10
|
HocuspocusProviderWebsocket,
|
|
11
11
|
} from './HocuspocusProviderWebsocket.js'
|
|
12
12
|
import { IncomingMessage } from './IncomingMessage.js'
|
|
@@ -15,14 +15,11 @@ import { MessageSender } from './MessageSender.js'
|
|
|
15
15
|
import { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage.js'
|
|
16
16
|
import { AwarenessMessage } from './OutgoingMessages/AwarenessMessage.js'
|
|
17
17
|
import { CloseMessage } from './OutgoingMessages/CloseMessage.js'
|
|
18
|
-
import { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage.js'
|
|
19
18
|
import { StatelessMessage } from './OutgoingMessages/StatelessMessage.js'
|
|
20
19
|
import { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage.js'
|
|
21
|
-
import { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage.js'
|
|
22
20
|
import { UpdateMessage } from './OutgoingMessages/UpdateMessage.js'
|
|
23
|
-
import {
|
|
21
|
+
import type {
|
|
24
22
|
ConstructableOutgoingMessage,
|
|
25
|
-
WebSocketStatus,
|
|
26
23
|
onAuthenticationFailedParameters,
|
|
27
24
|
onAwarenessChangeParameters,
|
|
28
25
|
onAwarenessUpdateParameters,
|
|
@@ -153,7 +150,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
153
150
|
|
|
154
151
|
unsyncedChanges = 0
|
|
155
152
|
|
|
156
|
-
status = WebSocketStatus.Disconnected
|
|
153
|
+
// status = WebSocketStatus.Disconnected
|
|
157
154
|
|
|
158
155
|
isAuthenticated = false
|
|
159
156
|
|
|
@@ -165,7 +162,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
165
162
|
forceSync: null,
|
|
166
163
|
}
|
|
167
164
|
|
|
168
|
-
isConnected = true
|
|
165
|
+
// isConnected = true
|
|
169
166
|
|
|
170
167
|
constructor(configuration: HocuspocusProviderConfiguration) {
|
|
171
168
|
super()
|
|
@@ -196,7 +193,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
196
193
|
this.configuration.websocketProvider.on('close', this.configuration.onClose)
|
|
197
194
|
this.configuration.websocketProvider.on('close', this.forwardClose)
|
|
198
195
|
|
|
199
|
-
this.configuration.websocketProvider.on('status', this.boundOnStatus)
|
|
196
|
+
// this.configuration.websocketProvider.on('status', this.boundOnStatus)
|
|
200
197
|
|
|
201
198
|
this.configuration.websocketProvider.on('disconnect', this.configuration.onDisconnect)
|
|
202
199
|
this.configuration.websocketProvider.on('disconnect', this.forwardDisconnect)
|
|
@@ -229,7 +226,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
229
226
|
this.configuration.websocketProvider.attach(this)
|
|
230
227
|
}
|
|
231
228
|
|
|
232
|
-
boundBroadcastChannelSubscriber = this.broadcastChannelSubscriber.bind(this)
|
|
229
|
+
// boundBroadcastChannelSubscriber = this.broadcastChannelSubscriber.bind(this)
|
|
233
230
|
|
|
234
231
|
boundPageHide = this.pageHide.bind(this)
|
|
235
232
|
|
|
@@ -237,7 +234,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
237
234
|
|
|
238
235
|
boundOnClose = this.onClose.bind(this)
|
|
239
236
|
|
|
240
|
-
boundOnStatus = this.onStatus.bind(this)
|
|
237
|
+
// boundOnStatus = this.onStatus.bind(this)
|
|
241
238
|
|
|
242
239
|
forwardConnect = (e: any) => this.emit('connect', e)
|
|
243
240
|
|
|
@@ -249,12 +246,12 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
249
246
|
|
|
250
247
|
forwardDestroy = (e: any) => this.emit('destroy', e)
|
|
251
248
|
|
|
252
|
-
public onStatus({ status } : onStatusParameters) {
|
|
253
|
-
this.status = status
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
249
|
+
// public onStatus({ status } : onStatusParameters) {
|
|
250
|
+
// this.status = status
|
|
251
|
+
//
|
|
252
|
+
// this.configuration.onStatus({ status })
|
|
253
|
+
// this.emit('status', { status })
|
|
254
|
+
// }
|
|
258
255
|
|
|
259
256
|
public setConfiguration(configuration: Partial<HocuspocusProviderConfiguration> = {}): void {
|
|
260
257
|
if (!configuration.websocketProvider && (configuration as CompleteHocuspocusProviderWebsocketConfiguration).url) {
|
|
@@ -373,29 +370,31 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
373
370
|
|
|
374
371
|
// not needed, but provides backward compatibility with e.g. lexical/yjs
|
|
375
372
|
async connect() {
|
|
376
|
-
|
|
377
|
-
this.subscribeToBroadcastChannel()
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
this.configuration.websocketProvider.shouldConnect = true
|
|
373
|
+
console.warn('HocuspocusProvider::connect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.')
|
|
381
374
|
|
|
382
|
-
|
|
375
|
+
// if (this.configuration.broadcast) {
|
|
376
|
+
// this.subscribeToBroadcastChannel()
|
|
377
|
+
// }
|
|
378
|
+
//
|
|
379
|
+
// return this.configuration.websocketProvider.connect()
|
|
383
380
|
}
|
|
384
381
|
|
|
385
382
|
disconnect() {
|
|
386
|
-
|
|
387
|
-
this.configuration.websocketProvider.detach(this)
|
|
388
|
-
this.isConnected = false
|
|
389
|
-
|
|
390
|
-
if (!this.configuration.preserveConnection) {
|
|
391
|
-
this.configuration.websocketProvider.disconnect()
|
|
392
|
-
}
|
|
383
|
+
console.warn('HocuspocusProvider::disconnect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.')
|
|
393
384
|
|
|
385
|
+
// this.disconnectBroadcastChannel()
|
|
386
|
+
// this.configuration.websocketProvider.detach(this)
|
|
387
|
+
// this.isConnected = false
|
|
388
|
+
//
|
|
389
|
+
// if (!this.configuration.preserveConnection) {
|
|
390
|
+
// this.configuration.websocketProvider.disconnect()
|
|
391
|
+
// }
|
|
392
|
+
//
|
|
394
393
|
}
|
|
395
394
|
|
|
396
395
|
async onOpen(event: Event) {
|
|
397
396
|
this.isAuthenticated = false
|
|
398
|
-
this.isConnected = true
|
|
397
|
+
// this.isConnected = true
|
|
399
398
|
|
|
400
399
|
this.emit('open', { event })
|
|
401
400
|
|
|
@@ -441,13 +440,13 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
441
440
|
}
|
|
442
441
|
|
|
443
442
|
send(message: ConstructableOutgoingMessage, args: any, broadcast = false) {
|
|
444
|
-
if (!this.isConnected) {
|
|
445
|
-
|
|
446
|
-
}
|
|
443
|
+
// if (!this.isConnected) {
|
|
444
|
+
// return
|
|
445
|
+
// }
|
|
447
446
|
|
|
448
|
-
if (broadcast) {
|
|
449
|
-
|
|
450
|
-
}
|
|
447
|
+
// if (broadcast) {
|
|
448
|
+
// this.mux(() => { this.broadcast(message, args) })
|
|
449
|
+
// }
|
|
451
450
|
|
|
452
451
|
const messageSender = new MessageSender(message, args)
|
|
453
452
|
|
|
@@ -505,13 +504,14 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
505
504
|
this.configuration.websocketProvider.off('close', this.boundOnClose)
|
|
506
505
|
this.configuration.websocketProvider.off('close', this.configuration.onClose)
|
|
507
506
|
this.configuration.websocketProvider.off('close', this.forwardClose)
|
|
508
|
-
this.configuration.websocketProvider.off('status', this.boundOnStatus)
|
|
507
|
+
// this.configuration.websocketProvider.off('status', this.boundOnStatus)
|
|
509
508
|
this.configuration.websocketProvider.off('disconnect', this.configuration.onDisconnect)
|
|
510
509
|
this.configuration.websocketProvider.off('disconnect', this.forwardDisconnect)
|
|
511
510
|
this.configuration.websocketProvider.off('destroy', this.configuration.onDestroy)
|
|
512
511
|
this.configuration.websocketProvider.off('destroy', this.forwardDestroy)
|
|
513
512
|
|
|
514
513
|
this.send(CloseMessage, { documentName: this.configuration.name })
|
|
514
|
+
this.configuration.websocketProvider.detach(this)
|
|
515
515
|
this.disconnect()
|
|
516
516
|
|
|
517
517
|
if (typeof window === 'undefined' || !('removeEventListener' in window)) {
|
|
@@ -524,8 +524,8 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
524
524
|
permissionDeniedHandler(reason: string) {
|
|
525
525
|
this.emit('authenticationFailed', { reason })
|
|
526
526
|
this.isAuthenticated = false
|
|
527
|
-
this.disconnect()
|
|
528
|
-
this.status = WebSocketStatus.Disconnected
|
|
527
|
+
// this.disconnect()
|
|
528
|
+
// this.status = WebSocketStatus.Disconnected
|
|
529
529
|
}
|
|
530
530
|
|
|
531
531
|
authenticatedHandler(scope: string) {
|
|
@@ -535,73 +535,73 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
535
535
|
this.emit('authenticated')
|
|
536
536
|
}
|
|
537
537
|
|
|
538
|
-
get broadcastChannel() {
|
|
539
|
-
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
broadcastChannelSubscriber(data: ArrayBuffer) {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
subscribeToBroadcastChannel() {
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
disconnectBroadcastChannel() {
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
broadcast(Message: ConstructableOutgoingMessage, args?: any) {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
}
|
|
538
|
+
// get broadcastChannel() {
|
|
539
|
+
// return `${this.configuration.name}`
|
|
540
|
+
// }
|
|
541
|
+
//
|
|
542
|
+
// broadcastChannelSubscriber(data: ArrayBuffer) {
|
|
543
|
+
// this.mux(() => {
|
|
544
|
+
// const message = new IncomingMessage(data)
|
|
545
|
+
//
|
|
546
|
+
// const documentName = message.readVarString()
|
|
547
|
+
//
|
|
548
|
+
// message.writeVarString(documentName)
|
|
549
|
+
//
|
|
550
|
+
// new MessageReceiver(message)
|
|
551
|
+
// .setBroadcasted(true)
|
|
552
|
+
// .apply(this, false)
|
|
553
|
+
// })
|
|
554
|
+
// }
|
|
555
|
+
|
|
556
|
+
// subscribeToBroadcastChannel() {
|
|
557
|
+
// if (!this.subscribedToBroadcastChannel) {
|
|
558
|
+
// bc.subscribe(this.broadcastChannel, this.boundBroadcastChannelSubscriber)
|
|
559
|
+
// this.subscribedToBroadcastChannel = true
|
|
560
|
+
// }
|
|
561
|
+
//
|
|
562
|
+
// this.mux(() => {
|
|
563
|
+
// this.broadcast(SyncStepOneMessage, { document: this.document, documentName: this.configuration.name })
|
|
564
|
+
// this.broadcast(SyncStepTwoMessage, { document: this.document, documentName: this.configuration.name })
|
|
565
|
+
// this.broadcast(QueryAwarenessMessage, { document: this.document, documentName: this.configuration.name })
|
|
566
|
+
// if (this.awareness) {
|
|
567
|
+
// this.broadcast(AwarenessMessage, {
|
|
568
|
+
// awareness: this.awareness,
|
|
569
|
+
// clients: [this.document.clientID],
|
|
570
|
+
// document: this.document,
|
|
571
|
+
// documentName: this.configuration.name,
|
|
572
|
+
// })
|
|
573
|
+
// }
|
|
574
|
+
// })
|
|
575
|
+
// }
|
|
576
|
+
//
|
|
577
|
+
// disconnectBroadcastChannel() {
|
|
578
|
+
// // broadcast message with local awareness state set to null (indicating disconnect)
|
|
579
|
+
// if (this.awareness) {
|
|
580
|
+
// this.send(AwarenessMessage, {
|
|
581
|
+
// awareness: this.awareness,
|
|
582
|
+
// clients: [this.document.clientID],
|
|
583
|
+
// states: new Map(),
|
|
584
|
+
// documentName: this.configuration.name,
|
|
585
|
+
// }, true)
|
|
586
|
+
// }
|
|
587
|
+
//
|
|
588
|
+
// if (this.subscribedToBroadcastChannel) {
|
|
589
|
+
// bc.unsubscribe(this.broadcastChannel, this.boundBroadcastChannelSubscriber)
|
|
590
|
+
// this.subscribedToBroadcastChannel = false
|
|
591
|
+
// }
|
|
592
|
+
// }
|
|
593
|
+
|
|
594
|
+
// broadcast(Message: ConstructableOutgoingMessage, args?: any) {
|
|
595
|
+
// if (!this.configuration.broadcast) {
|
|
596
|
+
// return
|
|
597
|
+
// }
|
|
598
|
+
//
|
|
599
|
+
// if (!this.subscribedToBroadcastChannel) {
|
|
600
|
+
// return
|
|
601
|
+
// }
|
|
602
|
+
//
|
|
603
|
+
// new MessageSender(Message, args).broadcast(this.broadcastChannel)
|
|
604
|
+
// }
|
|
605
605
|
|
|
606
606
|
setAwarenessField(key: string, value: any) {
|
|
607
607
|
if (!this.awareness) {
|
|
@@ -4,14 +4,14 @@ import {
|
|
|
4
4
|
import { retry } from '@lifeomic/attempt'
|
|
5
5
|
import * as time from 'lib0/time'
|
|
6
6
|
import * as url from 'lib0/url'
|
|
7
|
-
import type { MessageEvent } from 'ws'
|
|
8
|
-
import { Event } from 'ws'
|
|
7
|
+
import type { MessageEvent , Event } from 'ws'
|
|
9
8
|
import EventEmitter from './EventEmitter.js'
|
|
10
|
-
import { HocuspocusProvider } from './HocuspocusProvider.js'
|
|
9
|
+
import type { HocuspocusProvider } from './HocuspocusProvider.js'
|
|
10
|
+
import type {
|
|
11
|
+
onAwarenessChangeParameters, onAwarenessUpdateParameters,
|
|
12
|
+
onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters} from './types.js'
|
|
11
13
|
import {
|
|
12
14
|
WebSocketStatus,
|
|
13
|
-
onAwarenessChangeParameters, onAwarenessUpdateParameters,
|
|
14
|
-
onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters,
|
|
15
15
|
} from './types.js'
|
|
16
16
|
import { IncomingMessage } from './IncomingMessage.js'
|
|
17
17
|
|
|
@@ -228,11 +228,9 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
|
|
|
228
228
|
provider.onOpen(this.receivedOnOpenPayload)
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
if (this.receivedOnStatusPayload) {
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
return connectPromise
|
|
231
|
+
// if (this.receivedOnStatusPayload) {
|
|
232
|
+
// provider.onStatus(this.receivedOnStatusPayload)
|
|
233
|
+
// }
|
|
236
234
|
}
|
|
237
235
|
|
|
238
236
|
detach(provider: HocuspocusProvider) {
|
|
@@ -301,6 +299,7 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
|
|
|
301
299
|
return retryPromise
|
|
302
300
|
}
|
|
303
301
|
|
|
302
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
304
303
|
attachWebSocketListeners(ws: HocusPocusWebSocket, reject: Function) {
|
|
305
304
|
const { identifier } = ws
|
|
306
305
|
const onMessageHandler = (payload: any) => this.emit('message', payload)
|
package/src/IncomingMessage.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Decoder} from 'lib0/decoding'
|
|
1
3
|
import {
|
|
2
4
|
createDecoder,
|
|
3
5
|
peekVarString,
|
|
4
6
|
readVarUint,
|
|
5
7
|
readVarUint8Array,
|
|
6
8
|
readVarString,
|
|
7
|
-
Decoder,
|
|
8
9
|
} from 'lib0/decoding'
|
|
10
|
+
import type {
|
|
11
|
+
Encoder} from 'lib0/encoding'
|
|
9
12
|
import {
|
|
10
|
-
Encoder,
|
|
11
13
|
createEncoder,
|
|
12
14
|
writeVarUint,
|
|
13
15
|
writeVarUint8Array,
|
|
14
16
|
writeVarString,
|
|
15
17
|
length,
|
|
16
18
|
} from 'lib0/encoding'
|
|
17
|
-
import { MessageType } from './types.js'
|
|
19
|
+
import type { MessageType } from './types.js'
|
|
18
20
|
|
|
19
21
|
export class IncomingMessage {
|
|
20
22
|
|
package/src/MessageReceiver.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { readAuthMessage } from '@hocuspocus/common'
|
|
|
2
2
|
import { readVarInt, readVarString } from 'lib0/decoding'
|
|
3
3
|
import * as awarenessProtocol from 'y-protocols/awareness'
|
|
4
4
|
import { messageYjsSyncStep2, readSyncMessage } from 'y-protocols/sync'
|
|
5
|
-
import { HocuspocusProvider } from './HocuspocusProvider.js'
|
|
6
|
-
import { IncomingMessage } from './IncomingMessage.js'
|
|
5
|
+
import type { HocuspocusProvider } from './HocuspocusProvider.js'
|
|
6
|
+
import type { IncomingMessage } from './IncomingMessage.js'
|
|
7
7
|
import { OutgoingMessage } from './OutgoingMessage.js'
|
|
8
8
|
import { MessageType } from './types.js'
|
|
9
9
|
|
package/src/MessageSender.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Encoder
|
|
1
|
+
import type { Encoder} from 'lib0/encoding'
|
|
2
|
+
import { toUint8Array } from 'lib0/encoding'
|
|
2
3
|
import * as bc from 'lib0/broadcastchannel'
|
|
3
|
-
import { ConstructableOutgoingMessage } from './types.js'
|
|
4
|
+
import type { ConstructableOutgoingMessage } from './types.js'
|
|
4
5
|
|
|
5
6
|
export class MessageSender {
|
|
6
7
|
|
package/src/OutgoingMessage.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Encoder
|
|
2
|
-
import {
|
|
1
|
+
import type { Encoder} from 'lib0/encoding'
|
|
2
|
+
import { createEncoder, toUint8Array } from 'lib0/encoding'
|
|
3
|
+
import type { MessageType, OutgoingMessageArguments, OutgoingMessageInterface } from './types.js'
|
|
3
4
|
|
|
4
5
|
export class OutgoingMessage implements OutgoingMessageInterface {
|
|
5
6
|
encoder: Encoder
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { writeVarString, writeVarUint } from 'lib0/encoding'
|
|
2
2
|
import { writeAuthentication } from '@hocuspocus/common'
|
|
3
|
-
import {
|
|
3
|
+
import type { OutgoingMessageArguments } from '../types.js'
|
|
4
|
+
import { MessageType } from '../types.js'
|
|
4
5
|
import { OutgoingMessage } from '../OutgoingMessage.js'
|
|
5
6
|
|
|
6
7
|
export class AuthenticationMessage extends OutgoingMessage {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as encoding from 'lib0/encoding'
|
|
2
2
|
import { encodeAwarenessUpdate } from 'y-protocols/awareness'
|
|
3
|
-
import {
|
|
3
|
+
import type { OutgoingMessageArguments } from '../types.js'
|
|
4
|
+
import { MessageType } from '../types.js'
|
|
4
5
|
import { OutgoingMessage } from '../OutgoingMessage.js'
|
|
5
6
|
|
|
6
7
|
export class AwarenessMessage extends OutgoingMessage {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as encoding from 'lib0/encoding'
|
|
2
|
-
import {
|
|
2
|
+
import type { OutgoingMessageArguments } from '../types.js'
|
|
3
|
+
import { MessageType } from '../types.js'
|
|
3
4
|
import { OutgoingMessage } from '../OutgoingMessage.js'
|
|
4
5
|
|
|
5
6
|
export class CloseMessage extends OutgoingMessage {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as encoding from 'lib0/encoding'
|
|
2
|
-
import {
|
|
2
|
+
import type { OutgoingMessageArguments } from '../types.js'
|
|
3
|
+
import { MessageType } from '../types.js'
|
|
3
4
|
import { OutgoingMessage } from '../OutgoingMessage.js'
|
|
4
5
|
|
|
5
6
|
export class QueryAwarenessMessage extends OutgoingMessage {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { writeVarString, writeVarUint } from 'lib0/encoding'
|
|
2
|
-
import {
|
|
2
|
+
import type { OutgoingMessageArguments } from '../types.js'
|
|
3
|
+
import { MessageType } from '../types.js'
|
|
3
4
|
import { OutgoingMessage } from '../OutgoingMessage.js'
|
|
4
5
|
|
|
5
6
|
export class StatelessMessage extends OutgoingMessage {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as encoding from 'lib0/encoding'
|
|
2
2
|
import * as syncProtocol from 'y-protocols/sync'
|
|
3
|
-
import {
|
|
3
|
+
import type { OutgoingMessageArguments } from '../types.js'
|
|
4
|
+
import { MessageType } from '../types.js'
|
|
4
5
|
import { OutgoingMessage } from '../OutgoingMessage.js'
|
|
5
6
|
|
|
6
7
|
export class SyncStepOneMessage extends OutgoingMessage {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as encoding from 'lib0/encoding'
|
|
2
2
|
import * as syncProtocol from 'y-protocols/sync'
|
|
3
|
-
import {
|
|
3
|
+
import type { OutgoingMessageArguments } from '../types.js'
|
|
4
|
+
import { MessageType } from '../types.js'
|
|
4
5
|
import { OutgoingMessage } from '../OutgoingMessage.js'
|
|
5
6
|
|
|
6
7
|
export class SyncStepTwoMessage extends OutgoingMessage {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { writeVarString, writeVarUint } from 'lib0/encoding'
|
|
2
2
|
import { writeUpdate } from 'y-protocols/sync'
|
|
3
|
-
import {
|
|
3
|
+
import type { OutgoingMessageArguments } from '../types.js'
|
|
4
|
+
import { MessageType } from '../types.js'
|
|
4
5
|
import { OutgoingMessage } from '../OutgoingMessage.js'
|
|
5
6
|
|
|
6
7
|
export class UpdateMessage extends OutgoingMessage {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { AbstractType, YArrayEvent } from 'yjs'
|
|
2
2
|
import * as Y from 'yjs'
|
|
3
3
|
import { uuidv4 } from 'lib0/random'
|
|
4
|
+
import type {
|
|
5
|
+
HocuspocusProviderConfiguration} from './HocuspocusProvider.js'
|
|
4
6
|
import {
|
|
5
7
|
HocuspocusProvider,
|
|
6
|
-
HocuspocusProviderConfiguration,
|
|
7
8
|
} from './HocuspocusProvider.js'
|
|
8
9
|
|
|
9
10
|
import { TiptapCollabProviderWebsocket } from './TiptapCollabProviderWebsocket.js'
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CompleteHocuspocusProviderWebsocketConfiguration, HocuspocusProviderWebsocketConfiguration} from './HocuspocusProviderWebsocket.js'
|
|
1
3
|
import {
|
|
2
|
-
|
|
3
|
-
HocuspocusProviderWebsocket, HocuspocusProviderWebsocketConfiguration,
|
|
4
|
+
HocuspocusProviderWebsocket,
|
|
4
5
|
} from './HocuspocusProviderWebsocket.js'
|
|
5
6
|
|
|
6
7
|
export type TiptapCollabProviderWebsocketConfiguration =
|
package/src/types.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Encoder } from 'lib0/encoding'
|
|
1
|
+
import type { Encoder } from 'lib0/encoding'
|
|
2
2
|
import type { Event, MessageEvent } from 'ws'
|
|
3
|
-
import { Awareness } from 'y-protocols/awareness'
|
|
4
|
-
import * as Y from 'yjs'
|
|
5
|
-
import { CloseEvent } from '@hocuspocus/common'
|
|
6
|
-
import { IncomingMessage } from './IncomingMessage.js'
|
|
7
|
-
import { OutgoingMessage } from './OutgoingMessage.js'
|
|
8
|
-
import { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage.js'
|
|
9
|
-
import { AwarenessMessage } from './OutgoingMessages/AwarenessMessage.js'
|
|
10
|
-
import { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage.js'
|
|
11
|
-
import { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage.js'
|
|
12
|
-
import { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage.js'
|
|
13
|
-
import { UpdateMessage } from './OutgoingMessages/UpdateMessage.js'
|
|
3
|
+
import type { Awareness } from 'y-protocols/awareness'
|
|
4
|
+
import type * as Y from 'yjs'
|
|
5
|
+
import type { CloseEvent } from '@hocuspocus/common'
|
|
6
|
+
import type { IncomingMessage } from './IncomingMessage.js'
|
|
7
|
+
import type { OutgoingMessage } from './OutgoingMessage.js'
|
|
8
|
+
import type { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage.js'
|
|
9
|
+
import type { AwarenessMessage } from './OutgoingMessages/AwarenessMessage.js'
|
|
10
|
+
import type { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage.js'
|
|
11
|
+
import type { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage.js'
|
|
12
|
+
import type { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage.js'
|
|
13
|
+
import type { UpdateMessage } from './OutgoingMessages/UpdateMessage.js'
|
|
14
14
|
|
|
15
15
|
export enum MessageType {
|
|
16
16
|
Sync = 0,
|