| 507 | } |
| 508 | |
| 509 | void EventSub::StartServerMigrationClient(const std::string &url) |
| 510 | { |
| 511 | _migrationClient = std::make_unique<EventSubWSClient>(); |
| 512 | SetupClient(*_migrationClient); |
| 513 | |
| 514 | _migrationClient->set_open_handler([this](connection_hdl) { |
| 515 | vblog(LOG_INFO, "Twitch EventSub migration client opened"); |
| 516 | }); |
| 517 | |
| 518 | _migrationClient->set_message_handler([this](connection_hdl hdl, |
| 519 | EventSubWSClient::message_ptr |
| 520 | message) { |
| 521 | const auto msg = ParseWebSocketMessage(message); |
| 522 | if (!msg) { |
| 523 | return; |
| 524 | } |
| 525 | |
| 526 | const auto &type = msg->type; |
| 527 | const auto &data = msg->payload; |
| 528 | |
| 529 | if (type == "session_welcome") { |
| 530 | blog(LOG_INFO, |
| 531 | "Twitch EventSub migration successful - switching to new connection"); |
| 532 | OBSDataAutoRelease session = |
| 533 | obs_data_get_obj(data, "session"); |
| 534 | _migrationSessionID = |
| 535 | obs_data_get_string(session, "id"); |
| 536 | OnServerMigrationWelcome(hdl, _migrationClient); |
| 537 | } else { |
| 538 | OnMessage(hdl, message); |
| 539 | } |
| 540 | }); |
| 541 | |
| 542 | websocketpp::lib::error_code ec; |
| 543 | auto con = _migrationClient->get_connection(url, ec); |
| 544 | if (ec) { |
| 545 | blog(LOG_ERROR, |
| 546 | "Twitch EventSub migration connection failed: %s", |
| 547 | ec.message().c_str()); |
| 548 | _migrating = false; |
| 549 | return; |
| 550 | } |
| 551 | |
| 552 | _migrationConnection = con; |
| 553 | _migrationClient->connect(con); |
| 554 | _migrationClient->run(); |
| 555 | } |
| 556 | |
| 557 | void EventSub::HandleServerMigration(obs_data_t *data) |
| 558 | { |