@hocuspocus/provider 2.0.0-alpha.1 → 2.0.0-beta.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 +421 -411
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +422 -412
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/extension-webhook/src/index.d.ts +1 -2
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +3 -2
- package/dist/tests/server/onClose.d.ts +1 -0
- package/package.json +2 -2
- package/src/HocuspocusProvider.ts +18 -3
- package/src/HocuspocusProviderWebsocket.ts +3 -1
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { Extension, onChangePayload, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload } from '@hocuspocus/server';
|
|
3
3
|
import { Doc } from 'yjs';
|
|
4
4
|
import { Transformer } from '@hocuspocus/transformer';
|
|
5
|
-
import { AxiosResponse } from 'axios';
|
|
6
5
|
export declare enum Events {
|
|
7
6
|
onChange = "change",
|
|
8
7
|
onConnect = "connect",
|
|
@@ -41,7 +40,7 @@ export declare class Webhook implements Extension {
|
|
|
41
40
|
/**
|
|
42
41
|
* Send a request to the given url containing the given data
|
|
43
42
|
*/
|
|
44
|
-
sendRequest(event: Events, payload: any): Promise<AxiosResponse<any, any>>;
|
|
43
|
+
sendRequest(event: Events, payload: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
45
44
|
/**
|
|
46
45
|
* onChange hook
|
|
47
46
|
*/
|
|
@@ -4,9 +4,9 @@ import * as mutex from 'lib0/mutex';
|
|
|
4
4
|
import type { CloseEvent, Event, MessageEvent } from 'ws';
|
|
5
5
|
import EventEmitter from './EventEmitter';
|
|
6
6
|
import { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSyncedParameters, WebSocketStatus } from './types';
|
|
7
|
-
import { HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket';
|
|
7
|
+
import { CompleteHocuspocusProviderWebsocketConfiguration, HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket';
|
|
8
8
|
import { onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.';
|
|
9
|
-
export declare type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'name'
|
|
9
|
+
export declare type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'name'>> & Partial<CompleteHocuspocusProviderConfiguration> & (Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, 'url'>> | Required<Pick<CompleteHocuspocusProviderConfiguration, 'websocketProvider'>>);
|
|
10
10
|
export interface CompleteHocuspocusProviderConfiguration {
|
|
11
11
|
/**
|
|
12
12
|
* The identifier/name of your document
|
|
@@ -70,6 +70,7 @@ export declare class HocuspocusProvider extends EventEmitter {
|
|
|
70
70
|
isAuthenticated: boolean;
|
|
71
71
|
mux: mutex.mutex;
|
|
72
72
|
intervals: any;
|
|
73
|
+
isConnected: boolean;
|
|
73
74
|
constructor(configuration: HocuspocusProviderConfiguration);
|
|
74
75
|
onStatus({ status }: onStatusParameters): void;
|
|
75
76
|
setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hocuspocus/provider",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
4
|
"description": "hocuspocus provider",
|
|
5
5
|
"homepage": "https://hocuspocus.dev",
|
|
6
6
|
"keywords": [
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@hocuspocus/common": "^2.0.0-
|
|
31
|
+
"@hocuspocus/common": "^2.0.0-beta.0",
|
|
32
32
|
"@lifeomic/attempt": "^3.0.2",
|
|
33
33
|
"lib0": "^0.2.47",
|
|
34
34
|
"ws": "^7.5.9"
|
|
@@ -26,14 +26,20 @@ import {
|
|
|
26
26
|
onSyncedParameters,
|
|
27
27
|
WebSocketStatus,
|
|
28
28
|
} from './types'
|
|
29
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
CompleteHocuspocusProviderWebsocketConfiguration,
|
|
31
|
+
HocuspocusProviderWebsocket,
|
|
32
|
+
} from './HocuspocusProviderWebsocket'
|
|
30
33
|
import { StatelessMessage } from './OutgoingMessages/StatelessMessage'
|
|
31
34
|
import { CloseMessage } from './OutgoingMessages/CloseMessage'
|
|
32
35
|
import { onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.'
|
|
33
36
|
|
|
34
37
|
export type HocuspocusProviderConfiguration =
|
|
35
|
-
Required<Pick<CompleteHocuspocusProviderConfiguration, 'name'
|
|
36
|
-
|
|
38
|
+
Required<Pick<CompleteHocuspocusProviderConfiguration, 'name'>>
|
|
39
|
+
& Partial<CompleteHocuspocusProviderConfiguration> & (
|
|
40
|
+
Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, 'url'>> |
|
|
41
|
+
Required<Pick<CompleteHocuspocusProviderConfiguration, 'websocketProvider'>>
|
|
42
|
+
)
|
|
37
43
|
|
|
38
44
|
export interface CompleteHocuspocusProviderConfiguration {
|
|
39
45
|
/**
|
|
@@ -135,6 +141,8 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
135
141
|
forceSync: null,
|
|
136
142
|
}
|
|
137
143
|
|
|
144
|
+
isConnected = true
|
|
145
|
+
|
|
138
146
|
constructor(configuration: HocuspocusProviderConfiguration) {
|
|
139
147
|
super()
|
|
140
148
|
this.setConfiguration(configuration)
|
|
@@ -204,6 +212,10 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
204
212
|
}
|
|
205
213
|
|
|
206
214
|
public setConfiguration(configuration: Partial<HocuspocusProviderConfiguration> = {}): void {
|
|
215
|
+
if (!configuration.websocketProvider && (configuration as CompleteHocuspocusProviderWebsocketConfiguration).url) {
|
|
216
|
+
this.configuration.websocketProvider = new HocuspocusProviderWebsocket({ url: (configuration as CompleteHocuspocusProviderWebsocketConfiguration).url })
|
|
217
|
+
}
|
|
218
|
+
|
|
207
219
|
this.configuration = { ...this.configuration, ...configuration }
|
|
208
220
|
}
|
|
209
221
|
|
|
@@ -327,6 +339,8 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
327
339
|
}
|
|
328
340
|
|
|
329
341
|
send(message: ConstructableOutgoingMessage, args: any, broadcast = false) {
|
|
342
|
+
if (!this.isConnected) return
|
|
343
|
+
|
|
330
344
|
if (broadcast) {
|
|
331
345
|
this.mux(() => { this.broadcast(message, args) })
|
|
332
346
|
}
|
|
@@ -382,6 +396,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
382
396
|
this.removeAllListeners()
|
|
383
397
|
|
|
384
398
|
this.send(CloseMessage, { documentName: this.configuration.name })
|
|
399
|
+
this.isConnected = false
|
|
385
400
|
|
|
386
401
|
if (typeof window === 'undefined') {
|
|
387
402
|
return
|
|
@@ -409,8 +409,10 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
|
|
|
409
409
|
}
|
|
410
410
|
|
|
411
411
|
if (event.code === Unauthorized.code) {
|
|
412
|
-
if (
|
|
412
|
+
if (event.reason === Unauthorized.reason) {
|
|
413
413
|
console.warn('[HocuspocusProvider] An authentication token is required, but you didn’t send one. Try adding a `token` to your HocuspocusProvider configuration. Won’t try again.')
|
|
414
|
+
} else {
|
|
415
|
+
console.warn(`[HocuspocusProvider] Connection closed with status Unauthorized: ${event.reason}`)
|
|
414
416
|
}
|
|
415
417
|
|
|
416
418
|
this.shouldConnect = false
|