Skip to content

Commit

Permalink
fix: remove adData from response if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
avencat committed Nov 23, 2023
1 parent e8fe11c commit 2bcd09b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,10 @@ public void receiveAdEvent(String event, Map<String, String> adData) {
}

public void receiveAdEvent(String event) {
this.receiveAdEvent(event, Map.of());
WritableMap map = Arguments.createMap();
map.putString("event", event);

receiveEvent(EVENT_ON_RECEIVE_AD_EVENT, map);
}

private void receiveEvent(@VideoEvents String type, WritableMap event) {
Expand Down
18 changes: 11 additions & 7 deletions docs/pages/component/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ Enum `AdEvent` possible values for [Android](https://developers.google.com/inter
| `AD_PROGRESS` | Android | Fires when the ad's current time value changes. Calling getAdData() on this event will return an AdProgressData object. |
| `ALL_ADS_COMPLETED` | Android, iOS | Fires when the ads manager is done playing all the valid ads in the ads response, or when the response doesn't return any valid ads. |
| `CLICK` | Android, iOS | Fires when the ad is clicked. |
| `COMPLETE` | Android, iOS | Fires when the ad completes playing. |
| `COMPLETED` | Android, iOS | Fires when the ad completes playing. |
| `CONTENT_PAUSE_REQUESTED` | Android | Fires when content should be paused. This usually happens right before an ad is about to cover the content. |
| `CONTENT_RESUME_REQUESTED` | Android | Fires when content should be resumed. This usually happens when an ad finishes or collapses. |
| `CUEPOINTS_CHANGED` | iOS | Cuepoints changed for VOD stream (only used for dynamic ad insertion). |
Expand Down Expand Up @@ -395,14 +395,18 @@ Enum `AdEvent` possible values for [Android](https://developers.google.com/inter

Payload:

| Property | Type | Description |
|----------|---------|-----------------------|
| event | AdEvent | The ad event received |
| Property | Type | Description |
|----------|-------------------------------------|-----------------------|
| event | AdEvent | The ad event received |
| adData | Record<string, string> \| undefined | The ad event data |

Example:
```javascript
```json
{
"event": "LOADED"
"adData": {
"key": "value"
},
"event": "LOG"
}
```

Expand Down Expand Up @@ -540,4 +544,4 @@ Example:
}
```

Platforms: Android, iOS
Platforms: Android, iOS
17 changes: 12 additions & 5 deletions ios/Video/Features/RCTIMAAdsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,18 @@ class RCTIMAAdsManager: NSObject, IMAAdsLoaderDelegate, IMAAdsManagerDelegate, I
if _video.onReceiveAdEvent != nil {
let type = convertEventToString(event: event.type)

_video.onReceiveAdEvent?([
"event": type,
"adData": event.adData ?? [String](),
"target": _video.reactTag!
]);
if (event.adData != nil) {
_video.onReceiveAdEvent?([
"event": type,
"adData": event.adData ?? [String](),
"target": _video.reactTag!
]);
} else {
_video.onReceiveAdEvent?([
"event": type,
"target": _video.reactTag!
]);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/VideoNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export type OnPictureInPictureStatusChangedData = Readonly<{
}>;

export type OnReceiveAdEventData = Readonly<{
adData: Record<string, string>;
adData?: Record<string, string>;
event: AdEvent;
}>;

Expand Down
2 changes: 1 addition & 1 deletion src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export type OnPictureInPictureStatusChangedData = Readonly<{
}>;

export type OnReceiveAdEventData = Readonly<{
adData: Record<string, string>;
adData?: Record<string, string>;
event: AdEvent;
}>;

Expand Down

0 comments on commit 2bcd09b

Please sign in to comment.