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" CONNECTED: str = "connected"
CONFIGURATION: str = "configuration"
LOG_INFO: str = "log_info" LOG_INFO: str = "log_info"
LOG_WARNING: str = "log_warning" LOG_WARNING: str = "log_warning"
LOG_ERROR: str = "log_error" LOG_ERROR: str = "log_error"
@ -90,6 +92,7 @@ class Events:
""" """
return [ return [
Events.CONFIGURATION,
Events.CONNECTED, Events.CONNECTED,
Events.LOG_INFO, Events.LOG_INFO,
Events.LOG_WARNING, Events.LOG_WARNING,

View file

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

View file

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

View file

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