Register callback function for receiving events
This section explains the types of events received from Remote Play, the process of receiving them, and how to register callback functions in the SDK to handle these events.
Event Reception Process¶
By registering a callback function in the SDK, the host PC game can receive status events and chat events from Remote Play.
Receiving Status Events¶
Status events occur when Remote Play starts or ends, allowing the host PC game to implement different behaviors accordingly. For example, if there are features that cannot be used during Remote Play, such as 'payment' or 'logout', you can display a popup notifying the user that these features are unavailable when the Remote Play start event is received.
Examples of handling Remote Play status events in the host PC game include:
- Hiding the mouse cursor when Remote Play starts and showing it again when Remote Play ends.
- Displaying a popup to inform users that the cash shop is unavailable when Remote Play starts.
Receiving Chat Events¶
When a user enters a chat message in the Remote Play session, the host PC game receives the chat string and sends it to the in-game chat window, enabling the Remote Play chat feature.
The process for implementing the Remote Play chat feature by receiving chat events is as follows:
1) When the user enters a string in the text box on the Remote Play web interface and presses the Enter key, the string is sent to the host PC game as shown below. * The maximum input length for remote play is 150 characters, and the reading directions are LTR (Left to Right) and RTL (Right to Left).
2) In host PC games, strings are received through pre-registered callback functions.
3) In host PC games, the corresponding string is passed to the game chat window.
Registering Callback Functions¶
To receive events from Remote Play, you must import the Remote Play plugin into the SDK and register a callback function.
Once the callback function is registered, the host PC game is ready to receive events during Remote Play. The game can then analyze each received event and apply it according to its environment.
Below is an example of how to register a callback function in the SDK. Register your callback function using HiveRemotePlayManager.RegisterCallback.
using AOT; // Required for MonoPInvokeCallback
public class {YourCustomClass} : MonoBehaviour { // YourCustomClass: Class used in your user game
#if !UNITY_EDITOR && UNITY_STANDALONE_WIN
[MonoPInvokeCallback (typeof(HiveRemotePlayManager.RemotePlayCallbackType))]
public static void RegisterRemoteCallbackFunction(int type, string remotePlayJsonData)
{
Debug.Log("REMOTE Callback DATA :" + remotePlayJsonData); // Receiving json data sent from RemoteSDK.
}
#endif
void Start() {
#if !UNITY_EDITOR && UNITY_STANDALONE_WIN
HiveRemotePlayManager.RegisterCallback(RegisterRemoteCallbackFunction);
#endif
}
}
Add the following content to [Your_Project_Root]/Source/[Your_Project_Name]/[Your_Project_Name].build.cs. Replace [Your_Project_Name] with the actual name of your project.
public class <Your_Project_Name> : ModuleRules
{
public <Your_Project_Name>(ReadOnlyTargetRules Target) : base(Target)
{
...
PublicDependencyModuleNames.AddRange(new string[] { "HiveRemotePlay" });
...
}
}
An example of the code used during project implementation is as follows.
#include "RemotePluginInterface.h" // Required in the project's build.cs: PublicDependencyModuleNames.AddRange(new string[] { "HiveRemotePlay" });
// Example API 1. Temporal API Name
void SendRemotePlayKeyCallback(int _type, const char* _pData) {
UE_LOG(LogTemp, VeryVerbose, TEXT("==================SendRemotePlayKeyCallback================\n"));
char typeBuffer[35];
char* typeStr;
typeStr = _itoa(_type, typeBuffer, 10);
UE_LOG(LogTemp, VeryVerbose, TEXT("type : %s \n"), *FString(typeStr));
UE_LOG(LogTemp, VeryVerbose, TEXT("type : %s \n"), *FString(_pData)); // Example: {"version":"1.0.250300","eventType":"Message","eventValue":{"value":"MTFIZWxsbyBrZXkgaW5wdXQgMQ==","action":"LTR"},"etc":{}}
}
// Example API 2. Call this API after signing in, EX) inner sign-in Callback
void RegisterHiveRemoteCallback {
RegisterCallback(SendRemotePlayKeyCallback);
}
Event protocol¶
This section describes the protocol for status events and chat events received through the callback function in the game.
JSON protocol¶
Key | Value Type | Description | ETC | |
---|---|---|---|---|
version | version | number | Json version information | Refer to example |
eventType | eventType | string | Event type - includes "Event" and "Message" values | Refer to example |
eventValue | eventValue | object | Event value object | Refer to example |
eventValue - value | eventValue - value | string | Event value | Refer to example |
eventValue - action | eventValue - action | string | Event action | Refer to example |
etc | etc | object | For extension purposes | Refer to example |
Status Event Data Example¶
Below is an example of status event data.
{
"version" : "1.0.2411.0",
"eventType" : "Event",
"eventValue" : {
"value" : "REMOTE_PLAY_CONNECTED"
},
"etc" : { }
}
// value : REMOTE_PLAY_CONNECTED, REMOTE_PLAY_DISCONNECTED
Chat Event Data Example¶
The received chat string is encoded in UTF-8 and then converted to Base64
. It also includes reading direction information to support multiple languages.
Below is an example of chat event data.
{
"version" : "1.0.2411.0",
"eventType" : "Message" ,
"eventValue" : {
"value" : "Something Message",
"action" : "LTR | RTL"
},
"etc" : { }
}
// value : Base64 (UTF-8 문장) 인코딩
// action : LTR (아랍어를 제외한 문자) | RTL (아랍어)