Created
June 29, 2022 22:58
-
-
Save ufna/e018e0f6ee5ed686059da76d8ad614b2 to your computer and use it in GitHub Desktop.
Emscripten -> Module control from c++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool UMyWebSocketNetDriver::InitConnect(FNetworkNotify* InNotify, const FURL& ConnectURL, FString& Error) | |
{ | |
const auto GameSettings = FMyGameModule::Get().GetGameSettings(); | |
FString ConnectionURL = FString::Printf(TEXT("%s/%s:%i/"), *GameSettings->DefaultWebSocketServer, *ConnectURL.Host, ConnectURL.Port); | |
if (ConnectURL.Op.Num() > 0) | |
{ | |
ConnectionURL += TEXT("?"); | |
for (int32 i = 0; i < ConnectURL.Op.Num(); ++i) | |
{ | |
if (i > 0) | |
{ | |
ConnectionURL += TEXT("&"); | |
} | |
ConnectionURL += ConnectURL.Op[i]; | |
} | |
} | |
UE_LOG(LogMyNetwork, Log, TEXT("%s: Connecting websocket to: %s"), *MY_FUNC_LINE, *ConnectionURL); | |
#ifdef __EMSCRIPTEN__ | |
EM_ASM({ | |
Module['websocket']['url'] = UTF8ToString($0); | |
console.log("WEBSOCKET_URL [" + UTF8ToString($0) + "]"); | |
}, | |
TCHAR_TO_UTF8(*ConnectionURL)); | |
#endif | |
const bool bResult = Super::InitConnect(InNotify, ConnectURL, Error); | |
if (bResult == false) | |
{ | |
#ifdef __EMSCRIPTEN__ | |
EM_ASM({ | |
Module['websocket']['url'] = "ws://"; | |
console.log("WEBSOCKET_URL [DEFAULT]"); | |
}); | |
#endif | |
} | |
return bResult; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment