Skip to content

Commit

Permalink
add overloaded emit with second param as TEXT() supported
Browse files Browse the repository at this point in the history
- needed a macro to handle the two possible text types wchar_t and char16_t
  • Loading branch information
getnamo committed Aug 1, 2019
1 parent 0bc6e1f commit be484fe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SocketIOClient.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "1.0.10",
"VersionName": "1.0.11",
"EngineVersion" : "4.22.0",
"FriendlyName": "Socket.IO Client",
"Description": "Real-time networking library Socket.IO Client usable from blueprints and c++.",
Expand Down
7 changes: 7 additions & 0 deletions Source/SocketIOClient/Private/SocketIONative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ void FSocketIONative::Emit(const FString& EventName, TFunction< void(const TArra
Emit(EventName, NoneValue, CallbackFunction, Namespace);
}

void FSocketIONative::Emit(const FString& EventName, const SIO_TEXT_TYPE StringMessage /*= TEXT("")*/, TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction /*= nullptr*/, const FString& Namespace /*= TEXT("/")*/)
{
//#if !PLATFORM_TCHAR_IS_CHAR16
Emit(EventName, MakeShareable(new FJsonValueString(FString(StringMessage))), CallbackFunction, Namespace);
//#endif
}

void FSocketIONative::EmitRaw(const FString& EventName, const sio::message::list& MessageList /*= nullptr*/, TFunction<void(const sio::message::list&)> CallbackFunction /*= nullptr*/, const FString& Namespace /*= FString(TEXT("/"))*/)
{
const TFunction<void(const sio::message::list&)> SafeFunction = CallbackFunction;
Expand Down
24 changes: 24 additions & 0 deletions Source/SocketIOClient/Public/SocketIONative.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,30 @@ class SOCKETIOCLIENT_API FSocketIONative
TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
const FString& Namespace = TEXT("/"));


//flexible type allowing TEXT() passed as second param for overloaded emit
#if !defined(SIO_TEXT_TYPE)
#if PLATFORM_TCHAR_IS_CHAR16
#define SIO_TEXT_TYPE char16_t*
#else
#define SIO_TEXT_TYPE wchar_t*
#endif
#endif

/**
* (Overloaded) Emit an event with a string literal message
*
* @param EventName Event name
* @param StringMessage Message in string format
* @param CallbackFunction Optional callback TFunction
* @param Namespace Optional Namespace within socket.io
*/
void Emit(
const FString& EventName,
const SIO_TEXT_TYPE StringMessage = TEXT(""),
TFunction< void(const TArray<TSharedPtr<FJsonValue>>&)> CallbackFunction = nullptr,
const FString& Namespace = TEXT("/"));

/**
* (Overloaded) Emit an event with a number (double) message
*
Expand Down

0 comments on commit be484fe

Please sign in to comment.