* @brief Processes frames by serializing them to JSON and writing to sockets */
| 282 | * @brief Processes frames by serializing them to JSON and writing to sockets |
| 283 | */ |
| 284 | void API::ServerWorker::processItems(const std::vector<DataModel::TimestampedFramePtr>& items) |
| 285 | { |
| 286 | Q_ASSERT(!items.empty()); |
| 287 | |
| 288 | if (items.empty() || m_sockets.isEmpty()) |
| 289 | return; |
| 290 | |
| 291 | QJsonArray array; |
| 292 | for (const auto& timestampedFrame : items) { |
| 293 | QJsonObject object; |
| 294 | object.insert(QStringLiteral("data"), serialize(timestampedFrame->data)); |
| 295 | array.append(object); |
| 296 | } |
| 297 | |
| 298 | QJsonObject object; |
| 299 | object.insert(QStringLiteral("frames"), array); |
| 300 | const QJsonDocument document(object); |
| 301 | const auto json = document.toJson(QJsonDocument::Compact) + "\n"; |
| 302 | |
| 303 | for (auto* socket : std::as_const(m_sockets)) |
| 304 | if (socket && socket->isWritable()) |
| 305 | socket->write(json); |
| 306 | } |
| 307 | |
| 308 | //-------------------------------------------------------------------------------------------------- |
| 309 | // Server implementation |