* @brief Set input device */
| 126 | * @brief Set input device |
| 127 | */ |
| 128 | API::CommandResponse API::Handlers::AudioHandler::setInputDevice(const QString& id, |
| 129 | const QJsonObject& params) |
| 130 | { |
| 131 | if (!params.contains(QStringLiteral("deviceIndex"))) { |
| 132 | return CommandResponse::makeError( |
| 133 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: deviceIndex")); |
| 134 | } |
| 135 | |
| 136 | const int device_index = params.value(QStringLiteral("deviceIndex")).toInt(); |
| 137 | |
| 138 | const auto& devices = IO::ConnectionManager::instance().audio()->inputDeviceList(); |
| 139 | if (device_index < 0 || device_index >= devices.count()) { |
| 140 | return CommandResponse::makeError( |
| 141 | id, |
| 142 | ErrorCode::InvalidParam, |
| 143 | QString(QStringLiteral("Invalid deviceIndex: %1. Valid range: 0-%2")) |
| 144 | .arg(device_index) |
| 145 | .arg(devices.count() - 1)); |
| 146 | } |
| 147 | |
| 148 | IO::ConnectionManager::instance().audio()->setSelectedInputDevice(device_index); |
| 149 | |
| 150 | QJsonObject result; |
| 151 | result[QStringLiteral("deviceIndex")] = device_index; |
| 152 | result[QStringLiteral("deviceName")] = devices.at(device_index); |
| 153 | return CommandResponse::makeSuccess(id, result); |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * @brief Set output device |
nothing calls this directly
no test coverage detected