OhMyDitzzy commited on
Commit ·
70c6694
1
Parent(s): 56e9e05
Anything
Browse files
src/modules/comic/ComicReader.tsx
CHANGED
|
@@ -46,10 +46,14 @@ export function ComicReader() {
|
|
| 46 |
const password = location.state?.password;
|
| 47 |
const originalSessionId = location.state?.sessionId;
|
| 48 |
|
|
|
|
| 49 |
useEffect(() => {
|
| 50 |
if (!password || !originalSessionId) return;
|
| 51 |
|
| 52 |
-
const
|
|
|
|
|
|
|
|
|
|
| 53 |
const ws = new WebSocket(wsUrl);
|
| 54 |
wsRef.current = ws;
|
| 55 |
|
|
@@ -91,10 +95,13 @@ export function ComicReader() {
|
|
| 91 |
|
| 92 |
ws.onclose = () => {
|
| 93 |
console.log('[Reader WS] Disconnected');
|
|
|
|
| 94 |
};
|
| 95 |
|
| 96 |
return () => {
|
| 97 |
-
ws.
|
|
|
|
|
|
|
| 98 |
};
|
| 99 |
}, [password, originalSessionId]);
|
| 100 |
|
|
@@ -214,26 +221,47 @@ export function ComicReader() {
|
|
| 214 |
};
|
| 215 |
|
| 216 |
const handleChapterNavigation = (chapterSlug: string) => {
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
|
| 222 |
if (!password || !originalSessionId) {
|
| 223 |
setError('Missing authentication data');
|
| 224 |
return;
|
| 225 |
}
|
| 226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
setLoadingChapter(true);
|
| 228 |
setShowMenu(false);
|
| 229 |
|
| 230 |
-
|
| 231 |
type: 'request_chapter_data',
|
| 232 |
sessionId: originalSessionId,
|
| 233 |
password: password,
|
| 234 |
chapterSlug: chapterSlug,
|
| 235 |
allChapters: data?.allChapters || []
|
| 236 |
-
}
|
|
|
|
|
|
|
|
|
|
| 237 |
};
|
| 238 |
|
| 239 |
if (loading) {
|
|
|
|
| 46 |
const password = location.state?.password;
|
| 47 |
const originalSessionId = location.state?.sessionId;
|
| 48 |
|
| 49 |
+
// WebSocket setup
|
| 50 |
useEffect(() => {
|
| 51 |
if (!password || !originalSessionId) return;
|
| 52 |
|
| 53 |
+
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
| 54 |
+
const wsUrl = `${protocol}//${window.location.host}/ws`;
|
| 55 |
+
console.log('[Reader WS] Connecting to:', wsUrl);
|
| 56 |
+
|
| 57 |
const ws = new WebSocket(wsUrl);
|
| 58 |
wsRef.current = ws;
|
| 59 |
|
|
|
|
| 95 |
|
| 96 |
ws.onclose = () => {
|
| 97 |
console.log('[Reader WS] Disconnected');
|
| 98 |
+
wsRef.current = null;
|
| 99 |
};
|
| 100 |
|
| 101 |
return () => {
|
| 102 |
+
if (ws.readyState === WebSocket.OPEN) {
|
| 103 |
+
ws.close();
|
| 104 |
+
}
|
| 105 |
};
|
| 106 |
}, [password, originalSessionId]);
|
| 107 |
|
|
|
|
| 221 |
};
|
| 222 |
|
| 223 |
const handleChapterNavigation = (chapterSlug: string) => {
|
| 224 |
+
console.log('[Reader] Attempting chapter navigation to:', chapterSlug);
|
| 225 |
+
console.log('[Reader] WebSocket state:', wsRef.current?.readyState);
|
| 226 |
+
console.log('[Reader] Has password:', !!password);
|
| 227 |
+
console.log('[Reader] Has sessionId:', !!originalSessionId);
|
| 228 |
|
| 229 |
if (!password || !originalSessionId) {
|
| 230 |
setError('Missing authentication data');
|
| 231 |
return;
|
| 232 |
}
|
| 233 |
|
| 234 |
+
if (!wsRef.current || wsRef.current.readyState !== WebSocket.OPEN) {
|
| 235 |
+
if (wsRef.current?.readyState === WebSocket.CONNECTING) {
|
| 236 |
+
console.log('[Reader] WebSocket is connecting, waiting...');
|
| 237 |
+
setTimeout(() => {
|
| 238 |
+
if (wsRef.current?.readyState === WebSocket.OPEN) {
|
| 239 |
+
handleChapterNavigation(chapterSlug);
|
| 240 |
+
} else {
|
| 241 |
+
setError('Connection not ready. Please try again.');
|
| 242 |
+
}
|
| 243 |
+
}, 1000);
|
| 244 |
+
return;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
setError('Connection lost. Please refresh the page.');
|
| 248 |
+
console.error('[Reader] WebSocket not connected. State:', wsRef.current?.readyState);
|
| 249 |
+
return;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
setLoadingChapter(true);
|
| 253 |
setShowMenu(false);
|
| 254 |
|
| 255 |
+
const requestData = {
|
| 256 |
type: 'request_chapter_data',
|
| 257 |
sessionId: originalSessionId,
|
| 258 |
password: password,
|
| 259 |
chapterSlug: chapterSlug,
|
| 260 |
allChapters: data?.allChapters || []
|
| 261 |
+
};
|
| 262 |
+
|
| 263 |
+
console.log('[Reader] Sending chapter request:', requestData);
|
| 264 |
+
wsRef.current.send(JSON.stringify(requestData));
|
| 265 |
};
|
| 266 |
|
| 267 |
if (loading) {
|