y-partyserver 2.1.1 → 2.1.3
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/chunk-C0xms8kb.cjs +34 -0
- package/dist/provider/index.cjs +489 -0
- package/dist/provider/index.cjs.map +1 -0
- package/dist/provider/index.d.cts +133 -0
- package/dist/provider/index.js +422 -285
- package/dist/provider/react.cjs +34 -0
- package/dist/provider/react.cjs.map +1 -0
- package/dist/provider/react.d.cts +15 -0
- package/dist/provider/react.js +24 -13
- package/dist/server/index.cjs +366 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +48 -0
- package/dist/server/index.js +329 -227
- package/package.json +23 -11
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import * as decoding from "lib0/decoding";
|
|
2
|
+
import * as encoding from "lib0/encoding";
|
|
3
|
+
import { Observable } from "lib0/observable";
|
|
4
|
+
import * as awarenessProtocol from "y-protocols/awareness";
|
|
5
|
+
import { Doc } from "yjs";
|
|
6
|
+
|
|
7
|
+
//#region src/provider/index.d.ts
|
|
8
|
+
declare const messageSync = 0;
|
|
9
|
+
declare const messageQueryAwareness = 3;
|
|
10
|
+
declare const messageAwareness = 1;
|
|
11
|
+
declare const messageAuth = 2;
|
|
12
|
+
declare const messageHandlers: Array<
|
|
13
|
+
(
|
|
14
|
+
encoder: encoding.Encoder,
|
|
15
|
+
decoder: decoding.Decoder,
|
|
16
|
+
provider: WebsocketProvider,
|
|
17
|
+
emitSynced: boolean,
|
|
18
|
+
messageType: number
|
|
19
|
+
) => void
|
|
20
|
+
>;
|
|
21
|
+
type AwarenessUpdate = {
|
|
22
|
+
added: number[];
|
|
23
|
+
updated: number[];
|
|
24
|
+
removed: number[];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Websocket Provider for Yjs. Creates a websocket connection to sync the shared document.
|
|
28
|
+
* The document name is attached to the provided url. I.e. the following example
|
|
29
|
+
* creates a websocket connection to http://localhost:1234/my-document-name
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* import * as Y from 'yjs'
|
|
33
|
+
* import { WebsocketProvider } from 'y-websocket'
|
|
34
|
+
* const doc = new Y.Doc()
|
|
35
|
+
* const provider = new WebsocketProvider('http://localhost:1234', 'my-document-name', doc)
|
|
36
|
+
*
|
|
37
|
+
* @extends {Observable<string>}
|
|
38
|
+
*/
|
|
39
|
+
declare class WebsocketProvider extends Observable<string> {
|
|
40
|
+
maxBackoffTime: number;
|
|
41
|
+
bcChannel: string;
|
|
42
|
+
url: string;
|
|
43
|
+
roomname: string;
|
|
44
|
+
doc: Doc;
|
|
45
|
+
_WS: typeof WebSocket;
|
|
46
|
+
awareness: awarenessProtocol.Awareness;
|
|
47
|
+
wsconnected: boolean;
|
|
48
|
+
wsconnecting: boolean;
|
|
49
|
+
bcconnected: boolean;
|
|
50
|
+
disableBc: boolean;
|
|
51
|
+
wsUnsuccessfulReconnects: number;
|
|
52
|
+
messageHandlers: typeof messageHandlers;
|
|
53
|
+
_synced: boolean;
|
|
54
|
+
ws: WebSocket | null;
|
|
55
|
+
wsLastMessageReceived: number;
|
|
56
|
+
shouldConnect: boolean;
|
|
57
|
+
_resyncInterval: ReturnType<typeof setInterval> | number;
|
|
58
|
+
_bcSubscriber: (message: Uint8Array, origin: unknown) => void;
|
|
59
|
+
_updateHandler: (update: Uint8Array, origin: unknown) => void;
|
|
60
|
+
_awarenessUpdateHandler: (update: AwarenessUpdate, origin: unknown) => void;
|
|
61
|
+
_unloadHandler: () => void;
|
|
62
|
+
constructor(
|
|
63
|
+
serverUrl: string,
|
|
64
|
+
roomname: string,
|
|
65
|
+
doc: Doc,
|
|
66
|
+
{
|
|
67
|
+
connect,
|
|
68
|
+
awareness,
|
|
69
|
+
params,
|
|
70
|
+
isPrefixedUrl,
|
|
71
|
+
WebSocketPolyfill,
|
|
72
|
+
// Optionally provide a WebSocket polyfill
|
|
73
|
+
resyncInterval,
|
|
74
|
+
// Request server state every `resyncInterval` milliseconds
|
|
75
|
+
maxBackoffTime,
|
|
76
|
+
// Maximum amount of time to wait before trying to reconnect (we try to reconnect using exponential backoff)
|
|
77
|
+
disableBc
|
|
78
|
+
}?: {
|
|
79
|
+
connect?: boolean;
|
|
80
|
+
awareness?: awarenessProtocol.Awareness;
|
|
81
|
+
params?: {
|
|
82
|
+
[s: string]: string;
|
|
83
|
+
};
|
|
84
|
+
isPrefixedUrl?: boolean;
|
|
85
|
+
WebSocketPolyfill?: typeof WebSocket | null;
|
|
86
|
+
resyncInterval?: number;
|
|
87
|
+
maxBackoffTime?: number;
|
|
88
|
+
disableBc?: boolean;
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
/**
|
|
92
|
+
* @type {boolean}
|
|
93
|
+
*/
|
|
94
|
+
get synced(): boolean;
|
|
95
|
+
set synced(state: boolean);
|
|
96
|
+
destroy(): void;
|
|
97
|
+
connectBc(): void;
|
|
98
|
+
disconnectBc(): void;
|
|
99
|
+
disconnect(): void;
|
|
100
|
+
connect(): void;
|
|
101
|
+
}
|
|
102
|
+
type Params = Record<string, string | null | undefined>;
|
|
103
|
+
type ParamsProvider = Params | (() => Params | Promise<Params>);
|
|
104
|
+
type BaseProviderOptions = ConstructorParameters<typeof WebsocketProvider>[3];
|
|
105
|
+
type YProviderOptions = Omit<NonNullable<BaseProviderOptions>, "params"> & {
|
|
106
|
+
connectionId?: string;
|
|
107
|
+
party?: string;
|
|
108
|
+
prefix?: string;
|
|
109
|
+
params?: ParamsProvider;
|
|
110
|
+
protocol?: "ws" | "wss";
|
|
111
|
+
};
|
|
112
|
+
declare class YProvider extends WebsocketProvider {
|
|
113
|
+
#private;
|
|
114
|
+
id: string;
|
|
115
|
+
constructor(
|
|
116
|
+
host: string,
|
|
117
|
+
room: string,
|
|
118
|
+
doc?: Doc,
|
|
119
|
+
options?: YProviderOptions
|
|
120
|
+
);
|
|
121
|
+
connect(): Promise<void>;
|
|
122
|
+
sendMessage(message: string): void;
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
export {
|
|
126
|
+
WebsocketProvider,
|
|
127
|
+
YProvider as default,
|
|
128
|
+
messageAuth,
|
|
129
|
+
messageAwareness,
|
|
130
|
+
messageQueryAwareness,
|
|
131
|
+
messageSync
|
|
132
|
+
};
|
|
133
|
+
//# sourceMappingURL=index.d.cts.map
|