mirror of
https://github.com/docmost/docmost.git
synced 2026-07-26 17:44:45 +10:00
feat: collab hocuspocus v4 upgrade (#2351)
* WIP 1 * complete v4 migration * add flushDelay * feat: multiplexing * fix: survive hocuspocus v4 message timeout * fix: searchTerm type error
This commit is contained in:
@@ -1,20 +1,17 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import type WebSocket from 'ws';
|
||||
import type { WebSocketLike } from '@hocuspocus/server';
|
||||
|
||||
/**
|
||||
* Wrapper around ws WebSocket that only receives events via emit().
|
||||
* This prevents double-handling when used with RedisSyncExtension.
|
||||
* Wrapper around ws WebSocket that Hocuspocus only writes to.
|
||||
* Incoming socket events are forwarded separately by the gateway,
|
||||
* which prevents double-handling with RedisSyncExtension.
|
||||
*/
|
||||
export class WsSocketWrapper extends EventEmitter {
|
||||
export class WsSocketWrapper implements WebSocketLike {
|
||||
private ws: WebSocket;
|
||||
readyState = 1;
|
||||
|
||||
constructor(ws: WebSocket) {
|
||||
super();
|
||||
this.ws = ws;
|
||||
this.once('close', () => {
|
||||
this.readyState = 3;
|
||||
});
|
||||
}
|
||||
|
||||
close(code?: number, reason?: string) {
|
||||
@@ -27,15 +24,6 @@ export class WsSocketWrapper extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
ping() {
|
||||
if (this.readyState !== 1) return;
|
||||
try {
|
||||
this.ws.ping();
|
||||
} catch (e) {
|
||||
// Socket already closed
|
||||
}
|
||||
}
|
||||
|
||||
send(message: Uint8Array) {
|
||||
if (this.readyState !== 1) return;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user