Skip to main content

Commands & Batch Operations

Send commands to individual devices or execute batch operations across multiple devices.

Source: src/commands/
Permission: MANAGE_REMOTE_CONTROL

Architecture

Single Commands

CommandsService handles individual device commands:

  1. Validate command permissions
  2. Send via EventsService.sendCommandToDevice() (WebSocket)
  3. Store in CommandHistory
  4. Listen for response via commandResponse$ Subject
  5. Update history and notify user via WebSocket

Batch Commands

BatchCommandService handles multi-device operations:

  • Parallel (default) or sequential execution
  • Max 50 concurrent commands
  • Default 30-second timeout per command
  • Progress tracked in-memory via activeBatches Map

Command Permission Levels

// Admin-only (destructive)
ADMIN_ONLY: ['clear_data', 'remote_install', 'factory_reset',
'disable_app', 'uninstall_app', 'change_system_settings',
'modify_security', 'kiosk_mode', 'lock_mode', 'enable_kiosk',
'disable_kiosk', 'reconnect_wifi', 'reset_network']

// Advanced (admin or special permission)
ADVANCED: ['clear_cache', 'force_stop', 'grant_permission',
'revoke_permission', 'change_brightness', 'change_volume',
'update_firmware']

Batch Execution Flow

executeBatchCommand()
├─ Generate batchId
├─ Save to BatchCommand DB record
├─ Sequential mode:
│ └─ Execute one at a time, await each
└─ Parallel mode:
└─ Fire all via MQTT, track in activeBatches Map

Prisma Models

  • CommandHistory — Individual command records
  • BatchCommand — Batch operation metadata
  • BatchCommandResult — Per-device results within a batch
  • EventsModule — WebSocket command delivery and response handling
  • MqttModule — MQTT command delivery
  • RemoteControlModule — Higher-level remote control operations