Skip to content

Commit

Permalink
Track CSAI ad media failures (#33)
Browse files Browse the repository at this point in the history
* Track CSAI ad media failures

* tests too
  • Loading branch information
daytime-em authored Apr 4, 2024
1 parent 4e2627a commit 045814b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Example/DemoAppTests/MuxImaListener_Test.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,24 @@ @interface MuxMockImaAdEvent : IMAAdEvent {
enum IMAAdEventType type;
}
@property (nonatomic) enum IMAAdEventType type;
@property(nonatomic, copy, nullable) NSDictionary<NSString *, id> *adData;
@end

@implementation MuxMockImaAdEvent

@synthesize type;
@synthesize adData;

- (id)initWithType:(NSInteger)_type {
type = _type;
return self;
}

- (id)initWithType:(NSInteger)_type andAdData:(NSDictionary*)_adData {
type = _type;
adData = _adData;
return self;
}
@end

SpecBegin(InitialSpecs)
Expand Down Expand Up @@ -118,6 +126,26 @@ - (id)initWithType:(NSInteger)_type {
MUXSDKPlaybackEvent *playbackEvent = [imaListener dispatchEvent:adEvent];
expect(playbackEvent).to.beKindOf([MUXSDKAdPauseEvent class]);
});

it(@"should not dispatch aderror for LOG event *without* error info", ^{
MuxMockImaAdEvent *adEvent = [[MuxMockImaAdEvent alloc] initWithType:kIMAAdEvent_LOG];
MUXSDKPlaybackEvent *playbackEvent = [imaListener dispatchEvent:adEvent];
expect(playbackEvent).to.beNil();
});

it(@"should dispatch aderror for LOG event with error info", ^{
NSMutableDictionary *mockErrorData = [[NSMutableDictionary alloc] init];
[mockErrorData setObject:[NSNumber numberWithInt:110] forKey:@"errorCode"];
[mockErrorData setObject:@"mock message" forKey:@"errorMessage"];
[mockErrorData setObject:@"adPlayError" forKey:@"type"];
NSMutableDictionary *mockLogData = [[NSMutableDictionary alloc] init];
[mockLogData setObject:mockErrorData forKey:@"logData"];

MuxMockImaAdEvent *adEvent = [[MuxMockImaAdEvent alloc] initWithType:kIMAAdEvent_LOG andAdData:mockLogData];

MUXSDKPlaybackEvent *playbackEvent = [imaListener dispatchEvent:adEvent];
expect(playbackEvent).to.beKindOf([MUXSDKAdErrorEvent class]);
});

it(@"should not dispatch an event for kIMAAdEvent_TAPPED", ^{
MuxMockImaAdEvent *adEvent = [[MuxMockImaAdEvent alloc] initWithType:kIMAAdEvent_TAPPED];
Expand Down
13 changes: 13 additions & 0 deletions MUXSDKImaListener/Classes/MuxImaListener.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ - (void)setupAdViewData:(MUXSDKAdEvent *)event withAd:(IMAAd *)ad {

- (MUXSDKAdEvent *_Nullable) dispatchEvent:(IMAAdEvent *)event {
MUXSDKAdEvent *playbackEvent;

NSDictionary *adData = event.adData;

switch(event.type) {
case kIMAAdEvent_STARTED:
if (_sendAdplayOnStarted) {
Expand Down Expand Up @@ -95,6 +98,16 @@ - (MUXSDKAdEvent *_Nullable) dispatchEvent:(IMAAdEvent *)event {
[_playerBinding dispatchAdEvent: playbackEvent];
playbackEvent = [MUXSDKAdPlayingEvent new];
break;
case kIMAAdEvent_LOG:
if (adData && adData[@"logData"]) {
NSDictionary *errorLog = (NSDictionary *)adData[@"logData"];
if (errorLog) {
if (errorLog[@"errorCode"] || errorLog[@"errorMessage"] || errorLog[@"type"]) {
playbackEvent = [[MUXSDKAdErrorEvent alloc] init];
}
}
}
break;
default:
break;
}
Expand Down

0 comments on commit 045814b

Please sign in to comment.