fix: NCWF-1 401 (#6)
Co-authored-by: shahdlala66 <shahd.lala66@gmail.com> Co-authored-by: Lala, Shahd <Shahd.Lala@sybit.de> Reviewed-on: #6
This commit was merged in pull request #6.
This commit is contained in:
@@ -84,8 +84,19 @@ export class StreamHandlerService {
|
||||
}
|
||||
};
|
||||
|
||||
// Set timeout to fallback if WebSocket doesn't connect quickly
|
||||
const connectionTimeoutId = setTimeout(() => {
|
||||
if (!connected && !fallbackActive) {
|
||||
console.warn(`[StreamHandler] WebSocket timeout for ${gameId}, attempting NDJSON fallback`);
|
||||
ws.close();
|
||||
void startNdjsonFallback();
|
||||
}
|
||||
}, 3000);
|
||||
|
||||
ws.onopen = () => {
|
||||
connected = true;
|
||||
clearTimeout(connectionTimeoutId);
|
||||
console.log(`[StreamHandler] WebSocket connected for ${gameId}`);
|
||||
};
|
||||
|
||||
ws.onmessage = (message) => {
|
||||
@@ -97,19 +108,23 @@ export class StreamHandlerService {
|
||||
};
|
||||
|
||||
ws.onerror = (error) => {
|
||||
console.warn(`[StreamHandler] WebSocket error for ${gameId}, attempting NDJSON fallback:`, error);
|
||||
if (!connected) {
|
||||
console.warn(`[StreamHandler] WebSocket error for ${gameId}:`, error);
|
||||
clearTimeout(connectionTimeoutId);
|
||||
if (!connected && !fallbackActive) {
|
||||
void startNdjsonFallback();
|
||||
}
|
||||
};
|
||||
|
||||
ws.onclose = () => {
|
||||
clearTimeout(connectionTimeoutId);
|
||||
console.warn(`[StreamHandler] WebSocket closed for ${gameId}, connected=${connected}`);
|
||||
if (!connected) {
|
||||
if (connected) {
|
||||
// Connection was established but closed, stream is complete
|
||||
observer.complete();
|
||||
} else if (!fallbackActive) {
|
||||
// Connection never established, try fallback
|
||||
console.log(`[StreamHandler] Starting NDJSON fallback for ${gameId}`);
|
||||
void startNdjsonFallback();
|
||||
} else {
|
||||
observer.complete();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user