Fix: WebSocket-Konflikt zwischen Streaming und Watch Together

Root Cause: ws-Library killt WS-Verbindungen mit HTTP 400 wenn
mehrere WebSocketServer mit { server, path } registriert werden.
Der erste WSS (streaming) hat abortHandshake() fuer watch-together
Verbindungen aufgerufen.

- Beide WSS auf noServer-Modus umgestellt
- Zentrales upgrade-Routing in index.ts nach Pathname
- Frontend: connectWs prueft jetzt auch CONNECTING-State
- Frontend: onclose clobbert wsRef nur noch wenn gleicher Socket
- Frontend: waitForWs hat jetzt 10s Timeout statt Endlosschleife

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Daniel 2026-03-07 11:02:36 +01:00
parent e748fc97e9
commit e4895a792c
6 changed files with 60 additions and 32 deletions

View file

@ -1,5 +1,4 @@
import type express from 'express';
import http from 'node:http';
import { WebSocketServer, WebSocket } from 'ws';
import crypto from 'node:crypto';
import type { Plugin, PluginContext } from '../../core/plugin.js';
@ -265,9 +264,9 @@ const streamingPlugin: Plugin = {
},
};
/** Call after httpServer is created to attach WebSocket signaling */
export function attachWebSocket(server: http.Server): void {
wss = new WebSocketServer({ server, path: '/ws/streaming' });
/** Attach WebSocket signaling to a pre-created WebSocketServer (noServer mode) */
export function attachWebSocket(existingWss: WebSocketServer): void {
wss = existingWss;
wss.on('connection', (ws) => {
const clientId = crypto.randomUUID();

View file

@ -1,5 +1,4 @@
import type express from 'express';
import http from 'node:http';
import { WebSocketServer, WebSocket } from 'ws';
import crypto from 'node:crypto';
import type { Plugin, PluginContext } from '../../core/plugin.js';
@ -515,9 +514,9 @@ const watchTogetherPlugin: Plugin = {
},
};
/** Call after httpServer is created to attach WebSocket */
export function attachWatchTogetherWs(server: http.Server): void {
wss = new WebSocketServer({ server, path: '/ws/watch-together' });
/** Attach WebSocket to a pre-created WebSocketServer (noServer mode) */
export function attachWatchTogetherWs(existingWss: WebSocketServer): void {
wss = existingWss;
wss.on('connection', (ws) => {
const clientId = crypto.randomUUID();