@hocuspocus/provider 3.4.3 → 3.4.5-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 +1836 -2083
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +1803 -2060
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/index.d.ts +558 -0
- package/dist/index.js +1940 -0
- package/package.json +4 -4
- package/src/HocuspocusProvider.ts +16 -9
- package/src/HocuspocusProviderWebsocket.ts +16 -4
- package/src/MessageReceiver.ts +2 -2
- package/src/types.ts +3 -1
- package/dist/node_modules/@tiptap/pm/model/index.d.ts +0 -1
- package/dist/node_modules/@tiptap/pm/state/index.d.ts +0 -1
- package/dist/node_modules/@tiptap/pm/transform/index.d.ts +0 -1
- package/dist/node_modules/@tiptap/pm/view/index.d.ts +0 -1
- package/dist/packages/common/src/CloseEvents.d.ts +0 -29
- package/dist/packages/common/src/auth.d.ts +0 -12
- package/dist/packages/common/src/awarenessStatesToArray.d.ts +0 -3
- package/dist/packages/common/src/index.d.ts +0 -4
- package/dist/packages/common/src/types.d.ts +0 -10
- package/dist/packages/extension-database/src/Database.d.ts +0 -30
- package/dist/packages/extension-database/src/index.d.ts +0 -1
- package/dist/packages/extension-logger/src/Logger.d.ts +0 -67
- package/dist/packages/extension-logger/src/index.d.ts +0 -1
- package/dist/packages/extension-redis/src/Redis.d.ts +0 -124
- package/dist/packages/extension-redis/src/index.d.ts +0 -1
- package/dist/packages/extension-s3/src/S3.d.ts +0 -44
- package/dist/packages/extension-s3/src/index.d.ts +0 -1
- package/dist/packages/extension-sqlite/src/SQLite.d.ts +0 -27
- package/dist/packages/extension-sqlite/src/index.d.ts +0 -1
- package/dist/packages/extension-throttle/src/index.d.ts +0 -30
- package/dist/packages/extension-webhook/src/index.d.ts +0 -56
- package/dist/packages/provider/src/EventEmitter.d.ts +0 -9
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +0 -116
- package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +0 -114
- package/dist/packages/provider/src/IncomingMessage.d.ts +0 -17
- package/dist/packages/provider/src/MessageReceiver.d.ts +0 -12
- package/dist/packages/provider/src/MessageSender.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessage.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +0 -8
- package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +0 -8
- package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +0 -8
- package/dist/packages/provider/src/index.d.ts +0 -3
- package/dist/packages/provider/src/types.d.ts +0 -92
- package/dist/packages/server/src/ClientConnection.d.ts +0 -63
- package/dist/packages/server/src/Connection.d.ts +0 -71
- package/dist/packages/server/src/DirectConnection.d.ts +0 -14
- package/dist/packages/server/src/Document.d.ts +0 -92
- package/dist/packages/server/src/Hocuspocus.d.ts +0 -80
- package/dist/packages/server/src/IncomingMessage.d.ts +0 -25
- package/dist/packages/server/src/MessageReceiver.d.ts +0 -11
- package/dist/packages/server/src/OutgoingMessage.d.ts +0 -23
- package/dist/packages/server/src/Server.d.ts +0 -32
- package/dist/packages/server/src/index.d.ts +0 -9
- package/dist/packages/server/src/types.d.ts +0 -342
- package/dist/packages/server/src/util/debounce.d.ts +0 -6
- package/dist/packages/server/src/util/getParameters.d.ts +0 -6
- package/dist/packages/transformer/src/Prosemirror.d.ts +0 -11
- package/dist/packages/transformer/src/Tiptap.d.ts +0 -10
- package/dist/packages/transformer/src/index.d.ts +0 -3
- package/dist/packages/transformer/src/types.d.ts +0 -5
- package/dist/playground/backend/src/default.d.ts +0 -1
- package/dist/playground/backend/src/deno.d.ts +0 -1
- package/dist/playground/backend/src/express.d.ts +0 -1
- package/dist/playground/backend/src/hono.d.ts +0 -1
- package/dist/playground/backend/src/koa.d.ts +0 -1
- package/dist/playground/backend/src/load-document.d.ts +0 -1
- package/dist/playground/backend/src/redis.d.ts +0 -1
- package/dist/playground/backend/src/s3-redis.d.ts +0 -1
- package/dist/playground/backend/src/s3.d.ts +0 -1
- package/dist/playground/backend/src/slow.d.ts +0 -1
- package/dist/playground/backend/src/tiptapcollab.d.ts +0 -1
- package/dist/playground/backend/src/webhook.d.ts +0 -1
- package/dist/playground/frontend/app/SocketContext1.d.ts +0 -2
- package/dist/playground/frontend/app/SocketContext2.d.ts +0 -2
- package/dist/playground/frontend/next.config.d.ts +0 -3
- package/dist/tests/extension-database/fetch.d.ts +0 -1
- package/dist/tests/extension-logger/onListen.d.ts +0 -1
- package/dist/tests/extension-redis/onAwarenessChange.d.ts +0 -1
- package/dist/tests/extension-redis/onChange.d.ts +0 -1
- package/dist/tests/extension-redis/onStateless.d.ts +0 -1
- package/dist/tests/extension-redis/onStoreDocument.d.ts +0 -1
- package/dist/tests/extension-s3/fetch.d.ts +0 -1
- package/dist/tests/extension-throttle/banning.d.ts +0 -1
- package/dist/tests/extension-throttle/configuration.d.ts +0 -1
- package/dist/tests/provider/hasUnsyncedChanges.d.ts +0 -1
- package/dist/tests/provider/observe.d.ts +0 -1
- package/dist/tests/provider/observeDeep.d.ts +0 -1
- package/dist/tests/provider/onAuthenticated.d.ts +0 -1
- package/dist/tests/provider/onAuthenticationFailed.d.ts +0 -1
- package/dist/tests/provider/onAwarenessChange.d.ts +0 -1
- package/dist/tests/provider/onAwarenessUpdate.d.ts +0 -1
- package/dist/tests/provider/onClose.d.ts +0 -1
- package/dist/tests/provider/onConnect.d.ts +0 -1
- package/dist/tests/provider/onDisconnect.d.ts +0 -1
- package/dist/tests/provider/onMessage.d.ts +0 -1
- package/dist/tests/provider/onOpen.d.ts +0 -1
- package/dist/tests/provider/onStateless.d.ts +0 -1
- package/dist/tests/provider/onSynced.d.ts +0 -1
- package/dist/tests/providerwebsocket/configuration.d.ts +0 -1
- package/dist/tests/server/address.d.ts +0 -1
- package/dist/tests/server/afterLoadDocument.d.ts +0 -1
- package/dist/tests/server/afterStoreDocument.d.ts +0 -1
- package/dist/tests/server/afterUnloadDocument.d.ts +0 -1
- package/dist/tests/server/beforeBroadcastStateless.d.ts +0 -1
- package/dist/tests/server/beforeHandleMessage.d.ts +0 -1
- package/dist/tests/server/beforeSync.d.ts +0 -1
- package/dist/tests/server/beforeUnloadDocument.d.ts +0 -1
- package/dist/tests/server/closeConnections.d.ts +0 -1
- package/dist/tests/server/getConnectionsCount.d.ts +0 -1
- package/dist/tests/server/getDocumentsCount.d.ts +0 -1
- package/dist/tests/server/listen.d.ts +0 -1
- package/dist/tests/server/onAuthenticate.d.ts +0 -1
- package/dist/tests/server/onAwarenessUpdate.d.ts +0 -1
- package/dist/tests/server/onChange.d.ts +0 -1
- package/dist/tests/server/onClose.d.ts +0 -1
- package/dist/tests/server/onConfigure.d.ts +0 -1
- package/dist/tests/server/onConnect.d.ts +0 -1
- package/dist/tests/server/onDestroy.d.ts +0 -1
- package/dist/tests/server/onDisconnect.d.ts +0 -1
- package/dist/tests/server/onListen.d.ts +0 -1
- package/dist/tests/server/onLoadDocument.d.ts +0 -1
- package/dist/tests/server/onRequest.d.ts +0 -1
- package/dist/tests/server/onStateless.d.ts +0 -1
- package/dist/tests/server/onStoreDocument.d.ts +0 -1
- package/dist/tests/server/onTokenSync.d.ts +0 -1
- package/dist/tests/server/onUpgrade.d.ts +0 -1
- package/dist/tests/server/openDirectConnection.d.ts +0 -1
- package/dist/tests/server/websocketError.d.ts +0 -1
- package/dist/tests/transformer/TiptapTransformer.d.ts +0 -1
- package/dist/tests/utils/createDirectory.d.ts +0 -1
- package/dist/tests/utils/flushRedis.d.ts +0 -1
- package/dist/tests/utils/index.d.ts +0 -9
- package/dist/tests/utils/newHocuspocus.d.ts +0 -2
- package/dist/tests/utils/newHocuspocusProvider.d.ts +0 -3
- package/dist/tests/utils/newHocuspocusProviderWebsocket.d.ts +0 -4
- package/dist/tests/utils/randomInteger.d.ts +0 -1
- package/dist/tests/utils/redisConnectionSettings.d.ts +0 -4
- package/dist/tests/utils/removeDirectory.d.ts +0 -1
- package/dist/tests/utils/retryableAssertion.d.ts +0 -2
- package/dist/tests/utils/sleep.d.ts +0 -1
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import type { Event, MessageEvent } from "ws";
|
|
2
|
-
import { Awareness } from "y-protocols/awareness";
|
|
3
|
-
import * as Y from "yjs";
|
|
4
|
-
import EventEmitter from "./EventEmitter.ts";
|
|
5
|
-
import type { CompleteHocuspocusProviderWebsocketConfiguration } from "./HocuspocusProviderWebsocket.ts";
|
|
6
|
-
import { HocuspocusProviderWebsocket } from "./HocuspocusProviderWebsocket.ts";
|
|
7
|
-
import type { ConstructableOutgoingMessage, onAuthenticatedParameters, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSyncedParameters, onUnsyncedChangesParameters } from "./types.ts";
|
|
8
|
-
export type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, "name">> & Partial<CompleteHocuspocusProviderConfiguration> & (Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, "url">> | Required<Pick<CompleteHocuspocusProviderConfiguration, "websocketProvider">>);
|
|
9
|
-
export interface CompleteHocuspocusProviderConfiguration {
|
|
10
|
-
/**
|
|
11
|
-
* The identifier/name of your document
|
|
12
|
-
*/
|
|
13
|
-
name: string;
|
|
14
|
-
/**
|
|
15
|
-
* The actual Y.js document
|
|
16
|
-
*/
|
|
17
|
-
document: Y.Doc;
|
|
18
|
-
/**
|
|
19
|
-
* An Awareness instance to keep the presence state of all clients.
|
|
20
|
-
*
|
|
21
|
-
* You can disable sharing awareness information by passing `null`.
|
|
22
|
-
* Note that having no awareness information shared across all connections will break our ping checks
|
|
23
|
-
* and thus trigger reconnects. You should always have at least one Provider with enabled awareness per
|
|
24
|
-
* socket connection, or ensure that the Provider receives messages before running into `HocuspocusProviderWebsocket.messageReconnectTimeout`.
|
|
25
|
-
*/
|
|
26
|
-
awareness: Awareness | null;
|
|
27
|
-
/**
|
|
28
|
-
* A token that’s sent to the backend for authentication purposes.
|
|
29
|
-
*/
|
|
30
|
-
token: string | (() => string) | (() => Promise<string>) | null;
|
|
31
|
-
/**
|
|
32
|
-
* Hocuspocus websocket provider
|
|
33
|
-
*/
|
|
34
|
-
websocketProvider: HocuspocusProviderWebsocket;
|
|
35
|
-
/**
|
|
36
|
-
* Force syncing the document in the defined interval.
|
|
37
|
-
*/
|
|
38
|
-
forceSyncInterval: false | number;
|
|
39
|
-
onAuthenticated: (data: onAuthenticatedParameters) => void;
|
|
40
|
-
onAuthenticationFailed: (data: onAuthenticationFailedParameters) => void;
|
|
41
|
-
onOpen: (data: onOpenParameters) => void;
|
|
42
|
-
onConnect: () => void;
|
|
43
|
-
onStatus: (data: onStatusParameters) => void;
|
|
44
|
-
onMessage: (data: onMessageParameters) => void;
|
|
45
|
-
onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
|
|
46
|
-
onSynced: (data: onSyncedParameters) => void;
|
|
47
|
-
onDisconnect: (data: onDisconnectParameters) => void;
|
|
48
|
-
onClose: (data: onCloseParameters) => void;
|
|
49
|
-
onDestroy: () => void;
|
|
50
|
-
onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
|
|
51
|
-
onAwarenessChange: (data: onAwarenessChangeParameters) => void;
|
|
52
|
-
onStateless: (data: onStatelessParameters) => void;
|
|
53
|
-
onUnsyncedChanges: (data: onUnsyncedChangesParameters) => void;
|
|
54
|
-
}
|
|
55
|
-
export declare class AwarenessError extends Error {
|
|
56
|
-
code: number;
|
|
57
|
-
}
|
|
58
|
-
export declare class HocuspocusProvider extends EventEmitter {
|
|
59
|
-
configuration: CompleteHocuspocusProviderConfiguration;
|
|
60
|
-
isSynced: boolean;
|
|
61
|
-
unsyncedChanges: number;
|
|
62
|
-
isAuthenticated: boolean;
|
|
63
|
-
authorizedScope: string | undefined;
|
|
64
|
-
manageSocket: boolean;
|
|
65
|
-
private _isAttached;
|
|
66
|
-
intervals: any;
|
|
67
|
-
constructor(configuration: HocuspocusProviderConfiguration);
|
|
68
|
-
boundDocumentUpdateHandler: (update: Uint8Array, origin: any) => void;
|
|
69
|
-
boundAwarenessUpdateHandler: ({ added, updated, removed }: any, origin: any) => void;
|
|
70
|
-
boundPageHide: () => void;
|
|
71
|
-
boundOnOpen: (event: Event) => Promise<void>;
|
|
72
|
-
boundOnClose: () => void;
|
|
73
|
-
forwardConnect: () => this;
|
|
74
|
-
forwardStatus: (e: onStatusParameters) => this;
|
|
75
|
-
forwardClose: (e: onCloseParameters) => this;
|
|
76
|
-
forwardDisconnect: (e: onDisconnectParameters) => this;
|
|
77
|
-
forwardDestroy: () => this;
|
|
78
|
-
setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void;
|
|
79
|
-
get document(): Y.Doc;
|
|
80
|
-
get isAttached(): boolean;
|
|
81
|
-
get awareness(): Awareness | null;
|
|
82
|
-
get hasUnsyncedChanges(): boolean;
|
|
83
|
-
private resetUnsyncedChanges;
|
|
84
|
-
incrementUnsyncedChanges(): void;
|
|
85
|
-
decrementUnsyncedChanges(): void;
|
|
86
|
-
forceSync(): void;
|
|
87
|
-
pageHide(): void;
|
|
88
|
-
registerEventListeners(): void;
|
|
89
|
-
sendStateless(payload: string): void;
|
|
90
|
-
sendToken(): Promise<void>;
|
|
91
|
-
documentUpdateHandler(update: Uint8Array, origin: any): void;
|
|
92
|
-
awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
|
|
93
|
-
/**
|
|
94
|
-
* Indicates whether a first handshake with the server has been established
|
|
95
|
-
*
|
|
96
|
-
* Note: this does not mean all updates from the client have been persisted to the backend. For this,
|
|
97
|
-
* use `hasUnsyncedChanges`.
|
|
98
|
-
*/
|
|
99
|
-
get synced(): boolean;
|
|
100
|
-
set synced(state: boolean);
|
|
101
|
-
receiveStateless(payload: string): void;
|
|
102
|
-
connect(): Promise<unknown>;
|
|
103
|
-
disconnect(): void;
|
|
104
|
-
onOpen(event: Event): Promise<void>;
|
|
105
|
-
getToken(): Promise<string | null>;
|
|
106
|
-
startSync(): void;
|
|
107
|
-
send(message: ConstructableOutgoingMessage, args: any): void;
|
|
108
|
-
onMessage(event: MessageEvent): void;
|
|
109
|
-
onClose(): void;
|
|
110
|
-
destroy(): void;
|
|
111
|
-
detach(): void;
|
|
112
|
-
attach(): void;
|
|
113
|
-
permissionDeniedHandler(reason: string): void;
|
|
114
|
-
authenticatedHandler(scope: string): void;
|
|
115
|
-
setAwarenessField(key: string, value: any): void;
|
|
116
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import type { Event, MessageEvent } from "ws";
|
|
2
|
-
import EventEmitter from "./EventEmitter.ts";
|
|
3
|
-
import type { HocuspocusProvider } from "./HocuspocusProvider.ts";
|
|
4
|
-
import { WebSocketStatus, type onAwarenessChangeParameters, type onAwarenessUpdateParameters, type onCloseParameters, type onDisconnectParameters, type onMessageParameters, type onOpenParameters, type onOutgoingMessageParameters, type onStatusParameters } from "./types.ts";
|
|
5
|
-
export type HocuspocusWebSocket = WebSocket & {
|
|
6
|
-
identifier: string;
|
|
7
|
-
};
|
|
8
|
-
export type HocusPocusWebSocket = HocuspocusWebSocket;
|
|
9
|
-
export type HocuspocusProviderWebsocketConfiguration = Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, "url">> & Partial<CompleteHocuspocusProviderWebsocketConfiguration>;
|
|
10
|
-
export interface CompleteHocuspocusProviderWebsocketConfiguration {
|
|
11
|
-
/**
|
|
12
|
-
* Whether to connect automatically when creating the provider instance. Default=true
|
|
13
|
-
*/
|
|
14
|
-
autoConnect: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* URL of your @hocuspocus/server instance
|
|
17
|
-
*/
|
|
18
|
-
url: string;
|
|
19
|
-
/**
|
|
20
|
-
* An optional WebSocket polyfill, for example for Node.js
|
|
21
|
-
*/
|
|
22
|
-
WebSocketPolyfill: any;
|
|
23
|
-
/**
|
|
24
|
-
* Disconnect when no message is received for the defined amount of milliseconds.
|
|
25
|
-
*/
|
|
26
|
-
messageReconnectTimeout: number;
|
|
27
|
-
/**
|
|
28
|
-
* The delay between each attempt in milliseconds. You can provide a factor to have the delay grow exponentially.
|
|
29
|
-
*/
|
|
30
|
-
delay: number;
|
|
31
|
-
/**
|
|
32
|
-
* The initialDelay is the amount of time to wait before making the first attempt. This option should typically be 0 since you typically want the first attempt to happen immediately.
|
|
33
|
-
*/
|
|
34
|
-
initialDelay: number;
|
|
35
|
-
/**
|
|
36
|
-
* The factor option is used to grow the delay exponentially.
|
|
37
|
-
*/
|
|
38
|
-
factor: number;
|
|
39
|
-
/**
|
|
40
|
-
* The maximum number of attempts or 0 if there is no limit on number of attempts.
|
|
41
|
-
*/
|
|
42
|
-
maxAttempts: number;
|
|
43
|
-
/**
|
|
44
|
-
* minDelay is used to set a lower bound of delay when jitter is enabled. This property has no effect if jitter is disabled.
|
|
45
|
-
*/
|
|
46
|
-
minDelay: number;
|
|
47
|
-
/**
|
|
48
|
-
* The maxDelay option is used to set an upper bound for the delay when factor is enabled. A value of 0 can be provided if there should be no upper bound when calculating delay.
|
|
49
|
-
*/
|
|
50
|
-
maxDelay: number;
|
|
51
|
-
/**
|
|
52
|
-
* If jitter is true then the calculated delay will be a random integer value between minDelay and the calculated delay for the current iteration.
|
|
53
|
-
*/
|
|
54
|
-
jitter: boolean;
|
|
55
|
-
/**
|
|
56
|
-
* A timeout in milliseconds. If timeout is non-zero then a timer is set using setTimeout. If the timeout is triggered then future attempts will be aborted.
|
|
57
|
-
*/
|
|
58
|
-
timeout: number;
|
|
59
|
-
handleTimeout: (() => Promise<unknown>) | null;
|
|
60
|
-
onOpen: (data: onOpenParameters) => void;
|
|
61
|
-
onConnect: () => void;
|
|
62
|
-
onMessage: (data: onMessageParameters) => void;
|
|
63
|
-
onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
|
|
64
|
-
onStatus: (data: onStatusParameters) => void;
|
|
65
|
-
onDisconnect: (data: onDisconnectParameters) => void;
|
|
66
|
-
onClose: (data: onCloseParameters) => void;
|
|
67
|
-
onDestroy: () => void;
|
|
68
|
-
onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
|
|
69
|
-
onAwarenessChange: (data: onAwarenessChangeParameters) => void;
|
|
70
|
-
/**
|
|
71
|
-
* Map of attached providers keyed by documentName.
|
|
72
|
-
*/
|
|
73
|
-
providerMap: Map<string, HocuspocusProvider>;
|
|
74
|
-
}
|
|
75
|
-
export declare class HocuspocusProviderWebsocket extends EventEmitter {
|
|
76
|
-
private messageQueue;
|
|
77
|
-
configuration: CompleteHocuspocusProviderWebsocketConfiguration;
|
|
78
|
-
webSocket: HocusPocusWebSocket | null;
|
|
79
|
-
webSocketHandlers: {
|
|
80
|
-
[key: string]: any;
|
|
81
|
-
};
|
|
82
|
-
shouldConnect: boolean;
|
|
83
|
-
status: WebSocketStatus;
|
|
84
|
-
lastMessageReceived: number;
|
|
85
|
-
identifier: number;
|
|
86
|
-
intervals: any;
|
|
87
|
-
connectionAttempt: {
|
|
88
|
-
resolve: (value?: any) => void;
|
|
89
|
-
reject: (reason?: any) => void;
|
|
90
|
-
} | null;
|
|
91
|
-
constructor(configuration: HocuspocusProviderWebsocketConfiguration);
|
|
92
|
-
receivedOnOpenPayload?: Event | undefined;
|
|
93
|
-
onOpen(event: Event): Promise<void>;
|
|
94
|
-
attach(provider: HocuspocusProvider): void;
|
|
95
|
-
detach(provider: HocuspocusProvider): void;
|
|
96
|
-
setConfiguration(configuration?: Partial<HocuspocusProviderWebsocketConfiguration>): void;
|
|
97
|
-
cancelWebsocketRetry?: () => void;
|
|
98
|
-
connect(): Promise<unknown>;
|
|
99
|
-
attachWebSocketListeners(ws: HocusPocusWebSocket, reject: Function): void;
|
|
100
|
-
cleanupWebSocket(): void;
|
|
101
|
-
createWebSocketConnection(): Promise<unknown>;
|
|
102
|
-
onMessage(event: MessageEvent): void;
|
|
103
|
-
resolveConnectionAttempt(): void;
|
|
104
|
-
stopConnectionAttempt(): void;
|
|
105
|
-
rejectConnectionAttempt(): void;
|
|
106
|
-
closeTries: number;
|
|
107
|
-
checkConnection(): void;
|
|
108
|
-
get serverUrl(): string;
|
|
109
|
-
get url(): string;
|
|
110
|
-
disconnect(): void;
|
|
111
|
-
send(message: any): void;
|
|
112
|
-
onClose({ event }: onCloseParameters): void;
|
|
113
|
-
destroy(): void;
|
|
114
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Decoder } from "lib0/decoding";
|
|
2
|
-
import type { Encoder } from "lib0/encoding";
|
|
3
|
-
import type { MessageType } from "./types.ts";
|
|
4
|
-
export declare class IncomingMessage {
|
|
5
|
-
data: any;
|
|
6
|
-
encoder: Encoder;
|
|
7
|
-
decoder: Decoder;
|
|
8
|
-
constructor(data: any);
|
|
9
|
-
peekVarString(): string;
|
|
10
|
-
readVarUint(): MessageType;
|
|
11
|
-
readVarString(): string;
|
|
12
|
-
readVarUint8Array(): Uint8Array<ArrayBufferLike>;
|
|
13
|
-
writeVarUint(type: MessageType): void;
|
|
14
|
-
writeVarString(string: string): void;
|
|
15
|
-
writeVarUint8Array(data: Uint8Array): void;
|
|
16
|
-
length(): number;
|
|
17
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { HocuspocusProvider } from "./HocuspocusProvider.ts";
|
|
2
|
-
import type { IncomingMessage } from "./IncomingMessage.ts";
|
|
3
|
-
export declare class MessageReceiver {
|
|
4
|
-
message: IncomingMessage;
|
|
5
|
-
constructor(message: IncomingMessage);
|
|
6
|
-
apply(provider: HocuspocusProvider, emitSynced: boolean): void;
|
|
7
|
-
private applySyncMessage;
|
|
8
|
-
applySyncStatusMessage(provider: HocuspocusProvider, applied: boolean): void;
|
|
9
|
-
private applyAwarenessMessage;
|
|
10
|
-
private applyAuthMessage;
|
|
11
|
-
private applyQueryAwarenessMessage;
|
|
12
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Encoder } from "lib0/encoding";
|
|
2
|
-
import type { ConstructableOutgoingMessage } from "./types.ts";
|
|
3
|
-
export declare class MessageSender {
|
|
4
|
-
encoder: Encoder;
|
|
5
|
-
message: any;
|
|
6
|
-
constructor(Message: ConstructableOutgoingMessage, args?: any);
|
|
7
|
-
create(): Uint8Array<ArrayBufferLike>;
|
|
8
|
-
send(webSocket: any): void;
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Encoder } from "lib0/encoding";
|
|
2
|
-
import type { MessageType, OutgoingMessageArguments, OutgoingMessageInterface } from "./types.ts";
|
|
3
|
-
export declare class OutgoingMessage implements OutgoingMessageInterface {
|
|
4
|
-
encoder: Encoder;
|
|
5
|
-
type?: MessageType;
|
|
6
|
-
constructor();
|
|
7
|
-
get(args: Partial<OutgoingMessageArguments>): Encoder | undefined;
|
|
8
|
-
toUint8Array(): Uint8Array<ArrayBufferLike>;
|
|
9
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { OutgoingMessageArguments } from "../types.ts";
|
|
2
|
-
import { MessageType } from "../types.ts";
|
|
3
|
-
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
4
|
-
export declare class AuthenticationMessage extends OutgoingMessage {
|
|
5
|
-
type: MessageType;
|
|
6
|
-
description: string;
|
|
7
|
-
get(args: Partial<OutgoingMessageArguments>): import("lib0/encoding").Encoder;
|
|
8
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as encoding from "lib0/encoding";
|
|
2
|
-
import type { OutgoingMessageArguments } from "../types.ts";
|
|
3
|
-
import { MessageType } from "../types.ts";
|
|
4
|
-
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
5
|
-
export declare class AwarenessMessage extends OutgoingMessage {
|
|
6
|
-
type: MessageType;
|
|
7
|
-
description: string;
|
|
8
|
-
get(args: Partial<OutgoingMessageArguments>): encoding.Encoder;
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as encoding from "lib0/encoding";
|
|
2
|
-
import type { OutgoingMessageArguments } from "../types.ts";
|
|
3
|
-
import { MessageType } from "../types.ts";
|
|
4
|
-
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
5
|
-
export declare class CloseMessage extends OutgoingMessage {
|
|
6
|
-
type: MessageType;
|
|
7
|
-
description: string;
|
|
8
|
-
get(args: Partial<OutgoingMessageArguments>): encoding.Encoder;
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as encoding from "lib0/encoding";
|
|
2
|
-
import type { OutgoingMessageArguments } from "../types.ts";
|
|
3
|
-
import { MessageType } from "../types.ts";
|
|
4
|
-
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
5
|
-
export declare class QueryAwarenessMessage extends OutgoingMessage {
|
|
6
|
-
type: MessageType;
|
|
7
|
-
description: string;
|
|
8
|
-
get(args: Partial<OutgoingMessageArguments>): encoding.Encoder;
|
|
9
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { OutgoingMessageArguments } from "../types.ts";
|
|
2
|
-
import { MessageType } from "../types.ts";
|
|
3
|
-
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
4
|
-
export declare class StatelessMessage extends OutgoingMessage {
|
|
5
|
-
type: MessageType;
|
|
6
|
-
description: string;
|
|
7
|
-
get(args: Partial<OutgoingMessageArguments>): import("lib0/encoding").Encoder;
|
|
8
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as encoding from "lib0/encoding";
|
|
2
|
-
import type { OutgoingMessageArguments } from "../types.ts";
|
|
3
|
-
import { MessageType } from "../types.ts";
|
|
4
|
-
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
5
|
-
export declare class SyncStepOneMessage extends OutgoingMessage {
|
|
6
|
-
type: MessageType;
|
|
7
|
-
description: string;
|
|
8
|
-
get(args: Partial<OutgoingMessageArguments>): encoding.Encoder;
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as encoding from "lib0/encoding";
|
|
2
|
-
import type { OutgoingMessageArguments } from "../types.ts";
|
|
3
|
-
import { MessageType } from "../types.ts";
|
|
4
|
-
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
5
|
-
export declare class SyncStepTwoMessage extends OutgoingMessage {
|
|
6
|
-
type: MessageType;
|
|
7
|
-
description: string;
|
|
8
|
-
get(args: Partial<OutgoingMessageArguments>): encoding.Encoder;
|
|
9
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { OutgoingMessageArguments } from "../types.ts";
|
|
2
|
-
import { MessageType } from "../types.ts";
|
|
3
|
-
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
4
|
-
export declare class UpdateMessage extends OutgoingMessage {
|
|
5
|
-
type: MessageType;
|
|
6
|
-
description: string;
|
|
7
|
-
get(args: Partial<OutgoingMessageArguments>): import("lib0/encoding").Encoder;
|
|
8
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import type { Encoder } from "lib0/encoding";
|
|
2
|
-
import type { Event, MessageEvent } from "ws";
|
|
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.ts";
|
|
7
|
-
import type { OutgoingMessage } from "./OutgoingMessage.ts";
|
|
8
|
-
import type { AuthenticationMessage } from "./OutgoingMessages/AuthenticationMessage.ts";
|
|
9
|
-
import type { AwarenessMessage } from "./OutgoingMessages/AwarenessMessage.ts";
|
|
10
|
-
import type { QueryAwarenessMessage } from "./OutgoingMessages/QueryAwarenessMessage.ts";
|
|
11
|
-
import type { SyncStepOneMessage } from "./OutgoingMessages/SyncStepOneMessage.ts";
|
|
12
|
-
import type { SyncStepTwoMessage } from "./OutgoingMessages/SyncStepTwoMessage.ts";
|
|
13
|
-
import type { UpdateMessage } from "./OutgoingMessages/UpdateMessage.ts";
|
|
14
|
-
export declare enum MessageType {
|
|
15
|
-
Sync = 0,
|
|
16
|
-
Awareness = 1,
|
|
17
|
-
Auth = 2,
|
|
18
|
-
QueryAwareness = 3,
|
|
19
|
-
Stateless = 5,
|
|
20
|
-
CLOSE = 7,
|
|
21
|
-
SyncStatus = 8
|
|
22
|
-
}
|
|
23
|
-
export declare enum WebSocketStatus {
|
|
24
|
-
Connecting = "connecting",
|
|
25
|
-
Connected = "connected",
|
|
26
|
-
Disconnected = "disconnected"
|
|
27
|
-
}
|
|
28
|
-
export interface OutgoingMessageInterface {
|
|
29
|
-
encoder: Encoder;
|
|
30
|
-
type?: MessageType;
|
|
31
|
-
}
|
|
32
|
-
export interface OutgoingMessageArguments {
|
|
33
|
-
documentName: string;
|
|
34
|
-
token: string;
|
|
35
|
-
document: Y.Doc;
|
|
36
|
-
awareness: Awareness;
|
|
37
|
-
clients: number[];
|
|
38
|
-
states: Map<number, {
|
|
39
|
-
[key: string]: any;
|
|
40
|
-
}>;
|
|
41
|
-
update: any;
|
|
42
|
-
payload: string;
|
|
43
|
-
encoder: Encoder;
|
|
44
|
-
}
|
|
45
|
-
export interface Constructable<T> {
|
|
46
|
-
new (...args: any): T;
|
|
47
|
-
}
|
|
48
|
-
export type ConstructableOutgoingMessage = Constructable<AuthenticationMessage> | Constructable<AwarenessMessage> | Constructable<QueryAwarenessMessage> | Constructable<SyncStepOneMessage> | Constructable<SyncStepTwoMessage> | Constructable<UpdateMessage>;
|
|
49
|
-
export type onAuthenticationFailedParameters = {
|
|
50
|
-
reason: string;
|
|
51
|
-
};
|
|
52
|
-
export type onAuthenticatedParameters = {
|
|
53
|
-
scope: "read-write" | "readonly";
|
|
54
|
-
};
|
|
55
|
-
export type onOpenParameters = {
|
|
56
|
-
event: Event;
|
|
57
|
-
};
|
|
58
|
-
export type onMessageParameters = {
|
|
59
|
-
event: MessageEvent;
|
|
60
|
-
message: IncomingMessage;
|
|
61
|
-
};
|
|
62
|
-
export type onOutgoingMessageParameters = {
|
|
63
|
-
message: OutgoingMessage;
|
|
64
|
-
};
|
|
65
|
-
export type onStatusParameters = {
|
|
66
|
-
status: WebSocketStatus;
|
|
67
|
-
};
|
|
68
|
-
export type onSyncedParameters = {
|
|
69
|
-
state: boolean;
|
|
70
|
-
};
|
|
71
|
-
export type onUnsyncedChangesParameters = {
|
|
72
|
-
number: number;
|
|
73
|
-
};
|
|
74
|
-
export type onDisconnectParameters = {
|
|
75
|
-
event: CloseEvent;
|
|
76
|
-
};
|
|
77
|
-
export type onCloseParameters = {
|
|
78
|
-
event: CloseEvent;
|
|
79
|
-
};
|
|
80
|
-
export type onAwarenessUpdateParameters = {
|
|
81
|
-
states: StatesArray;
|
|
82
|
-
};
|
|
83
|
-
export type onAwarenessChangeParameters = {
|
|
84
|
-
states: StatesArray;
|
|
85
|
-
};
|
|
86
|
-
export type onStatelessParameters = {
|
|
87
|
-
payload: string;
|
|
88
|
-
};
|
|
89
|
-
export type StatesArray = {
|
|
90
|
-
clientId: number;
|
|
91
|
-
[key: string | number]: any;
|
|
92
|
-
}[];
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { IncomingMessage } from "node:http";
|
|
2
|
-
import { type CloseEvent } from "@hocuspocus/common";
|
|
3
|
-
import type WebSocket from "ws";
|
|
4
|
-
import type Document from "./Document.ts";
|
|
5
|
-
import type { Hocuspocus } from "./Hocuspocus.ts";
|
|
6
|
-
import type { onDisconnectPayload } from "./types.ts";
|
|
7
|
-
/**
|
|
8
|
-
* The `ClientConnection` class is responsible for handling an incoming WebSocket
|
|
9
|
-
*
|
|
10
|
-
* TODO-refactor:
|
|
11
|
-
* - use event handlers instead of calling hooks directly, hooks should probably be called from Hocuspocus.ts
|
|
12
|
-
*/
|
|
13
|
-
export declare class ClientConnection {
|
|
14
|
-
private readonly websocket;
|
|
15
|
-
private readonly request;
|
|
16
|
-
private readonly documentProvider;
|
|
17
|
-
private readonly hooks;
|
|
18
|
-
private readonly opts;
|
|
19
|
-
private readonly defaultContext;
|
|
20
|
-
private readonly documentConnections;
|
|
21
|
-
private readonly incomingMessageQueue;
|
|
22
|
-
private readonly documentConnectionsEstablished;
|
|
23
|
-
private readonly hookPayloads;
|
|
24
|
-
private readonly callbacks;
|
|
25
|
-
private readonly socketId;
|
|
26
|
-
timeout: number;
|
|
27
|
-
pingInterval: NodeJS.Timeout;
|
|
28
|
-
pongReceived: boolean;
|
|
29
|
-
/**
|
|
30
|
-
* The `ClientConnection` class receives incoming WebSocket connections,
|
|
31
|
-
* runs all hooks:
|
|
32
|
-
*
|
|
33
|
-
* - onConnect for all connections
|
|
34
|
-
* - onAuthenticate only if required
|
|
35
|
-
*
|
|
36
|
-
* … and if nothings fails it’ll fully establish the connection and
|
|
37
|
-
* load the Document then.
|
|
38
|
-
*/
|
|
39
|
-
constructor(websocket: WebSocket, request: IncomingMessage, documentProvider: {
|
|
40
|
-
createDocument: Hocuspocus["createDocument"];
|
|
41
|
-
}, hooks: Hocuspocus["hooks"], opts: {
|
|
42
|
-
timeout: number;
|
|
43
|
-
}, defaultContext?: any);
|
|
44
|
-
private handleWebsocketClose;
|
|
45
|
-
close(event?: CloseEvent): void;
|
|
46
|
-
handlePong: () => void;
|
|
47
|
-
/**
|
|
48
|
-
* Check if pong was received and close the connection otherwise
|
|
49
|
-
* @private
|
|
50
|
-
*/
|
|
51
|
-
private check;
|
|
52
|
-
/**
|
|
53
|
-
* Set a callback that will be triggered when the connection is closed
|
|
54
|
-
*/
|
|
55
|
-
onClose(callback: (document: Document, payload: onDisconnectPayload) => void): ClientConnection;
|
|
56
|
-
/**
|
|
57
|
-
* Create a new connection by the given request and document
|
|
58
|
-
*/
|
|
59
|
-
private createConnection;
|
|
60
|
-
private setUpNewConnection;
|
|
61
|
-
private handleQueueingMessage;
|
|
62
|
-
private messageHandler;
|
|
63
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { IncomingMessage as HTTPIncomingMessage } from "node:http";
|
|
2
|
-
import { type CloseEvent } from "@hocuspocus/common";
|
|
3
|
-
import type WebSocket from "ws";
|
|
4
|
-
import type Document from "./Document.ts";
|
|
5
|
-
import type { beforeSyncPayload, onStatelessPayload, onTokenSyncPayload } from "./types.ts";
|
|
6
|
-
export declare class Connection {
|
|
7
|
-
webSocket: WebSocket;
|
|
8
|
-
context: any;
|
|
9
|
-
document: Document;
|
|
10
|
-
request: HTTPIncomingMessage;
|
|
11
|
-
callbacks: {
|
|
12
|
-
onClose: ((document: Document, event?: CloseEvent) => void)[];
|
|
13
|
-
beforeHandleMessage: (connection: Connection, update: Uint8Array) => Promise<void>;
|
|
14
|
-
beforeSync: (connection: Connection, payload: Pick<beforeSyncPayload, "type" | "payload">) => Promise<void>;
|
|
15
|
-
statelessCallback: (payload: onStatelessPayload) => Promise<void>;
|
|
16
|
-
onTokenSyncCallback: (payload: Partial<onTokenSyncPayload>) => Promise<void>;
|
|
17
|
-
};
|
|
18
|
-
socketId: string;
|
|
19
|
-
readOnly: boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Constructor.
|
|
22
|
-
*/
|
|
23
|
-
constructor(connection: WebSocket, request: HTTPIncomingMessage, document: Document, socketId: string, context: any, readOnly?: boolean);
|
|
24
|
-
/**
|
|
25
|
-
* Set a callback that will be triggered when the connection is closed
|
|
26
|
-
*/
|
|
27
|
-
onClose(callback: (document: Document, event?: CloseEvent) => void): Connection;
|
|
28
|
-
/**
|
|
29
|
-
* Set a callback that will be triggered when an stateless message is received
|
|
30
|
-
*/
|
|
31
|
-
onStatelessCallback(callback: (payload: onStatelessPayload) => Promise<void>): Connection;
|
|
32
|
-
/**
|
|
33
|
-
* Set a callback that will be triggered before an message is handled
|
|
34
|
-
*/
|
|
35
|
-
beforeHandleMessage(callback: (connection: Connection, update: Uint8Array) => Promise<any>): Connection;
|
|
36
|
-
/**
|
|
37
|
-
* Set a callback that will be triggered before a sync message is handled
|
|
38
|
-
*/
|
|
39
|
-
beforeSync(callback: (connection: Connection, payload: Pick<beforeSyncPayload, "type" | "payload">) => Promise<any>): Connection;
|
|
40
|
-
/**
|
|
41
|
-
* Set a callback that will be triggered when on token sync message is received
|
|
42
|
-
*/
|
|
43
|
-
onTokenSyncCallback(callback: (payload: onTokenSyncPayload) => Promise<void>): Connection;
|
|
44
|
-
/**
|
|
45
|
-
* Send the given message
|
|
46
|
-
*/
|
|
47
|
-
send(message: any): void;
|
|
48
|
-
/**
|
|
49
|
-
* Send a stateless message with payload
|
|
50
|
-
*/
|
|
51
|
-
sendStateless(payload: string): void;
|
|
52
|
-
/**
|
|
53
|
-
* Request current token from the client
|
|
54
|
-
*/
|
|
55
|
-
requestToken(): void;
|
|
56
|
-
/**
|
|
57
|
-
* Graceful wrapper around the WebSocket close method.
|
|
58
|
-
*/
|
|
59
|
-
close(event?: CloseEvent): void;
|
|
60
|
-
/**
|
|
61
|
-
* Send the current document awareness to the client, if any
|
|
62
|
-
* @private
|
|
63
|
-
*/
|
|
64
|
-
private sendCurrentAwareness;
|
|
65
|
-
/**
|
|
66
|
-
* Handle an incoming message
|
|
67
|
-
* @public
|
|
68
|
-
*/
|
|
69
|
-
handleMessage(data: Uint8Array): void;
|
|
70
|
-
}
|
|
71
|
-
export default Connection;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type Document from "./Document.ts";
|
|
2
|
-
import type { Hocuspocus } from "./Hocuspocus.ts";
|
|
3
|
-
import type { DirectConnection as DirectConnectionInterface } from "./types.ts";
|
|
4
|
-
export declare class DirectConnection implements DirectConnectionInterface {
|
|
5
|
-
document: Document | null;
|
|
6
|
-
instance: Hocuspocus;
|
|
7
|
-
context: any;
|
|
8
|
-
/**
|
|
9
|
-
* Constructor.
|
|
10
|
-
*/
|
|
11
|
-
constructor(document: Document, instance: Hocuspocus, context?: any);
|
|
12
|
-
transact(transaction: (document: Document) => void): Promise<void>;
|
|
13
|
-
disconnect(): Promise<void>;
|
|
14
|
-
}
|