fix: Collaboration debounce shared between docs (#3401)

* fix: Collaboration debounce shared between docs

* Rename, Tracing -> Metrics

* Add tracing

* tsc

* fix: Lock document row when loading document in collaboration service incase state needs writing

* fix: Incorrect service name regression
This commit is contained in:
Tom Moor
2022-04-16 14:58:17 -07:00
committed by GitHub
parent 1a8f2c3bb0
commit 4c4b80ba9b
9 changed files with 192 additions and 156 deletions

View File

@@ -4,26 +4,28 @@ import { Server } from "@hocuspocus/server";
import invariant from "invariant";
import Koa from "koa";
import WebSocket from "ws";
import AuthenticationExtension from "../collaboration/authentication";
import LoggerExtension from "../collaboration/logger";
import PersistenceExtension from "../collaboration/persistence";
import TracingExtension from "../collaboration/tracing";
import AuthenticationExtension from "../collaboration/AuthenticationExtension";
import LoggerExtension from "../collaboration/LoggerExtension";
import MetricsExtension from "../collaboration/MetricsExtension";
import PersistenceExtension from "../collaboration/PersistenceExtension";
export default function init(app: Koa, server: http.Server) {
const path = "/collaboration";
const wss = new WebSocket.Server({
noServer: true,
});
const hocuspocus = Server.configure({
debounce: 3000,
maxDebounce: 10000,
extensions: [
new AuthenticationExtension(),
// @ts-expect-error ts-migrate(2322) FIXME: Type 'Persistence' is not assignable to type 'Exte... Remove this comment to see the full error message
new PersistenceExtension(),
new LoggerExtension(),
// @ts-expect-error ts-migrate(2322) FIXME: Type 'Persistence' is not assignable to type 'Exte... Remove this comment to see the full error message
new TracingExtension(),
new MetricsExtension(),
],
});
server.on("upgrade", function (req, socket, head) {
if (req.url && req.url.indexOf(path) > -1) {
const documentName = url.parse(req.url).pathname?.split("/").pop();
@@ -34,7 +36,8 @@ export default function init(app: Koa, server: http.Server) {
});
}
});
server.on("shutdown", () => {
hocuspocus.destroy();
return hocuspocus.destroy();
});
}