Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion source/Assets/Plugins/Didomi/IOS/Didomi.mm
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ void removeSyncAcknowledgedCallback(int eventIndex) {
syncAcknowledgedCallbacks[@(eventIndex)] = nil;
}

void addEventListener( void (*event_listener_handler) (int, char *), void (*sync_ready_event_listener_handler) (int, char *, int, int), void (*integration_error_event_listener_handler) (int, char *, char *))
void addEventListener( void (*event_listener_handler) (int, char *), void (*sync_ready_event_listener_handler) (int, char *, int, int), void (*integration_error_event_listener_handler) (int, char *, char *), void (*show_widget_event_listener_handler) (int, char *, char *))
{

if(eventListener==nil)
Expand Down Expand Up @@ -1107,6 +1107,23 @@ void addEventListener( void (*event_listener_handler) (int, char *), void (*sync

};

// The iOS SDK exposes the property as `widgetID` while the Android SDK uses `widgetId`.
// It is mapped to `widgetId` on the C# side so that both platforms share the same event class.
eventListener.onShowWidget = ^(DDMShowWidgetEvent * event){

char * widgetId = convertNSStringToCString([event widgetID]);
char * layerName = convertNSStringToCString([event layerName]);

show_widget_event_listener_handler(DDMEventTypeShowWidget, widgetId, layerName);

};

eventListener.onHideWidget = ^(DDMHideWidgetEvent * event){

event_listener_handler(DDMEventTypeHideWidget, NULL);

};

[[Didomi shared] addEventListenerWithListener:eventListener];

}
Expand Down
6 changes: 3 additions & 3 deletions source/Assets/Plugins/Didomi/Resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "com.didomi.unityplugin",
"displayName": "Native Didomi",
"agentName": "Didomi Unity SDK",
"version": "2.28.0",
"iosNativeVersion": "2.46.0",
"androidNativeVersion": "2.46.0",
"version": "2.29.0",
"iosNativeVersion": "2.47.0",
"androidNativeVersion": "2.47.0",
"androidxAppCompatVersion": "1.6.1",
"description": "Unity plugin helps you to use native Didomi functionality on Android and iOS."
}
32 changes: 32 additions & 0 deletions source/Assets/Plugins/Didomi/Scripts/Android/EventListenerProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,20 @@ public void integrationError(AndroidJavaObject @event)
// An error occurred during integration process
}

public void showWidget(AndroidJavaObject @event)
{
var ShowWidgetEvent = ConvertToShowWidgetEvent(@event);

_eventListener.OnShowWidget(ShowWidgetEvent);
// A widget is being shown
}

public void hideWidget(AndroidJavaObject @event)
{
_eventListener.OnHideWidget(new HideWidgetEvent());
// A widget is being hidden
}

private static ErrorEvent ConvertToErrorEvent(AndroidJavaObject @event)
{
var errorMessage = GetErrorMessage(@event);
Expand Down Expand Up @@ -455,6 +469,14 @@ private static IntegrationErrorEvent ConvertToIntegrationErrorEvent(AndroidJavaO
return new IntegrationErrorEvent(integrationName, reason);
}

private static ShowWidgetEvent ConvertToShowWidgetEvent(AndroidJavaObject @event)
{
var widgetId = GetWidgetId(@event);
var layerName = GetLayerName(@event);

return new ShowWidgetEvent(widgetId, layerName);
}

private static string GetPurposeId(AndroidJavaObject @event)
{
return AndroidObjectMapper.GetMethodStringValue(@event, "getPurposeId");
Expand Down Expand Up @@ -514,5 +536,15 @@ private static string GetIntegrationName(AndroidJavaObject @event)
{
return AndroidObjectMapper.GetMethodStringValue(@event, "getIntegrationName");
}

private static string GetWidgetId(AndroidJavaObject @event)
{
return AndroidObjectMapper.GetMethodStringValue(@event, "getWidgetId");
}

private static string GetLayerName(AndroidJavaObject @event)
{
return AndroidObjectMapper.GetMethodStringValue(@event, "getLayerName");
}
}
}
20 changes: 20 additions & 0 deletions source/Assets/Plugins/Didomi/Scripts/Events/DidomiEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ public class DidomiEventListener
/// An error occurred in the Didomi SDK integration
/// </summary>
public event EventHandler<IntegrationErrorEvent> IntegrationError;
/// <summary>
/// A widget has been displayed
/// </summary>
public event EventHandler<ShowWidgetEvent> ShowWidget;
/// <summary>
/// A widget has been hidden
/// </summary>
public event EventHandler<HideWidgetEvent> HideWidget;

public DidomiEventListener() { }

Expand Down Expand Up @@ -454,5 +462,17 @@ public void OnIntegrationError(IntegrationErrorEvent @event)
IntegrationError?.Invoke(this, @event);
// An error occurred during Didomi SDK integration
}

public void OnShowWidget(ShowWidgetEvent @event)
{
ShowWidget?.Invoke(this, @event);
// A widget is being shown
}

public void OnHideWidget(HideWidgetEvent @event)
{
HideWidget?.Invoke(this, @event);
// A widget is being hidden
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace IO.Didomi.SDK.Events
{
/// <summary>
/// A widget has been hidden
/// </summary>
public class HideWidgetEvent : Event {
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions source/Assets/Plugins/Didomi/Scripts/Events/ShowWidgetEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace IO.Didomi.SDK.Events
{
/// <summary>
/// A widget has been displayed
/// </summary>
public class ShowWidgetEvent : Event
{
private string widgetId;
private string layerName;

public ShowWidgetEvent(
string widgetId,
string layerName
)
{
this.widgetId = widgetId;
this.layerName = layerName;
}

/// <summary>
/// Identifier of the widget that was displayed, as resolved by the Rules Engine.
/// Null if unknown.
/// </summary>
/// <returns></returns>
public string getWidgetId()
{
return widgetId;
}

/// <summary>
/// Name of the layer at which the widget was displayed.
/// Null if unknown or default.
/// </summary>
/// <returns></returns>
public string getLayerName()
{
return layerName;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions source/Assets/Plugins/Didomi/Scripts/IOS/DDMEventType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public enum DDMEventType
DDMEventTypeDCSSignatureReady = 41,
DDMEventTypeDCSSignatureError = 42,
DDMEventTypeIntegrationError = 43,
// Values 44 to 46 are used by events that are not exposed in the Unity SDK
// (ConsentChangedWithObject, OnConsentUIReady, OnConsentUIFinished).
DDMEventTypeShowWidget = 47,
DDMEventTypeHideWidget = 48,
DDMEventTypeError = 1000,
};
}
24 changes: 22 additions & 2 deletions source/Assets/Plugins/Didomi/Scripts/IOS/DidomiFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,11 @@ static void CallOnReady()

public delegate void OnIntegrationErrorEventListenerDelegate(int eventType, string integrationName, string reason);

public delegate void OnShowWidgetEventListenerDelegate(int eventType, string widgetId, string layerName);

#if (UNITY_IOS || UNITY_TVOS) && !UNITY_EDITOR
[DllImport("__Internal")]
private static extern void addEventListener(OnEventListenerDelegate eventListenerDelegate, OnSyncReadyEventListenerDelegate syncReadyEventListenerDelegate, OnIntegrationErrorEventListenerDelegate integrationErrorEventListenerDelegate);
private static extern void addEventListener(OnEventListenerDelegate eventListenerDelegate, OnSyncReadyEventListenerDelegate syncReadyEventListenerDelegate, OnIntegrationErrorEventListenerDelegate integrationErrorEventListenerDelegate, OnShowWidgetEventListenerDelegate showWidgetEventListenerDelegate);

[DllImport("__Internal")]
private static extern int syncAcknowledgedCallback(int callbackIndex);
Expand All @@ -478,7 +480,7 @@ public static void AddEventListener(DidomiEventListener eventListener)
{
eventListenerInner = eventListener;
#if (UNITY_IOS || UNITY_TVOS) && !UNITY_EDITOR
addEventListener(CallOnEventListenerDelegate, CallOnSyncReadyEventListenerDelegate, CallOnIntegrationErrorEventListenerDelegate);
addEventListener(CallOnEventListenerDelegate, CallOnSyncReadyEventListenerDelegate, CallOnIntegrationErrorEventListenerDelegate, CallOnShowWidgetEventListenerDelegate);
#endif
}

Expand Down Expand Up @@ -616,6 +618,9 @@ static void CallOnEventListenerDelegate(int eventType, string argument)
case DDMEventType.DDMEventTypeDCSSignatureReady:
eventListenerInner.OnDcsSignatureReady(new DcsSignatureReadyEvent());
break;
case DDMEventType.DDMEventTypeHideWidget:
eventListenerInner.OnHideWidget(new HideWidgetEvent());
break;
default:
break;
}
Expand Down Expand Up @@ -663,6 +668,21 @@ static void CallOnIntegrationErrorEventListenerDelegate(int eventType, string in
}
}

[AOT.MonoPInvokeCallback(typeof(OnShowWidgetEventListenerDelegate))]
static void CallOnShowWidgetEventListenerDelegate(int eventType, string widgetId, string layerName)
{
DDMEventType eventTypeEnum = (DDMEventType)eventType;
switch (eventTypeEnum)
{
case DDMEventType.DDMEventTypeShowWidget:
eventListenerInner.OnShowWidget(new ShowWidgetEvent(
widgetId,
layerName
));
break;
}
}

public delegate void OnVendorStatusListenerDelegate(string vendorStatus);

#if (UNITY_IOS || UNITY_TVOS) && !UNITY_EDITOR
Expand Down
12 changes: 12 additions & 0 deletions source/Assets/Scripts/DidomiSample/DemoGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,8 @@ private void RegisterEventHandlers()
eventListener.SyncError += EventListener_SyncError;
eventListener.LanguageUpdated += EventListener_LanguageUpdated;
eventListener.LanguageUpdateFailed += EventListener_LanguageUpdateFailed;
eventListener.ShowWidget += EventListener_ShowWidget;
eventListener.HideWidget += EventListener_HideWidget;

Didomi.GetInstance().AddEventListener(eventListener);
}
Expand Down Expand Up @@ -958,6 +960,16 @@ private void EventListener_LanguageUpdateFailed(object sender, LanguageUpdateFai
message += "\nEvent: LanguageUpdateFailed, Reason=" + e.getReason();
}

private void EventListener_ShowWidget(object sender, ShowWidgetEvent e)
{
message += "\nEvent: ShowWidget, WidgetId=" + e.getWidgetId() + ", LayerName=" + e.getLayerName();
}

private void EventListener_HideWidget(object sender, HideWidgetEvent e)
{
message += "\nEvent: HideWidget";
}

private void VendorStatusListener_VendorStatusChanged(object sender, CurrentUserStatus.VendorStatus status)
{
message += "\nEvent: VendorStatusChanged, VendorId=" + status.Id + ", Enabled=" + status.Enabled;
Expand Down