Files
Echoion/docs/05-echoion-desktop.md
T
2026-02-01 23:09:22 +03:00

9.7 KiB

EchoionDesktop - Desktop Control Client

Purpose

EchoionDesktop is a standalone Qt6 application that provides a graphical interface for controlling the Echoion music bot remotely. Unlike the TeamSpeak plugin interface, this desktop client connects via WebSocket to offer rich visual feedback and easier control.

flowchart TB
    subgraph "EchoionDesktop"
        UI[Qt6 GUI]
        CC[CoreClient]
        WS[QWebSocket]
    end
    
    subgraph "EchoionCore"
        RS[RpcServer]
        MM[MusicManager]
    end
    
    subgraph "Connection"
        Protocol[WebSocket Protocol<br/>Port 8765]
    end
    
    UI <-->|Signals/Slots| CC
    CC <-->|JSON-RPC| WS
    WS <-->|WebSocket| Protocol
    Protocol <-->|JSON-RPC| RS
    RS <-->|Commands| MM

Architecture

Three-Layer Design

flowchart TB
    subgraph "Presentation Layer"
        MW[MainWindow]
        LD[LoginDialog]
        
        subgraph "Widgets"
            PC[Playback Controls]
            SP[Search Panel]
            QV[Queue View]
            SB[Status Bar]
        end
        
        MW --> PC
        MW --> SP
        MW --> QV
        MW --> SB
    end
    
    subgraph "Business Logic Layer"
        CC[CoreClient]
        Auth[Authentication]
        
        CC --> Auth
    end
    
    subgraph "Network Layer"
        WS[QWebSocket]
        JR[JSON-RPC Handler]
    end
    
    PC -->|User Actions| CC
    CC -->|State Updates| PC
    CC --> WS
    WS --> JR

User Interface

Main Window Layout

flowchart TB
    subgraph "MainWindow"
        direction TB
        
        TB2[Title Bar<br/>Login/Settings]
        
        subgraph "Playback Section"
            NP[Now Playing<br/>Title - Artist]
            PB[Progress Bar<br/>[=====>    ] 2:34/4:12]
            CTRL[Buttons: Play Pause Stop Skip Shuffle Repeat]
            VOL[Volume: [====>    ] 50%]
        end
        
        subgraph "Main Content"
            direction LR
            
            subgraph "Search Panel"
                SI[Search Input]
                SR[Search Results List]
            end
            
            subgraph "Queue Panel"
                QL[Queue List]
                QB[Clear / Remove]
            end
        end
        
        ST[Status Bar<br/>Connected ● | Authenticated ●]
    end
    
    TB2 --> Playback Section
    Playback Section --> Main Content
    Main Content --> ST

Screen Flow

stateDiagram-v2
    [*] --> Disconnected
    Disconnected --> Connecting: Start application
    Connecting --> Connected: WebSocket open
    Connecting --> Disconnected: Connection failed
    
    Connected --> Authenticating: Login clicked
    Authenticating --> Authenticated: Valid credentials
    Authenticating --> Connected: Login failed
    
    Authenticated --> Connected: Logout
    Authenticated --> Disconnected: Connection lost
    
    Connected --> Disconnected: Disconnect
    Disconnected --> [*]: Close application

Components

1. MainWindow (The UI)

Central widget containing all controls:

Sections:

  • Playback Controls: Play, pause, stop, skip, shuffle, repeat buttons
  • Progress Display: Current position, duration, progress bar
  • Volume Control: Slider for volume adjustment
  • Search Panel: Input field and results list
  • Queue View: Current queue with drag-and-drop reordering
  • Status Bar: Connection and authentication status

State Synchronization:

sequenceDiagram
    participant UI as MainWindow
    participant CC as CoreClient
    participant RS as RpcServer
    
    UI->>CC: Request playback state
    CC->>RS: getPlaybackState
    RS-->>CC: PlaybackState
    CC-->>UI: playbackStateReceived
    UI->>UI: Update all widgets
    
    loop Real-time updates
        RS->>CC: Event notification
        CC-->>UI: trackStarted/volumeChanged/etc
        UI->>UI: Update specific widget
    end

2. CoreClient (The Connector)

Manages WebSocket connection to EchoionCore:

Responsibilities:

  • Establish and maintain WebSocket connection
  • Handle authentication
  • Send RPC requests
  • Receive and dispatch events
  • Auto-reconnection on disconnect
flowchart TB
    subgraph "CoreClient"
        State[Connection State]
        Pending[Pending Requests]
        Handlers[Response Handlers]
    end
    
    subgraph "Operations"
        Connect[connectToCore]
        Auth[authenticate]
        Call[RPC Calls]
        Events[Event Handling]
    end
    
    State --> Connect
    Connect --> Auth
    Auth --> Call
    Call --> Pending
    Pending --> Handlers
    Handlers --> Events

3. LoginDialog (Authentication)

Simple dialog for admin login:

flowchart LR
    Dialog[LoginDialog] -->|Show| User[User Input]
    User -->|Username| Field1[Username Field]
    User -->|Password| Field2[Password Field]
    Field1 --> Validate
    Field2 --> Validate
    Validate -->|OK| Return[Return Credentials]
    Validate -->|Cancel| Close[Close Dialog]

Communication Protocol

Message Types

flowchart TB
    subgraph "Client → Core (Requests)"
        R1[Method Call<br/>id + method + params]
        R2[Authentication<br/>username + password]
    end
    
    subgraph "Core → Client (Responses)"
        S1[Success Response<br/>id + result]
        S2[Error Response<br/>id + error code + message]
        S3[Event Notification<br/>event name + data]
    end

Request Flow

sequenceDiagram
    participant User
    participant UI as MainWindow
    participant CC as CoreClient
    participant RS as RpcServer
    participant MM as MusicManager
    
    User->>UI: Click Play
    UI->>CC: play(query)
    CC->>CC: Generate request ID
    CC->>RS: Send JSON-RPC request
    RS->>MM: Execute play
    MM-->>RS: Result
    RS-->>CC: JSON-RPC response
    CC->>CC: Match to pending request
    CC-->>UI: Handle response
    UI->>UI: Update display

Event Flow

sequenceDiagram
    participant MM as MusicManager
    participant RS as RpcServer
    participant CC as CoreClient
    participant UI as MainWindow
    
    MM->>RS: Track started
    RS->>RS: Broadcast to all clients
    RS->>CC: WebSocket message
    CC->>CC: Parse event type
    CC-->>UI: Emit trackStarted signal
    UI->>UI: Update now playing

Supported Operations

Playback Control

Action UI Element RPC Method
Play Play button / Search double-click play
Pause Pause button pause
Resume Play button (when paused) resume
Stop Stop button stop
Skip Skip button skip
Seek Progress bar drag seek
Volume Volume slider setVolume

Queue Management

Action UI Element RPC Method
Add to queue Add button / Context menu queueTrack
Remove Delete key / Remove button removeFromQueue
Reorder Drag & drop moveInQueue
Clear Clear button clearQueue
Shuffle Shuffle button toggleShuffle
Repeat Repeat button toggleRepeat
Action UI Element RPC Method
Search Search button searchTracks
Select result Double-click play or queueTrack

Auto-Reconnection

stateDiagram-v2
    Connected --> Disconnected: Connection lost
    Disconnected --> Reconnecting: Auto-retry enabled
    Reconnecting --> Connected: Success
    Reconnecting --> Disconnected: Max retries exceeded
    Reconnecting --> Reconnecting: Retry (delay increases)

Reconnection Strategy:

  1. Detect disconnection
  2. Wait 1 second (increases with each retry)
  3. Attempt reconnection
  4. If successful, restore authentication if previously authenticated
  5. If max retries (5) exceeded, show error dialog

Threading Model

flowchart TB
    subgraph "Main Thread (Qt)"
        UI[UI Updates]
        Signals[Signal/Slot Processing]
    end
    
    subgraph "Qt Network Thread"
        WS[QWebSocket I/O]
    end
    
    subgraph "Callback Thread"
        Handler[Response Handler]
        EventProc[Event Processor]
    end
    
    WS -->|Qt::QueuedConnection| Signals
    Signals --> UI
    Handler -->|Emit signals| Signals
    EventProc -->|Emit signals| Signals

All UI updates happen on the main thread via Qt's signal/slot mechanism.

Error Handling

flowchart TB
    Error{Error Type} --> Net[Network Error]
    Error --> Auth[Auth Error]
    Error --> RPC[RPC Error]
    
    Net -->|Show| Dialog1[Connection Failed Dialog]
    Net -->|Auto| Retry[Retry Connection]
    
    Auth -->|Show| Dialog2[Login Failed Message]
    Auth -->|Clear| Token[Clear Token]
    
    RPC -->|Show| Status[Status Bar Message]

State Synchronization Strategy

1. Polling (Backup)

loop Every 5 seconds
    UI->>CC: Request current state
    CC->>RS: getPlaybackState
    RS-->>CC: State
    CC-->>UI: Update UI
end

2. Event-Driven (Primary)

RS->>CC: playbackStarted event
CC->>UI: Update now playing
RS->>CC: volumeChanged event
CC->>UI: Update volume slider
RS->>CC: trackQueued event
CC->>UI: Add to queue list

3. Optimistic Updates

User->>UI: Click volume up
UI->>UI: Immediately update slider
UI->>CC: setVolume
CC->>RS: RPC call
RS-->>CC: Success
Note over UI,CC: No UI change needed

Multi-Client Support

Multiple desktop clients can connect simultaneously:

flowchart TB
    subgraph "Core RpcServer"
        B[Broadcast Events]
    end
    
    subgraph "Connected Clients"
        C1[Desktop Client 1]
        C2[Desktop Client 2]
        C3[Desktop Client 3]
    end
    
    B --> C1
    B --> C2
    B --> C3
    
    C1 -->|Control| Core
    C2 -->|Control| Core
    C3 -->|Control| Core

All clients receive the same events and stay synchronized.