diff --git a/schema/matches.h b/schema/matches.h index 47149c2..6a658dc 100644 --- a/schema/matches.h +++ b/schema/matches.h @@ -210,7 +210,6 @@ namespace gamelink struct MUXY_GAMELINK_API MatchPollUpdate : ReceiveEnvelope {}; - struct MatchPollUpdateInformationInternal { string matchId; diff --git a/test/integration.cpp b/test/integration.cpp index 1aa31ec..871f579 100644 --- a/test/integration.cpp +++ b/test/integration.cpp @@ -373,7 +373,6 @@ TEST_CASE_METHOD(IntegrationTestFixture, "Transactions Support", "[.][integratio REQUIRE(calls == 6); } - TEST_CASE_METHOD(IntegrationTestFixture, "Transactions Support through gateway", "[.][integration][t]") { Connect(); @@ -384,14 +383,14 @@ TEST_CASE_METHOD(IntegrationTestFixture, "Transactions Support through gateway", // This should get 1 call, to purchase 50 coins. REQUIRE(used.SKU == "muxy-bits-50"); REQUIRE(used.Bits == 50); - + bitsCalls++; }); size_t coinCalls = 0; gateway.OnActionUsed([&](const gateway::ActionUsed& used) { - // This should get 5 calls, which are all coins + // This should get 5 calls, which are all coins REQUIRE(used.ActionID == "costs-ten"); REQUIRE(used.Cost == 10); @@ -519,6 +518,53 @@ TEST_CASE_METHOD(IntegrationTestFixture, "Datastream operations", "[.][integrati REQUIRE(events == 6); } +TEST_CASE_METHOD(IntegrationTestFixture, "Matches and polls", "[.][integration]") +{ + Connect(); + + sdk.CreateMatch("my-cool-match"); + + sdk.AddChannelsToMatch("my-cool-match", { + "26052853", "89319907", "89368629", "89368745", "124708734" + }); + + size_t updateCalls = 0; + auto update = [&updateCalls](const gamelink::schema::MatchPollUpdate& update) + { + updateCalls++; + }; + + size_t finishCalls = 0; + auto finish = [&finishCalls](const gamelink::schema::MatchPollUpdate& finish) + { + finishCalls++; + }; + + gamelink::PollConfiguration config; + config.startsIn = 0; + config.endsIn = 5; + + gamelink::RequestId waiter = sdk.RunMatchPoll("my-cool-match", "what-to-eat", + "How many pizzas should I buy?", + config, + { "one", "two", "twenty" }, + update, + finish + ); + + Sleep(1); + + nlohmann::json voteValue; + voteValue["value"] = 1; + nlohmann::json unused; + + Request("POST", "vote?id=what-to-eat", &voteValue, &unused); + Sleep(6); + + REQUIRE(updateCalls > 0); + REQUIRE(finishCalls == 1); +} + TEST_CASE_METHOD(IntegrationTestFixture, "Client IP access", "[.][integration]") { int code; diff --git a/test/integration_utils.cpp b/test/integration_utils.cpp index ed99fb8..af1689d 100644 --- a/test/integration_utils.cpp +++ b/test/integration_utils.cpp @@ -59,7 +59,7 @@ void IntegrationTestFixture::Connect() std::string token = resp["token"]; gamelink::RequestId req = sdk.AuthenticateWithGameIDAndPIN( - gamelink::string(client.c_str()), + gamelink::string(client.c_str()), gamelink::string("Mystery Fun House"), gamelink::string(token.c_str()) ); @@ -68,7 +68,7 @@ void IntegrationTestFixture::Connect() else { gamelink::RequestId req = sdk.AuthenticateWithGameIDAndRefreshToken( - gamelink::string(client.c_str()), + gamelink::string(client.c_str()), gamelink::string("Mystery Fun House"), gamelink::string(refreshToken.c_str()) ); @@ -251,28 +251,28 @@ void IntegrationTestFixture::LoadEnvironment() } target = "sandbox"; - targetDomain = "sandbox.muxy.io"; + apiUrl = "https://sandbox.muxy.io"; + websocketUrl = "gamelink.sandbox.muxy.io"; + const char * targetEnv = std::getenv("MUXY_INTEGRATION_TARGET"); if (targetEnv) { - if (std::string(targetEnv) != "production") + target = std::string(targetEnv); + if (target == "localhost") { - target = std::string(targetEnv); - targetDomain = target + ".muxy.io"; - } else + apiUrl = "http://localhost:5050"; + websocketUrl = "localhost:5051"; + } + else if (std::string(targetEnv) != "production") { - target = "production"; - targetDomain = "muxy.io"; + apiUrl = "https://" + target + ".muxy.io"; + websocketUrl = "gamelink." + target + ".muxy.io"; + } + else + { + apiUrl = "https://api.muxy.io"; + websocketUrl = "gamelink.muxy.io"; } - } - REQUIRE(targetDomain.size()); - - targetPrefix = ""; - const char * prefixEnv = std::getenv("MUXY_INTEGRATION_OLD_URLS"); - if (prefixEnv && std::string(prefixEnv) == "true") - { - targetPrefix = target + "."; - targetDomain = "muxy.io"; } signature = ""; @@ -288,9 +288,8 @@ void IntegrationTestFixture::Reconnect() ForceDisconnect(); char buffer[256]; - int output = snprintf(buffer, 256, "%sgamelink.%s/%d.%d.%d/%s", - targetPrefix.c_str(), - targetDomain.c_str(), + int output = snprintf(buffer, 256, "%s/%d.%d.%d/%s", + websocketUrl.c_str(), MUXY_GAMELINK_VERSION_MAJOR, MUXY_GAMELINK_VERSION_MINOR, MUXY_GAMELINK_VERSION_PATCH, client.c_str()); @@ -342,9 +341,8 @@ int IntegrationTestFixture::Request(const char* method, const char* endpoint, co } char buffer[256]; - int writtenBytes = snprintf(buffer, 256, "https://%sapi.%s/v1/e/%s", - targetPrefix.c_str(), - targetDomain.c_str(), + int writtenBytes = snprintf(buffer, 256, "%s/v1/e/%s", + apiUrl.c_str(), endpoint); REQUIRE(writtenBytes > 0); diff --git a/test/integration_utils.h b/test/integration_utils.h index f470fa8..2537a93 100644 --- a/test/integration_utils.h +++ b/test/integration_utils.h @@ -40,9 +40,8 @@ class IntegrationTestFixture void LoadEnvironment(); std::string target; - - std::string targetDomain; - std::string targetPrefix; + std::string apiUrl; + std::string websocketUrl; std::string authenticationHeader; std::unique_ptr connection; diff --git a/websocket_network/websocket.cpp b/websocket_network/websocket.cpp index 1cee9ea..6dba5c7 100644 --- a/websocket_network/websocket.cpp +++ b/websocket_network/websocket.cpp @@ -45,7 +45,7 @@ size_t writeResponse(char* ptr, size_t size, size_t nmemb, void* data) char* start = impl->messageFragment.data() + oldSize; memcpy(start, ptr, size * nmemb); - + curl_ws_frame* frame = curl_ws_meta(impl->connection); if (frame->bytesleft > 0) { @@ -94,6 +94,11 @@ WebsocketConnection::WebsocketConnection(const std::string& url, uint16_t port) CURL* curl = curl_easy_init(); std::string protocolURL = "wss://" + url; + if (url.rfind("localhost", 0) == 0) + { + protocolURL = "ws://" + url; + } + curl_easy_setopt(curl, CURLOPT_URL, protocolURL.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeResponse); curl_easy_setopt(curl, CURLOPT_WRITEDATA, impl); @@ -185,11 +190,11 @@ int WebsocketConnection::run() size_t sent = 0; CURLcode result = curl_ws_send( - impl->connection, - msg->data.data(), - msg->data.size(), - &sent, - 0, + impl->connection, + msg->data.data(), + msg->data.size(), + &sent, + 0, flags ); @@ -218,7 +223,7 @@ void WebsocketConnection::send(const char* bytes, uint32_t length) std::unique_ptr msg = std::unique_ptr(new Message()); msg->binary = false; msg->data = std::vector(bytes, bytes + length); - + std::lock_guard lock(impl->lock); impl->messages.push_back(std::move(msg)); }