| 414 | } |
| 415 | |
| 416 | bool GrApplication::PostMessage2RemoteRender(const std::shared_ptr<GrBaseStreamMessage>& msg) { |
| 417 | if (!msg || !msg->stream_item_) { |
| 418 | return false; |
| 419 | } |
| 420 | |
| 421 | auto& item = msg->stream_item_; |
| 422 | if (item->HasRelayInfo()) { |
| 423 | auto srv_remote_device_id = "server_" + item->remote_device_id_; |
| 424 | auto res = relay::RelayApi::NotifyEvent(item->relay_host_, |
| 425 | item->relay_port_, |
| 426 | context_->GetDeviceIdOrIpAddress(), |
| 427 | srv_remote_device_id, |
| 428 | msg->AsJson(), |
| 429 | this->GetAppkey()); |
| 430 | if (res.has_value()) { |
| 431 | if (res.value() == relay::kRelayOk) { |
| 432 | return true; |
| 433 | } |
| 434 | else { |
| 435 | LOGE("NotifyEvent failed, res: {}", res.value()); |
| 436 | } |
| 437 | } |
| 438 | return false; |
| 439 | } |
| 440 | else { |
| 441 | // host & port mode |
| 442 | auto client = HttpClient::Make(item->stream_host_, item->stream_port_, "/panel/stream/message", 3000); |
| 443 | auto res = client->Post({}, msg->AsJson()); |
| 444 | LOGI("res: {} {}", res.status, res.body); |
| 445 | if (res.status == 200) { |
| 446 | try { |
| 447 | auto obj = json::parse(res.body); |
| 448 | auto code = obj["code"].get<int>(); |
| 449 | if (code == 200) { |
| 450 | return true; |
| 451 | } |
| 452 | else { |
| 453 | LOGE("NotifyEvent failed, error code: {}", code); |
| 454 | } |
| 455 | } catch(std::exception& e) { |
| 456 | LOGE("NotifyEvent, parse json failed: {}, body: {}", e.what(), res.body); |
| 457 | } |
| 458 | } |
| 459 | return false; |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | void GrApplication::LoadPanelCompanion() { |
| 464 | auto base_path = QCoreApplication::applicationDirPath(); |
no test coverage detected