This commit is contained in:
Philipinho
2026-01-27 02:03:59 +00:00
parent 4d5e23cad2
commit f40f4daa1a
2 changed files with 8 additions and 7 deletions
@@ -85,30 +85,31 @@ export class CollaborationGateway {
method: request.method ?? 'GET', method: request.method ?? 'GET',
url: request.url ?? '/', url: request.url ?? '/',
headers: { headers: {
...request.headers,
'sec-websocket-key': request.headers['sec-websocket-key'] ?? '', 'sec-websocket-key': request.headers['sec-websocket-key'] ?? '',
} as SerializedHTTPRequest['headers'], 'sec-websocket-protocol':
request.headers['sec-websocket-protocol'] ?? '',
},
socket: { remoteAddress: request.socket?.remoteAddress ?? '' }, socket: { remoteAddress: request.socket?.remoteAddress ?? '' },
}; };
} }
handleConnection(client: WebSocket, request: IncomingMessage): any { handleConnection(client: WebSocket, request: IncomingMessage): any {
if (this.redisSync) { if (this.redisSync) {
const serializedRequest = this.serializeRequest(request); const serializedHTTPRequest = this.serializeRequest(request);
const socketId = serializedRequest.headers['sec-websocket-key']; const socketId = serializedHTTPRequest.headers['sec-websocket-key'];
// Create wrapper socket that only receives events via emit() // Create wrapper socket that only receives events via emit()
// This prevents double-handling since Hocuspocus won't listen to raw WebSocket events // This prevents double-handling since Hocuspocus won't listen to raw WebSocket events
const wrappedSocket = new WsSocketWrapper(client); const wrappedSocket = new WsSocketWrapper(client);
// Route through RedisSync extension (this calls handleConnection internally) // Route through RedisSync extension (this calls handleConnection internally)
this.redisSync.onSocketOpen(wrappedSocket as any, serializedRequest); this.redisSync.onSocketOpen(wrappedSocket as any, serializedHTTPRequest);
// Forward raw WebSocket messages to the extension // Forward raw WebSocket messages to the extension
client.on('message', (data: ArrayBuffer) => { client.on('message', (data: ArrayBuffer) => {
this.redisSync!.onSocketMessage( this.redisSync!.onSocketMessage(
wrappedSocket as any, wrappedSocket as any,
serializedRequest, serializedHTTPRequest,
data, data,
); );
}); });
@@ -13,7 +13,7 @@ export type SecondParam<T> = T extends (
export type SerializedHTTPRequest = { export type SerializedHTTPRequest = {
method: string; method: string;
url: string; url: string;
headers: IncomingHttpHeaders & { 'sec-websocket-key': string }; headers: IncomingHttpHeaders;
socket: { remoteAddress: string }; socket: { remoteAddress: string };
}; };