snapshot of https://github.com/ueberdosis/hocuspocus.git @ cf3cfa355b4d3bb61c6b6c80071f71783e32470e (2026-09-15)
Some checks failed
build / lint (22) (push) Failing after 17s
build / test (22) (push) Failing after 8s
build / lint (23) (push) Failing after 2s
build / build (22) (push) Has been skipped
build / build (23) (push) Has been skipped
build / test (23) (push) Failing after 4s
docsearch / docsearch (push) Failing after 1s
Some checks failed
build / lint (22) (push) Failing after 17s
build / test (22) (push) Failing after 8s
build / lint (23) (push) Failing after 2s
build / build (22) (push) Has been skipped
build / build (23) (push) Has been skipped
build / test (23) (push) Failing after 4s
docsearch / docsearch (push) Failing after 1s
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { writeVarString, writeVarUint } from "lib0/encoding";
|
||||
import { writeAuthentication } from "@hocuspocus/common";
|
||||
import type { OutgoingMessageArguments } from "../types.ts";
|
||||
import { MessageType } from "../types.ts";
|
||||
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
||||
import { version } from "../version.ts";
|
||||
|
||||
export class AuthenticationMessage extends OutgoingMessage {
|
||||
type = MessageType.Auth;
|
||||
|
||||
description = "Authentication";
|
||||
|
||||
get(args: Partial<OutgoingMessageArguments>) {
|
||||
if (typeof args.token === "undefined") {
|
||||
throw new Error(
|
||||
"The authentication message requires `token` as an argument.",
|
||||
);
|
||||
}
|
||||
|
||||
writeVarString(this.encoder, args.documentName!);
|
||||
writeVarUint(this.encoder, this.type);
|
||||
writeAuthentication(this.encoder, args.token);
|
||||
writeVarString(this.encoder, version);
|
||||
|
||||
return this.encoder;
|
||||
}
|
||||
}
|
||||
41
packages/provider/src/OutgoingMessages/AwarenessMessage.ts
Normal file
41
packages/provider/src/OutgoingMessages/AwarenessMessage.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import * as encoding from "lib0/encoding";
|
||||
import { encodeAwarenessUpdate } from "y-protocols/awareness";
|
||||
import type { OutgoingMessageArguments } from "../types.ts";
|
||||
import { MessageType } from "../types.ts";
|
||||
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
||||
|
||||
export class AwarenessMessage extends OutgoingMessage {
|
||||
type = MessageType.Awareness;
|
||||
|
||||
description = "Awareness states update";
|
||||
|
||||
get(args: Partial<OutgoingMessageArguments>) {
|
||||
if (typeof args.awareness === "undefined") {
|
||||
throw new Error(
|
||||
"The awareness message requires awareness as an argument",
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof args.clients === "undefined") {
|
||||
throw new Error("The awareness message requires clients as an argument");
|
||||
}
|
||||
|
||||
encoding.writeVarString(this.encoder, args.documentName!);
|
||||
encoding.writeVarUint(this.encoder, this.type);
|
||||
|
||||
let awarenessUpdate;
|
||||
if (args.states === undefined) {
|
||||
awarenessUpdate = encodeAwarenessUpdate(args.awareness, args.clients);
|
||||
} else {
|
||||
awarenessUpdate = encodeAwarenessUpdate(
|
||||
args.awareness,
|
||||
args.clients,
|
||||
args.states,
|
||||
);
|
||||
}
|
||||
|
||||
encoding.writeVarUint8Array(this.encoder, awarenessUpdate);
|
||||
|
||||
return this.encoder;
|
||||
}
|
||||
}
|
||||
17
packages/provider/src/OutgoingMessages/CloseMessage.ts
Normal file
17
packages/provider/src/OutgoingMessages/CloseMessage.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import * as encoding from "lib0/encoding";
|
||||
import type { OutgoingMessageArguments } from "../types.ts";
|
||||
import { MessageType } from "../types.ts";
|
||||
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
||||
|
||||
export class CloseMessage extends OutgoingMessage {
|
||||
type = MessageType.CLOSE;
|
||||
|
||||
description = "Ask the server to close the connection";
|
||||
|
||||
get(args: Partial<OutgoingMessageArguments>) {
|
||||
encoding.writeVarString(this.encoder, args.documentName!);
|
||||
encoding.writeVarUint(this.encoder, this.type);
|
||||
|
||||
return this.encoder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import * as encoding from "lib0/encoding";
|
||||
import type { OutgoingMessageArguments } from "../types.ts";
|
||||
import { MessageType } from "../types.ts";
|
||||
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
||||
|
||||
export class QueryAwarenessMessage extends OutgoingMessage {
|
||||
type = MessageType.QueryAwareness;
|
||||
|
||||
description = "Queries awareness states";
|
||||
|
||||
get(args: Partial<OutgoingMessageArguments>) {
|
||||
encoding.writeVarString(this.encoder, args.documentName!);
|
||||
encoding.writeVarUint(this.encoder, this.type);
|
||||
|
||||
return this.encoder;
|
||||
}
|
||||
}
|
||||
18
packages/provider/src/OutgoingMessages/StatelessMessage.ts
Normal file
18
packages/provider/src/OutgoingMessages/StatelessMessage.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { writeVarString, writeVarUint } from "lib0/encoding";
|
||||
import type { OutgoingMessageArguments } from "../types.ts";
|
||||
import { MessageType } from "../types.ts";
|
||||
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
||||
|
||||
export class StatelessMessage extends OutgoingMessage {
|
||||
type = MessageType.Stateless;
|
||||
|
||||
description = "A stateless message";
|
||||
|
||||
get(args: Partial<OutgoingMessageArguments>) {
|
||||
writeVarString(this.encoder, args.documentName!);
|
||||
writeVarUint(this.encoder, this.type);
|
||||
writeVarString(this.encoder, args.payload ?? "");
|
||||
|
||||
return this.encoder;
|
||||
}
|
||||
}
|
||||
25
packages/provider/src/OutgoingMessages/SyncStepOneMessage.ts
Normal file
25
packages/provider/src/OutgoingMessages/SyncStepOneMessage.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import * as encoding from "lib0/encoding";
|
||||
import * as syncProtocol from "y-protocols/sync";
|
||||
import type { OutgoingMessageArguments } from "../types.ts";
|
||||
import { MessageType } from "../types.ts";
|
||||
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
||||
|
||||
export class SyncStepOneMessage extends OutgoingMessage {
|
||||
type = MessageType.Sync;
|
||||
|
||||
description = "First sync step";
|
||||
|
||||
get(args: Partial<OutgoingMessageArguments>) {
|
||||
if (typeof args.document === "undefined") {
|
||||
throw new Error(
|
||||
"The sync step one message requires document as an argument",
|
||||
);
|
||||
}
|
||||
|
||||
encoding.writeVarString(this.encoder, args.documentName!);
|
||||
encoding.writeVarUint(this.encoder, this.type);
|
||||
syncProtocol.writeSyncStep1(this.encoder, args.document);
|
||||
|
||||
return this.encoder;
|
||||
}
|
||||
}
|
||||
25
packages/provider/src/OutgoingMessages/SyncStepTwoMessage.ts
Normal file
25
packages/provider/src/OutgoingMessages/SyncStepTwoMessage.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import * as encoding from "lib0/encoding";
|
||||
import * as syncProtocol from "y-protocols/sync";
|
||||
import type { OutgoingMessageArguments } from "../types.ts";
|
||||
import { MessageType } from "../types.ts";
|
||||
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
||||
|
||||
export class SyncStepTwoMessage extends OutgoingMessage {
|
||||
type = MessageType.Sync;
|
||||
|
||||
description = "Second sync step";
|
||||
|
||||
get(args: Partial<OutgoingMessageArguments>) {
|
||||
if (typeof args.document === "undefined") {
|
||||
throw new Error(
|
||||
"The sync step two message requires document as an argument",
|
||||
);
|
||||
}
|
||||
|
||||
encoding.writeVarString(this.encoder, args.documentName!);
|
||||
encoding.writeVarUint(this.encoder, this.type);
|
||||
syncProtocol.writeSyncStep2(this.encoder, args.document);
|
||||
|
||||
return this.encoder;
|
||||
}
|
||||
}
|
||||
20
packages/provider/src/OutgoingMessages/UpdateMessage.ts
Normal file
20
packages/provider/src/OutgoingMessages/UpdateMessage.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { writeVarString, writeVarUint } from "lib0/encoding";
|
||||
import { writeUpdate } from "y-protocols/sync";
|
||||
import type { OutgoingMessageArguments } from "../types.ts";
|
||||
import { MessageType } from "../types.ts";
|
||||
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
||||
|
||||
export class UpdateMessage extends OutgoingMessage {
|
||||
type = MessageType.Sync;
|
||||
|
||||
description = "A document update";
|
||||
|
||||
get(args: Partial<OutgoingMessageArguments>) {
|
||||
writeVarString(this.encoder, args.documentName!);
|
||||
writeVarUint(this.encoder, this.type);
|
||||
|
||||
writeUpdate(this.encoder, args.update);
|
||||
|
||||
return this.encoder;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user