Add a Gamebase event handler to be called when every events are arrived.
You have to convert the message data to VO below according to the category value.
SERVER_PUSH : Receive messages from the Gamebase server. OBSERVER : This is an event that fires when the launch, login account(hearbeat), or network connection 'status changes', webview event, introspect fail event. PURCHASE_UPDATED : Promotion payment events can be received. PUSH_RECEIVED_MESSAGE : This event operates when a Push message is received. PUSH_CLICK_MESSAGE : This event is executed when the Push message is clicked. PUSH_CLICK_ACTION : This is an event that is triggered when the action button added through the rich message function is clicked.
public void AddEventHandlerSample()
{
}
private void GamebaseEventHandler(GamebaseResponse.Event.GamebaseEventMessage message)
{
switch (message.category)
{
case GamebaseEventCategory.LOGGED_OUT:
{
GamebaseResponse.Event.GamebaseEventLoggedOutData loggedData = GamebaseResponse.Event.GamebaseEventLoggedOutData.From(message.data);
if (loggedData != null)
{
}
break;
}
case GamebaseEventCategory.IDP_REVOKED:
{
GamebaseResponse.Event.GamebaseEventIdPRevokedData idPRevokedData = GamebaseResponse.Event.GamebaseEventIdPRevokedData.From(message.data);
if (idPRevokedData != null)
{
CheckIdpRevoked(idPRevokedData);
}
break;
}
case GamebaseEventCategory.SERVER_PUSH_APP_KICKOUT:
case GamebaseEventCategory.SERVER_PUSH_APP_KICKOUT_MESSAGE_RECEIVED:
case GamebaseEventCategory.SERVER_PUSH_TRANSFER_KICKOUT:
{
GamebaseResponse.Event.GamebaseEventServerPushData serverPushData = GamebaseResponse.Event.GamebaseEventServerPushData.From(message.data);
if (serverPushData != null)
{
CheckServerPush(message.category, serverPushData);
}
break;
}
case GamebaseEventCategory.OBSERVER_LAUNCHING:
{
GamebaseResponse.Event.GamebaseEventObserverData observerData = GamebaseResponse.Event.GamebaseEventObserverData.From(message.data);
if(observerData != null)
{
CheckLaunchingStatus(observerData);
}
break;
}
case GamebaseEventCategory.OBSERVER_NETWORK:
{
GamebaseResponse.Event.GamebaseEventObserverData observerData = GamebaseResponse.Event.GamebaseEventObserverData.From(message.data);
if (observerData != null)
{
CheckNetwork(observerData);
}
break;
}
case GamebaseEventCategory.OBSERVER_HEARTBEAT:
{
GamebaseResponse.Event.GamebaseEventObserverData observerData = GamebaseResponse.Event.GamebaseEventObserverData.From(message.data);
if (observerData != null)
{
CheckHeartbeat(observerData);
}
break;
}
case GamebaseEventCategory.OBSERVER_WEBVIEW:
{
GamebaseResponse.Event.GamebaseEventObserverData observerData = GamebaseResponse.Event.GamebaseEventObserverData.From(message.data);
if (observerData != null)
{
CheckWebView(observerData);
}
break;
}
case GamebaseEventCategory.OBSERVER_INTROSPECT:
{
GamebaseResponse.Event.GamebaseEventObserverData observerData = GamebaseResponse.Event.GamebaseEventObserverData.From(message.data);
int errorCode = observerData.code;
string errorMessage = observerData.message;
break;
}
case GamebaseEventCategory.PURCHASE_UPDATED:
{
GamebaseResponse.Event.PurchasableReceipt purchasableReceipt = GamebaseResponse.Event.PurchasableReceipt.From(message.data);
if (purchasableReceipt != null)
{
}
break;
}
case GamebaseEventCategory.PUSH_RECEIVED_MESSAGE:
{
GamebaseResponse.Event.PushMessage pushMessage = GamebaseResponse.Event.PushMessage.From(message.data);
if (pushMessage != null)
{
}
break;
}
case GamebaseEventCategory.PUSH_CLICK_MESSAGE:
{
GamebaseResponse.Event.PushMessage pushMessage = GamebaseResponse.Event.PushMessage.From(message.data);
if (pushMessage != null)
{
}
break;
}
case GamebaseEventCategory.PUSH_CLICK_ACTION:
{
GamebaseResponse.Event.PushAction pushAction = GamebaseResponse.Event.PushAction.From(message.data);
if (pushAction != null)
{
}
break;
}
}
}
private void CheckIdpRevoked(GamebaseResponse.Event.GamebaseEventIdPRevokedData idPRevokedData)
{
switch (idPRevokedData.code)
{
case GamebaseIdPRevokedCode.WITHDRAW:
{
Gamebase.Withdraw((error) => { });
break;
}
case GamebaseIdPRevokedCode.OVERWRITE_LOGIN_AND_REMOVE_MAPPING:
{
foreach (var idp in idPRevokedData.authMappingList)
{
var additional = new Dictionary<string, object>();
additional.Add(GamebaseAuthProviderCredential.IGNORE_ALREADY_LOGGED_IN, true);
Gamebase.Login(idp, additional, (authToken, loginError) =>
{
if (Gamebase.IsSuccess(loginError) == true)
{
Gamebase.RemoveMapping(idPRevokedData.idPType, (mappingError) => { });
}
});
}
break;
}
case GamebaseIdPRevokedCode.REMOVE_MAPPING:
{
Gamebase.RemoveMapping(idPRevokedData.idPType, (error) => { });
break;
}
}
}
private void CheckServerPush(string category, GamebaseResponse.Event.GamebaseEventServerPushData data)
{
if (category.Equals(GamebaseEventCategory.SERVER_PUSH_APP_KICKOUT) == true)
{
}
else if (category.Equals(GamebaseEventCategory.SERVER_PUSH_APP_KICKOUT_MESSAGE_RECEIVED) == true)
{
}
else if (category.Equals(GamebaseEventCategory.SERVER_PUSH_TRANSFER_KICKOUT) == true)
{
}
}
private void CheckLaunchingStatus(GamebaseResponse.Event.GamebaseEventObserverData observerData)
{
switch (observerData.code)
{
case GamebaseLaunchingStatus.IN_SERVICE:
{
break;
}
case GamebaseLaunchingStatus.INTERNAL_SERVER_ERROR:
{
break;
}
}
}
private void CheckNetwork(GamebaseResponse.Event.GamebaseEventObserverData observerData)
{
switch ((GamebaseNetworkType)observerData.code)
{
case GamebaseNetworkType.TYPE_NOT:
{
break;
}
case GamebaseNetworkType.TYPE_MOBILE:
case GamebaseNetworkType.TYPE_WIFI:
case GamebaseNetworkType.TYPE_ANY:
{
break;
}
}
}
private void CheckHeartbeat(GamebaseResponse.Event.GamebaseEventObserverData observerData)
{
switch (observerData.code)
{
case GamebaseErrorCode.INVALID_MEMBER:
{
break;
}
case GamebaseErrorCode.BANNED_MEMBER:
{
break;
}
}
}
private void CheckWebView(GamebaseResponse.Event.GamebaseEventObserverData observerData)
{
switch (observerData.code)
{
case GamebaseWebViewEventType.OPENED:
{
break;
}
case GamebaseWebViewEventType.CLOSED:
{
break;
}
}
}
static void AddEventHandler(GamebaseCallback.DataDelegate< GamebaseResponse.Event.GamebaseEventMessage > eventHandler)
Add a Gamebase event handler to be called when every events are arrived.
Definition Gamebase.cs:526
The Gamebase class is core of Gamebase service.
Definition Gamebase.cs:11