Fix: reduce the initial connection data

This commit is contained in:
arabcoders 2025-11-11 17:24:07 +03:00
parent e6296de3fe
commit fa9f1fcefc
4 changed files with 44 additions and 23 deletions

View file

@ -24,6 +24,8 @@ class Events:
CONNECTED: str = "connected"
CONFIGURATION: str = "configuration"
LOG_INFO: str = "log_info"
LOG_WARNING: str = "log_warning"
LOG_ERROR: str = "log_error"
@ -90,6 +92,7 @@ class Events:
"""
return [
Events.CONFIGURATION,
Events.CONNECTED,
Events.LOG_INFO,
Events.LOG_WARNING,

View file

@ -44,7 +44,7 @@ class HttpSocket:
self.sio = sio or socketio.AsyncServer(
async_handlers=True,
async_mode="aiohttp",
cors_allowed_origins=[],
cors_allowed_origins="*",
transports=["websocket", "polling"],
logger=self.config.debug,
engineio_logger=self.config.debug,

View file

@ -23,25 +23,31 @@ class _Data:
@route(RouteType.SOCKET, "connect", "socket_connect")
async def connect(config: Config, queue: DownloadQueue, notify: EventBus, sid: str):
data = {
**queue.get(),
"config": config.frontend(),
"presets": Presets.get_instance().get_all(),
"dl_fields": DLFields.get_instance().get_all(),
"paused": queue.is_paused(),
}
data["folders"] = list_folders(
path=Path(config.download_path),
base=Path(config.download_path),
depth_limit=config.download_path_depth-1,
notify.emit(
Events.CONFIGURATION,
data={
"config": config.frontend(),
"presets": Presets.get_instance().get_all(),
"dl_fields": DLFields.get_instance().get_all(),
"paused": queue.is_paused(),
},
title="Client connected",
message=f"Client '{sid}' connected.",
to=sid,
)
notify.emit(
Events.CONNECTED,
data=data,
title="Client connected",
message=f"Client '{sid}' connected.",
data={
"folders": list_folders(
path=Path(config.download_path),
base=Path(config.download_path),
depth_limit=config.download_path_depth - 1,
),
**queue.get(),
},
title="Sending initial download data",
message=f"Sending initial download data to client '{sid}'.",
to=sid,
)

View file

@ -54,8 +54,10 @@ export const useSocketStore = defineStore('socket', () => {
transports: ['websocket', 'polling'],
withCredentials: true,
reconnection: true,
reconnectionAttempts: 30,
reconnectionDelay: 5000
reconnectionAttempts: 50,
reconnectionDelay: 5000,
tryAllTransports: true,
timeout: 10000 * 5,
} as Partial<ManagerOptions & SocketOptions>
let url = runtimeConfig.public.wss
@ -70,28 +72,38 @@ export const useSocketStore = defineStore('socket', () => {
connectionStatus.value = 'connecting';
socket.value = io(url, opts)
socket.value.on('connect', () => {
on("connect_error", (e: any) => {
if (!socket.value) {
return;
}
console.error("Socket connection error:", e);
socket.value.io.opts.transports = ["polling", "websocket"];
});
on('connect', () => {
isConnected.value = true
connectionStatus.value = 'connected';
});
socket.value.on('disconnect', () => {
on('disconnect', () => {
isConnected.value = false
connectionStatus.value = 'disconnected';
});
socket.value.on('connected', stream => {
on('configuration', stream => {
const json = JSON.parse(stream)
config.setAll({
app: json.data.config,
tasks: json.data.tasks,
folders: json.data.folders,
presets: json.data.presets,
dl_fields: json.data.dl_fields,
paused: Boolean(json.data.paused)
} as Partial<ConfigState>)
})
on('connected', stream => {
const json = JSON.parse(stream);
config.add('folders', json.data.folders)
stateStore.addAll('queue', json.data.queue || {})
stateStore.addAll('history', json.data.done || {})
})