@hocuspocus/provider 2.2.1 → 2.2.2

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.
@@ -72,6 +72,17 @@ export declare class HocuspocusProvider extends EventEmitter {
72
72
  intervals: any;
73
73
  isConnected: boolean;
74
74
  constructor(configuration: HocuspocusProviderConfiguration);
75
+ boundBroadcastChannelSubscriber: (data: ArrayBuffer) => void;
76
+ boundBeforeUnload: () => void;
77
+ boundOnOpen: (event: Event) => Promise<void>;
78
+ boundOnMessage: (event: MessageEvent) => void;
79
+ boundOnClose: (event: CloseEvent) => void;
80
+ boundOnStatus: ({ status }: onStatusParameters) => void;
81
+ forwardConnect: (e: any) => this;
82
+ forwardOpen: (e: any) => this;
83
+ forwardClose: (e: any) => this;
84
+ forwardDisconnect: (e: any) => this;
85
+ forwardDestroy: (e: any) => this;
75
86
  onStatus({ status }: onStatusParameters): void;
76
87
  setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void;
77
88
  get document(): Y.Doc;
@@ -79,7 +90,6 @@ export declare class HocuspocusProvider extends EventEmitter {
79
90
  get hasUnsyncedChanges(): boolean;
80
91
  updateUnsyncedChanges(unsyncedChanges?: number): void;
81
92
  forceSync(): void;
82
- boundBeforeUnload: () => void;
83
93
  beforeUnload(): void;
84
94
  registerEventListeners(): void;
85
95
  sendStateless(payload: string): void;
@@ -101,7 +111,6 @@ export declare class HocuspocusProvider extends EventEmitter {
101
111
  permissionDeniedHandler(reason: string): void;
102
112
  authenticatedHandler(scope: string): void;
103
113
  get broadcastChannel(): string;
104
- boundBroadcastChannelSubscriber: (data: ArrayBuffer) => void;
105
114
  broadcastChannelSubscriber(data: ArrayBuffer): void;
106
115
  subscribeToBroadcastChannel(): void;
107
116
  disconnectBroadcastChannel(): void;
@@ -1,10 +1,12 @@
1
1
  import { HocuspocusProvider, HocuspocusProviderConfiguration } from './HocuspocusProvider.js';
2
- export type TiptapCollabProviderConfiguration = Required<Pick<HocuspocusProviderConfiguration, 'name'>> & Partial<HocuspocusProviderConfiguration> & AdditionalTiptapCollabProviderConfiguration;
2
+ import { TiptapCollabProviderWebsocket } from './TiptapCollabProviderWebsocket.js';
3
+ export type TiptapCollabProviderConfiguration = Required<Pick<HocuspocusProviderConfiguration, 'name'>> & Partial<HocuspocusProviderConfiguration> & (Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'websocketProvider'>> | Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'appId'>>);
3
4
  export interface AdditionalTiptapCollabProviderConfiguration {
4
5
  /**
5
6
  * A Hocuspocus Cloud App ID, get one here: https://collab.tiptap.dev
6
7
  */
7
- appId: string;
8
+ appId?: string;
9
+ websocketProvider?: TiptapCollabProviderWebsocket;
8
10
  }
9
11
  export declare class TiptapCollabProvider extends HocuspocusProvider {
10
12
  constructor(configuration: TiptapCollabProviderConfiguration);
@@ -1,6 +1,6 @@
1
1
  import Document from './Document.js';
2
2
  import type { Hocuspocus } from './Hocuspocus.js';
3
- import type { DirectConnection as DirectConnectionInterface } from './types';
3
+ import type { DirectConnection as DirectConnectionInterface } from './types.js';
4
4
  export declare class DirectConnection implements DirectConnectionInterface {
5
5
  document: Document | null;
6
6
  instance: Hocuspocus;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hocuspocus/provider",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
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.2.1",
32
+ "@hocuspocus/common": "^2.2.2",
33
33
  "@lifeomic/attempt": "^3.0.2",
34
34
  "lib0": "^0.2.47",
35
35
  "ws": "^7.5.9"
@@ -166,24 +166,24 @@ export class HocuspocusProvider extends EventEmitter {
166
166
  this.on('authenticationFailed', this.configuration.onAuthenticationFailed)
167
167
 
168
168
  this.configuration.websocketProvider.on('connect', this.configuration.onConnect)
169
- this.configuration.websocketProvider.on('connect', (e: Event) => this.emit('connect', e))
169
+ this.configuration.websocketProvider.on('connect', this.forwardConnect)
170
170
 
171
- this.configuration.websocketProvider.on('open', this.onOpen.bind(this))
172
- this.configuration.websocketProvider.on('open', (e: Event) => this.emit('open', e))
171
+ this.configuration.websocketProvider.on('open', this.boundOnOpen)
172
+ this.configuration.websocketProvider.on('open', this.forwardOpen)
173
173
 
174
- this.configuration.websocketProvider.on('message', this.onMessage.bind(this))
174
+ this.configuration.websocketProvider.on('message', this.boundOnMessage)
175
175
 
176
- this.configuration.websocketProvider.on('close', this.onClose.bind(this))
176
+ this.configuration.websocketProvider.on('close', this.boundOnClose)
177
177
  this.configuration.websocketProvider.on('close', this.configuration.onClose)
178
- this.configuration.websocketProvider.on('close', (e: Event) => this.emit('close', e))
178
+ this.configuration.websocketProvider.on('close', this.forwardClose)
179
179
 
180
- this.configuration.websocketProvider.on('status', this.onStatus.bind(this))
180
+ this.configuration.websocketProvider.on('status', this.boundOnStatus)
181
181
 
182
182
  this.configuration.websocketProvider.on('disconnect', this.configuration.onDisconnect)
183
- this.configuration.websocketProvider.on('disconnect', (e: Event) => this.emit('disconnect', e))
183
+ this.configuration.websocketProvider.on('disconnect', this.forwardDisconnect)
184
184
 
185
185
  this.configuration.websocketProvider.on('destroy', this.configuration.onDestroy)
186
- this.configuration.websocketProvider.on('destroy', (e: Event) => this.emit('destroy', e))
186
+ this.configuration.websocketProvider.on('destroy', this.forwardDestroy)
187
187
 
188
188
  this.awareness.on('update', () => {
189
189
  this.emit('awarenessUpdate', { states: awarenessStatesToArray(this.awareness.getStates()) })
@@ -207,6 +207,28 @@ export class HocuspocusProvider extends EventEmitter {
207
207
  this.configuration.websocketProvider.attach(this)
208
208
  }
209
209
 
210
+ boundBroadcastChannelSubscriber = this.broadcastChannelSubscriber.bind(this)
211
+
212
+ boundBeforeUnload = this.beforeUnload.bind(this)
213
+
214
+ boundOnOpen = this.onOpen.bind(this)
215
+
216
+ boundOnMessage = this.onMessage.bind(this)
217
+
218
+ boundOnClose = this.onClose.bind(this)
219
+
220
+ boundOnStatus = this.onStatus.bind(this)
221
+
222
+ forwardConnect = (e: any) => this.emit('connect', e)
223
+
224
+ forwardOpen = (e: any) => this.emit('open', e)
225
+
226
+ forwardClose = (e: any) => this.emit('close', e)
227
+
228
+ forwardDisconnect = (e: any) => this.emit('disconnect', e)
229
+
230
+ forwardDestroy = (e: any) => this.emit('destroy', e)
231
+
210
232
  public onStatus({ status } : onStatusParameters) {
211
233
  this.status = status
212
234
 
@@ -248,8 +270,6 @@ export class HocuspocusProvider extends EventEmitter {
248
270
  this.send(SyncStepOneMessage, { document: this.document, documentName: this.configuration.name })
249
271
  }
250
272
 
251
- boundBeforeUnload = this.beforeUnload.bind(this)
252
-
253
273
  beforeUnload() {
254
274
  removeAwarenessStates(this.awareness, [this.document.clientID], 'window unload')
255
275
  }
@@ -414,6 +434,20 @@ export class HocuspocusProvider extends EventEmitter {
414
434
 
415
435
  this.removeAllListeners()
416
436
 
437
+ this.configuration.websocketProvider.off('connect', this.configuration.onConnect)
438
+ this.configuration.websocketProvider.off('connect', this.forwardConnect)
439
+ this.configuration.websocketProvider.off('open', this.boundOnOpen)
440
+ this.configuration.websocketProvider.off('open', this.forwardOpen)
441
+ this.configuration.websocketProvider.off('message', this.boundOnMessage)
442
+ this.configuration.websocketProvider.off('close', this.boundOnClose)
443
+ this.configuration.websocketProvider.off('close', this.configuration.onClose)
444
+ this.configuration.websocketProvider.off('close', this.forwardClose)
445
+ this.configuration.websocketProvider.off('status', this.boundOnStatus)
446
+ this.configuration.websocketProvider.off('disconnect', this.configuration.onDisconnect)
447
+ this.configuration.websocketProvider.off('disconnect', this.forwardDisconnect)
448
+ this.configuration.websocketProvider.off('destroy', this.configuration.onDestroy)
449
+ this.configuration.websocketProvider.off('destroy', this.forwardDestroy)
450
+
417
451
  this.send(CloseMessage, { documentName: this.configuration.name })
418
452
  this.isConnected = false
419
453
 
@@ -443,8 +477,6 @@ export class HocuspocusProvider extends EventEmitter {
443
477
  return `${this.configuration.name}`
444
478
  }
445
479
 
446
- boundBroadcastChannelSubscriber = this.broadcastChannelSubscriber.bind(this)
447
-
448
480
  broadcastChannelSubscriber(data: ArrayBuffer) {
449
481
  this.mux(() => {
450
482
  const message = new IncomingMessage(data)
@@ -8,19 +8,22 @@ import { TiptapCollabProviderWebsocket } from './TiptapCollabProviderWebsocket.j
8
8
  export type TiptapCollabProviderConfiguration =
9
9
  Required<Pick<HocuspocusProviderConfiguration, 'name'>> &
10
10
  Partial<HocuspocusProviderConfiguration> &
11
- AdditionalTiptapCollabProviderConfiguration
11
+ (Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'websocketProvider'>> |
12
+ Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'appId'>>)
12
13
 
13
14
  export interface AdditionalTiptapCollabProviderConfiguration {
14
15
  /**
15
16
  * A Hocuspocus Cloud App ID, get one here: https://collab.tiptap.dev
16
17
  */
17
- appId: string,
18
+ appId?: string,
19
+
20
+ websocketProvider?: TiptapCollabProviderWebsocket
18
21
  }
19
22
 
20
23
  export class TiptapCollabProvider extends HocuspocusProvider {
21
24
  constructor(configuration: TiptapCollabProviderConfiguration) {
22
25
  if (!configuration.websocketProvider) {
23
- configuration.websocketProvider = new TiptapCollabProviderWebsocket({ appId: configuration.appId })
26
+ configuration.websocketProvider = new TiptapCollabProviderWebsocket({ appId: (configuration as Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'appId'>>).appId })
24
27
  }
25
28
 
26
29
  if (!configuration.token) {