@hocuspocus/provider 3.1.2 → 3.1.4
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 +111 -92
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +111 -92
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/common/src/auth.d.ts +2 -2
- package/dist/packages/common/src/index.d.ts +4 -4
- package/dist/packages/extension-database/src/Database.d.ts +1 -1
- package/dist/packages/extension-database/src/index.d.ts +1 -1
- package/dist/packages/extension-logger/src/Logger.d.ts +1 -1
- package/dist/packages/extension-logger/src/index.d.ts +1 -1
- package/dist/packages/extension-redis/src/index.d.ts +1 -1
- package/dist/packages/extension-sqlite/src/SQLite.d.ts +3 -3
- package/dist/packages/extension-sqlite/src/index.d.ts +1 -1
- package/dist/packages/extension-throttle/src/index.d.ts +1 -1
- package/dist/packages/extension-webhook/src/index.d.ts +3 -3
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +10 -10
- 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/OutgoingMessage.d.ts +2 -2
- package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +3 -3
- package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +4 -4
- package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +4 -4
- package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +4 -4
- package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +3 -3
- package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +4 -4
- package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +4 -4
- package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +3 -3
- package/dist/packages/provider/src/index.d.ts +3 -3
- package/dist/packages/provider/src/types.d.ts +14 -14
- package/dist/packages/server/src/ClientConnection.d.ts +17 -17
- package/dist/packages/server/src/Connection.d.ts +6 -6
- package/dist/packages/server/src/DirectConnection.d.ts +3 -3
- package/dist/packages/server/src/Document.d.ts +4 -4
- package/dist/packages/server/src/Hocuspocus.d.ts +8 -8
- package/dist/packages/server/src/IncomingMessage.d.ts +3 -3
- package/dist/packages/server/src/MessageReceiver.d.ts +3 -3
- package/dist/packages/server/src/OutgoingMessage.d.ts +3 -3
- package/dist/packages/server/src/Server.d.ts +5 -5
- package/dist/packages/server/src/index.d.ts +9 -9
- package/dist/packages/server/src/types.d.ts +7 -7
- package/dist/packages/server/src/util/getParameters.d.ts +5 -5
- package/dist/packages/transformer/src/Prosemirror.d.ts +3 -3
- package/dist/packages/transformer/src/Tiptap.d.ts +3 -3
- package/dist/packages/transformer/src/index.d.ts +3 -3
- package/dist/packages/transformer/src/types.d.ts +1 -1
- package/dist/playground/frontend/app/SocketContext1.d.ts +2 -0
- package/dist/playground/frontend/app/SocketContext2.d.ts +2 -0
- package/package.json +40 -40
- package/src/EventEmitter.ts +32 -32
- package/src/HocuspocusProvider.ts +566 -498
- package/src/IncomingMessage.ts +47 -50
- package/src/MessageReceiver.ts +135 -132
- package/src/OutgoingMessage.ts +18 -14
- package/src/OutgoingMessages/AuthenticationMessage.ts +18 -16
- package/src/OutgoingMessages/AwarenessMessage.ts +38 -32
- package/src/OutgoingMessages/CloseMessage.ts +11 -11
- package/src/OutgoingMessages/QueryAwarenessMessage.ts +11 -12
- package/src/OutgoingMessages/StatelessMessage.ts +12 -12
- package/src/OutgoingMessages/SyncStepOneMessage.ts +18 -16
- package/src/OutgoingMessages/SyncStepTwoMessage.ts +18 -16
- package/src/OutgoingMessages/UpdateMessage.ts +13 -13
- package/src/index.ts +3 -3
- package/src/types.ts +69 -69
- package/dist/playground/frontend/app/SocketContext.d.ts +0 -2
package/src/IncomingMessage.ts
CHANGED
|
@@ -1,66 +1,63 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Decoder} from 'lib0/decoding'
|
|
1
|
+
import type { Decoder } from "lib0/decoding";
|
|
3
2
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from
|
|
10
|
-
import type {
|
|
11
|
-
Encoder} from 'lib0/encoding'
|
|
3
|
+
createDecoder,
|
|
4
|
+
peekVarString,
|
|
5
|
+
readVarUint,
|
|
6
|
+
readVarUint8Array,
|
|
7
|
+
readVarString,
|
|
8
|
+
} from "lib0/decoding";
|
|
9
|
+
import type { Encoder } from "lib0/encoding";
|
|
12
10
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} from
|
|
19
|
-
import type { MessageType } from
|
|
11
|
+
createEncoder,
|
|
12
|
+
writeVarUint,
|
|
13
|
+
writeVarUint8Array,
|
|
14
|
+
writeVarString,
|
|
15
|
+
length,
|
|
16
|
+
} from "lib0/encoding";
|
|
17
|
+
import type { MessageType } from "./types.ts";
|
|
20
18
|
|
|
21
19
|
export class IncomingMessage {
|
|
20
|
+
data: any;
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
encoder: Encoder;
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
decoder: Decoder;
|
|
26
25
|
|
|
27
|
-
|
|
26
|
+
constructor(data: any) {
|
|
27
|
+
this.data = data;
|
|
28
|
+
this.encoder = createEncoder();
|
|
29
|
+
this.decoder = createDecoder(new Uint8Array(this.data));
|
|
30
|
+
}
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
this.decoder = createDecoder(new Uint8Array(this.data))
|
|
33
|
-
}
|
|
32
|
+
peekVarString(): string {
|
|
33
|
+
return peekVarString(this.decoder);
|
|
34
|
+
}
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
readVarUint(): MessageType {
|
|
37
|
+
return readVarUint(this.decoder);
|
|
38
|
+
}
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
readVarString(): string {
|
|
41
|
+
return readVarString(this.decoder);
|
|
42
|
+
}
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
readVarUint8Array() {
|
|
45
|
+
return readVarUint8Array(this.decoder);
|
|
46
|
+
}
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
writeVarUint(type: MessageType) {
|
|
49
|
+
return writeVarUint(this.encoder, type);
|
|
50
|
+
}
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
writeVarString(string: string) {
|
|
53
|
+
return writeVarString(this.encoder, string);
|
|
54
|
+
}
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
writeVarUint8Array(data: Uint8Array) {
|
|
57
|
+
return writeVarUint8Array(this.encoder, data);
|
|
58
|
+
}
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
length() {
|
|
64
|
-
return length(this.encoder)
|
|
65
|
-
}
|
|
60
|
+
length() {
|
|
61
|
+
return length(this.encoder);
|
|
62
|
+
}
|
|
66
63
|
}
|
package/src/MessageReceiver.ts
CHANGED
|
@@ -1,135 +1,138 @@
|
|
|
1
|
-
import { readAuthMessage } from
|
|
2
|
-
import { readVarInt, readVarString } from
|
|
3
|
-
import * as awarenessProtocol from
|
|
4
|
-
import { messageYjsSyncStep2, readSyncMessage } from
|
|
5
|
-
import type { CloseEvent } from
|
|
6
|
-
import type { HocuspocusProvider } from
|
|
7
|
-
import type { IncomingMessage } from
|
|
8
|
-
import { OutgoingMessage } from
|
|
9
|
-
import { MessageType } from
|
|
1
|
+
import { readAuthMessage } from "@hocuspocus/common";
|
|
2
|
+
import { readVarInt, readVarString } from "lib0/decoding";
|
|
3
|
+
import * as awarenessProtocol from "y-protocols/awareness";
|
|
4
|
+
import { messageYjsSyncStep2, readSyncMessage } from "y-protocols/sync";
|
|
5
|
+
import type { CloseEvent } from "ws";
|
|
6
|
+
import type { HocuspocusProvider } from "./HocuspocusProvider.ts";
|
|
7
|
+
import type { IncomingMessage } from "./IncomingMessage.ts";
|
|
8
|
+
import { OutgoingMessage } from "./OutgoingMessage.ts";
|
|
9
|
+
import { MessageType } from "./types.ts";
|
|
10
10
|
|
|
11
11
|
export class MessageReceiver {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
12
|
+
message: IncomingMessage;
|
|
13
|
+
|
|
14
|
+
constructor(message: IncomingMessage) {
|
|
15
|
+
this.message = message;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public apply(provider: HocuspocusProvider, emitSynced: boolean) {
|
|
19
|
+
const { message } = this;
|
|
20
|
+
const type = message.readVarUint();
|
|
21
|
+
|
|
22
|
+
const emptyMessageLength = message.length();
|
|
23
|
+
|
|
24
|
+
switch (type) {
|
|
25
|
+
case MessageType.Sync:
|
|
26
|
+
this.applySyncMessage(provider, emitSynced);
|
|
27
|
+
break;
|
|
28
|
+
|
|
29
|
+
case MessageType.Awareness:
|
|
30
|
+
this.applyAwarenessMessage(provider);
|
|
31
|
+
break;
|
|
32
|
+
|
|
33
|
+
case MessageType.Auth:
|
|
34
|
+
this.applyAuthMessage(provider);
|
|
35
|
+
break;
|
|
36
|
+
|
|
37
|
+
case MessageType.QueryAwareness:
|
|
38
|
+
this.applyQueryAwarenessMessage(provider);
|
|
39
|
+
break;
|
|
40
|
+
|
|
41
|
+
case MessageType.Stateless:
|
|
42
|
+
provider.receiveStateless(readVarString(message.decoder));
|
|
43
|
+
break;
|
|
44
|
+
|
|
45
|
+
case MessageType.SyncStatus:
|
|
46
|
+
this.applySyncStatusMessage(
|
|
47
|
+
provider,
|
|
48
|
+
readVarInt(message.decoder) === 1,
|
|
49
|
+
);
|
|
50
|
+
break;
|
|
51
|
+
|
|
52
|
+
case MessageType.CLOSE:
|
|
53
|
+
// eslint-disable-next-line no-case-declarations
|
|
54
|
+
const event: CloseEvent = {
|
|
55
|
+
code: 1000,
|
|
56
|
+
reason: readVarString(message.decoder),
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
target: provider.configuration.websocketProvider.webSocket!,
|
|
59
|
+
type: "close",
|
|
60
|
+
};
|
|
61
|
+
provider.onClose();
|
|
62
|
+
provider.configuration.onClose({ event });
|
|
63
|
+
provider.forwardClose(event);
|
|
64
|
+
break;
|
|
65
|
+
|
|
66
|
+
default:
|
|
67
|
+
throw new Error(`Can’t apply message of unknown type: ${type}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Reply
|
|
71
|
+
if (message.length() > emptyMessageLength + 1) {
|
|
72
|
+
// length of documentName (considered in emptyMessageLength plus length of yjs sync type, set in applySyncMessage)
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
provider.send(OutgoingMessage, { encoder: message.encoder });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private applySyncMessage(provider: HocuspocusProvider, emitSynced: boolean) {
|
|
79
|
+
const { message } = this;
|
|
80
|
+
|
|
81
|
+
message.writeVarUint(MessageType.Sync);
|
|
82
|
+
|
|
83
|
+
// Apply update
|
|
84
|
+
const syncMessageType = readSyncMessage(
|
|
85
|
+
message.decoder,
|
|
86
|
+
message.encoder,
|
|
87
|
+
provider.document,
|
|
88
|
+
provider,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
// Synced once we receive Step2
|
|
92
|
+
if (emitSynced && syncMessageType === messageYjsSyncStep2) {
|
|
93
|
+
provider.synced = true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
applySyncStatusMessage(provider: HocuspocusProvider, applied: boolean) {
|
|
98
|
+
if (applied) {
|
|
99
|
+
provider.decrementUnsyncedChanges();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private applyAwarenessMessage(provider: HocuspocusProvider) {
|
|
104
|
+
if (!provider.awareness) return;
|
|
105
|
+
|
|
106
|
+
const { message } = this;
|
|
107
|
+
|
|
108
|
+
awarenessProtocol.applyAwarenessUpdate(
|
|
109
|
+
provider.awareness,
|
|
110
|
+
message.readVarUint8Array(),
|
|
111
|
+
provider,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private applyAuthMessage(provider: HocuspocusProvider) {
|
|
116
|
+
const { message } = this;
|
|
117
|
+
|
|
118
|
+
readAuthMessage(
|
|
119
|
+
message.decoder,
|
|
120
|
+
provider.permissionDeniedHandler.bind(provider),
|
|
121
|
+
provider.authenticatedHandler.bind(provider),
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private applyQueryAwarenessMessage(provider: HocuspocusProvider) {
|
|
126
|
+
if (!provider.awareness) return;
|
|
127
|
+
|
|
128
|
+
const { message } = this;
|
|
129
|
+
|
|
130
|
+
message.writeVarUint(MessageType.Awareness);
|
|
131
|
+
message.writeVarUint8Array(
|
|
132
|
+
awarenessProtocol.encodeAwarenessUpdate(
|
|
133
|
+
provider.awareness,
|
|
134
|
+
Array.from(provider.awareness.getStates().keys()),
|
|
135
|
+
),
|
|
136
|
+
);
|
|
137
|
+
}
|
|
135
138
|
}
|
package/src/OutgoingMessage.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
import type { Encoder} from
|
|
2
|
-
import { createEncoder, toUint8Array } from
|
|
3
|
-
import type {
|
|
1
|
+
import type { Encoder } from "lib0/encoding";
|
|
2
|
+
import { createEncoder, toUint8Array } from "lib0/encoding";
|
|
3
|
+
import type {
|
|
4
|
+
MessageType,
|
|
5
|
+
OutgoingMessageArguments,
|
|
6
|
+
OutgoingMessageInterface,
|
|
7
|
+
} from "./types.ts";
|
|
4
8
|
|
|
5
9
|
export class OutgoingMessage implements OutgoingMessageInterface {
|
|
6
|
-
|
|
10
|
+
encoder: Encoder;
|
|
7
11
|
|
|
8
|
-
|
|
12
|
+
type?: MessageType;
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
constructor() {
|
|
15
|
+
this.encoder = createEncoder();
|
|
16
|
+
}
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
get(args: Partial<OutgoingMessageArguments>) {
|
|
19
|
+
return args.encoder;
|
|
20
|
+
}
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
toUint8Array() {
|
|
23
|
+
return toUint8Array(this.encoder);
|
|
24
|
+
}
|
|
21
25
|
}
|
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import { writeVarString, writeVarUint } from
|
|
2
|
-
import { writeAuthentication } from
|
|
3
|
-
import type { OutgoingMessageArguments } from
|
|
4
|
-
import { MessageType } from
|
|
5
|
-
import { OutgoingMessage } from
|
|
1
|
+
import { writeVarString, writeVarUint } from "lib0/encoding";
|
|
2
|
+
import { writeAuthentication } from "@hocuspocus/common";
|
|
3
|
+
import type { OutgoingMessageArguments } from "../types.ts";
|
|
4
|
+
import { MessageType } from "../types.ts";
|
|
5
|
+
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
6
6
|
|
|
7
7
|
export class AuthenticationMessage extends OutgoingMessage {
|
|
8
|
-
|
|
8
|
+
type = MessageType.Auth;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
description = "Authentication";
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
get(args: Partial<OutgoingMessageArguments>) {
|
|
13
|
+
if (typeof args.token === "undefined") {
|
|
14
|
+
throw new Error(
|
|
15
|
+
"The authentication message requires `token` as an argument.",
|
|
16
|
+
);
|
|
17
|
+
}
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
writeVarString(this.encoder, args.documentName!);
|
|
20
|
+
writeVarUint(this.encoder, this.type);
|
|
21
|
+
writeAuthentication(this.encoder, args.token);
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
return this.encoder;
|
|
24
|
+
}
|
|
23
25
|
}
|
|
@@ -1,35 +1,41 @@
|
|
|
1
|
-
import * as encoding from
|
|
2
|
-
import { encodeAwarenessUpdate } from
|
|
3
|
-
import type { OutgoingMessageArguments } from
|
|
4
|
-
import { MessageType } from
|
|
5
|
-
import { OutgoingMessage } from
|
|
1
|
+
import * as encoding from "lib0/encoding";
|
|
2
|
+
import { encodeAwarenessUpdate } from "y-protocols/awareness";
|
|
3
|
+
import type { OutgoingMessageArguments } from "../types.ts";
|
|
4
|
+
import { MessageType } from "../types.ts";
|
|
5
|
+
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
6
6
|
|
|
7
7
|
export class AwarenessMessage extends OutgoingMessage {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
8
|
+
type = MessageType.Awareness;
|
|
9
|
+
|
|
10
|
+
description = "Awareness states update";
|
|
11
|
+
|
|
12
|
+
get(args: Partial<OutgoingMessageArguments>) {
|
|
13
|
+
if (typeof args.awareness === "undefined") {
|
|
14
|
+
throw new Error(
|
|
15
|
+
"The awareness message requires awareness as an argument",
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (typeof args.clients === "undefined") {
|
|
20
|
+
throw new Error("The awareness message requires clients as an argument");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
encoding.writeVarString(this.encoder, args.documentName!);
|
|
24
|
+
encoding.writeVarUint(this.encoder, this.type);
|
|
25
|
+
|
|
26
|
+
let awarenessUpdate;
|
|
27
|
+
if (args.states === undefined) {
|
|
28
|
+
awarenessUpdate = encodeAwarenessUpdate(args.awareness, args.clients);
|
|
29
|
+
} else {
|
|
30
|
+
awarenessUpdate = encodeAwarenessUpdate(
|
|
31
|
+
args.awareness,
|
|
32
|
+
args.clients,
|
|
33
|
+
args.states,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
encoding.writeVarUint8Array(this.encoder, awarenessUpdate);
|
|
38
|
+
|
|
39
|
+
return this.encoder;
|
|
40
|
+
}
|
|
35
41
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import * as encoding from
|
|
2
|
-
import type { OutgoingMessageArguments } from
|
|
3
|
-
import { MessageType } from
|
|
4
|
-
import { OutgoingMessage } from
|
|
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
5
|
|
|
6
6
|
export class CloseMessage extends OutgoingMessage {
|
|
7
|
-
|
|
7
|
+
type = MessageType.CLOSE;
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
description = "Ask the server to close the connection";
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
get(args: Partial<OutgoingMessageArguments>) {
|
|
12
|
+
encoding.writeVarString(this.encoder, args.documentName!);
|
|
13
|
+
encoding.writeVarUint(this.encoder, this.type);
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
return this.encoder;
|
|
16
|
+
}
|
|
17
17
|
}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import * as encoding from
|
|
2
|
-
import type { OutgoingMessageArguments } from
|
|
3
|
-
import { MessageType } from
|
|
4
|
-
import { OutgoingMessage } from
|
|
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
5
|
|
|
6
6
|
export class QueryAwarenessMessage extends OutgoingMessage {
|
|
7
|
-
|
|
7
|
+
type = MessageType.QueryAwareness;
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
description = "Queries awareness states";
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
get(args: Partial<OutgoingMessageArguments>) {
|
|
12
|
+
encoding.writeVarString(this.encoder, args.documentName!);
|
|
13
|
+
encoding.writeVarUint(this.encoder, this.type);
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return this.encoder
|
|
17
|
-
}
|
|
15
|
+
return this.encoder;
|
|
16
|
+
}
|
|
18
17
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { writeVarString, writeVarUint } from
|
|
2
|
-
import type { OutgoingMessageArguments } from
|
|
3
|
-
import { MessageType } from
|
|
4
|
-
import { OutgoingMessage } from
|
|
1
|
+
import { writeVarString, writeVarUint } from "lib0/encoding";
|
|
2
|
+
import type { OutgoingMessageArguments } from "../types.ts";
|
|
3
|
+
import { MessageType } from "../types.ts";
|
|
4
|
+
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
5
5
|
|
|
6
6
|
export class StatelessMessage extends OutgoingMessage {
|
|
7
|
-
|
|
7
|
+
type = MessageType.Stateless;
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
description = "A stateless message";
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
get(args: Partial<OutgoingMessageArguments>) {
|
|
12
|
+
writeVarString(this.encoder, args.documentName!);
|
|
13
|
+
writeVarUint(this.encoder, this.type);
|
|
14
|
+
writeVarString(this.encoder, args.payload ?? "");
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
return this.encoder;
|
|
17
|
+
}
|
|
18
18
|
}
|