Skip to content

Commit

Permalink
feat: remove onAdError event listener and use already existing
Browse files Browse the repository at this point in the history
  • Loading branch information
avencat committed Nov 27, 2023
1 parent 09993c2 commit 90d1ca7
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public VideoEventEmitter(ReactContext reactContext) {
private static final String EVENT_TEXT_TRACKS = "onTextTracks";
private static final String EVENT_VIDEO_TRACKS = "onVideoTracks";
private static final String EVENT_ON_RECEIVE_AD_EVENT = "onReceiveAdEvent";
private static final String EVENT_ON_AD_ERROR = "onAdError";

static public final String[] Events = {
EVENT_LOAD_START,
Expand Down Expand Up @@ -85,8 +84,7 @@ public VideoEventEmitter(ReactContext reactContext) {
EVENT_TEXT_TRACKS,
EVENT_VIDEO_TRACKS,
EVENT_BANDWIDTH,
EVENT_ON_RECEIVE_AD_EVENT,
EVENT_ON_AD_ERROR
EVENT_ON_RECEIVE_AD_EVENT
};

@Retention(RetentionPolicy.SOURCE)
Expand Down Expand Up @@ -116,8 +114,7 @@ public VideoEventEmitter(ReactContext reactContext) {
EVENT_TEXT_TRACKS,
EVENT_VIDEO_TRACKS,
EVENT_BANDWIDTH,
EVENT_ON_RECEIVE_AD_EVENT,
EVENT_ON_AD_ERROR
EVENT_ON_RECEIVE_AD_EVENT
})
@interface VideoEvents {
}
Expand Down Expand Up @@ -426,11 +423,15 @@ public void receiveAdEvent(String event) {

public void receiveAdErrorEvent(AdError error) {
WritableMap map = Arguments.createMap();
map.putString("message", error.getMessage());
map.putString("code", String.valueOf(error.getErrorCode()));
map.putString("type", String.valueOf(error.getErrorType()));
map.putString("event", "ERROR");

receiveEvent(EVENT_ON_AD_ERROR, map);
WritableMap dataMap = Arguments.createMap();
dataMap.putString("message", error.getMessage());
dataMap.putString("code", String.valueOf(error.getErrorCode()));
dataMap.putString("type", String.valueOf(error.getErrorType()));
map.putMap("data", dataMap);

receiveEvent(EVENT_ON_RECEIVE_AD_EVENT, map);
}

private void receiveEvent(@VideoEvents String type, WritableMap event) {
Expand Down
14 changes: 0 additions & 14 deletions docs/pages/component/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ This page shows the list of available callbacks to handle player notifications
## List
| Name | Platforms Support |
|-------------------------------------------------------------------------------------------------|---------------------------|
| [onAdError](#onaderror) | Android, iOS |
| [onAudioBecomingNoisy](#onaudiobecomingnoisy) | Android, iOS |
| [onAudioFocusChanged](#onaudiofocuschanged) | Android |
| [onAudioTracks](#onaudiotracks) | Android |
Expand Down Expand Up @@ -34,19 +33,6 @@ This page shows the list of available callbacks to handle player notifications


## Details
### `onAdError`
Callback function that is called when an ad from the IMA's sdk fails to launch.

Payload:

| Property | Type | Description |
|----------|--------|-------------------|
| code | string | The error code |
| message | string | The error message |
| type | string | The error type |

Platforms: Android, iOS

### `onAudioBecomingNoisy`
Callback function that is called when the audio is about to become 'noisy' due to a change in audio outputs. Typically this is called when audio output is being switched from an external source like headphones back to the internal speaker. It's a good idea to pause the media when this happens so the speaker doesn't start blasting sound.

Expand Down
13 changes: 8 additions & 5 deletions ios/Video/Features/RCTIMAAdsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,14 @@ class RCTIMAAdsManager: NSObject, IMAAdsLoaderDelegate, IMAAdsManagerDelegate, I

guard let _video = _video else {return}

if _video.onAdError != nil {
_video.onAdError?([
"message": error.message ?? "",
"code": error.code,
"type": error.type,
if _video.onReceiveAdEvent != nil {
_video.onReceiveAdEvent?([
"event": "ERROR",
"data": [
"message": error.message ?? "",
"code": error.code,
"type": error.type,
],
"target": _video.reactTag!
])
}
Expand Down
1 change: 0 additions & 1 deletion ios/Video/RCTVideo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
@objc var onRestoreUserInterfaceForPictureInPictureStop: RCTDirectEventBlock?
@objc var onGetLicense: RCTDirectEventBlock?
@objc var onReceiveAdEvent: RCTDirectEventBlock?
@objc var onAdError: RCTDirectEventBlock?

@objc func _onPictureInPictureStatusChanged() {
onPictureInPictureStatusChanged?([ "isActive": NSNumber(value: true)])
Expand Down
1 change: 0 additions & 1 deletion ios/Video/RCTVideoManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ @interface RCT_EXTERN_MODULE(RCTVideoManager, RCTViewManager)
RCT_EXPORT_VIEW_PROPERTY(onPictureInPictureStatusChanged, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onRestoreUserInterfaceForPictureInPictureStop, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onReceiveAdEvent, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onAdError, RCTDirectEventBlock);

RCT_EXTERN_METHOD(save:(NSDictionary *)options
reactTag:(nonnull NSNumber *)reactTag
Expand Down
10 changes: 0 additions & 10 deletions src/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import type {StyleProp, ImageStyle, NativeSyntheticEvent} from 'react-native';
import {getReactTag, resolveAssetSourceForVideo} from './utils';
import {VideoManager} from './VideoNativeComponent';
import type {
OnAdErrorData,
OnAudioFocusChangedData,
OnAudioTracksData,
OnBandwidthUpdateData,
Expand Down Expand Up @@ -84,7 +83,6 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
onReadyForDisplay,
onPlaybackRateChange,
onVolumeChange,
onAdError,
onAudioBecomingNoisy,
onPictureInPictureStatusChanged,
onRestoreUserInterfaceForPictureInPictureStop,
Expand Down Expand Up @@ -402,13 +400,6 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
[onReceiveAdEvent],
);

const _onAdError = useCallback(
(e: NativeSyntheticEvent<OnAdErrorData>) => {
onAdError?.(e.nativeEvent);
},
[onAdError],
);

const _onVideoAspectRatio = useCallback(
(e: NativeSyntheticEvent<OnVideoAspectRatioData>) => {
onAspectRatio?.(e.nativeEvent);
Expand Down Expand Up @@ -504,7 +495,6 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
selectedTextTrack={_selectedTextTrack}
selectedAudioTrack={_selectedAudioTrack}
selectedVideoTrack={_selectedVideoTrack}
onAdError={_onAdError}
onGetLicense={onGetLicense}
onVideoLoad={onVideoLoad}
onVideoLoadStart={onVideoLoadStart}
Expand Down
3 changes: 1 addition & 2 deletions src/VideoNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {NativeModules, requireNativeComponent} from 'react-native';
import type ResizeMode from './types/ResizeMode';
import type FilterType from './types/FilterType';
import type Orientation from './types/Orientation';
import type {AdEvent, OnAdErrorData, OnTextTracksTypeData} from './types';
import type {AdEvent, OnTextTracksTypeData} from './types';

// -------- There are types for native component (future codegen) --------
// if you are looking for types for react component, see src/types/video.ts
Expand Down Expand Up @@ -355,7 +355,6 @@ export interface VideoNativeProps extends ViewProps {
onReceiveAdEvent?: (
event: NativeSyntheticEvent<OnReceiveAdEventData>,
) => void;
onAdError?: (event: NativeSyntheticEvent<OnAdErrorData>) => void;
onVideoPlaybackStateChanged?: (
event: NativeSyntheticEvent<OnPlaybackStateChangedData>,
) => void; // android only
Expand Down
4 changes: 4 additions & 0 deletions src/types/Ads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export enum AdEvent {
* Android only: Fires when the ad's duration changes.
*/
DURATION_CHANGE = 'DURATION_CHANGE',
/**
* Fires when an error is encountered and the ad can't be played.
*/
ERROR = 'ERROR',
/**
* Fires when the ad playhead crosses first quartile.
*/
Expand Down
7 changes: 0 additions & 7 deletions src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,6 @@ export type OnReceiveAdEventData = Readonly<{
event: AdEvent;
}>;

export type OnAdErrorData = Readonly<{
code: string;
message: string;
type: string;
}>;

export type OnVideoErrorData = Readonly<{
error: OnVideoErrorDataDetails;
target?: number; // ios
Expand Down Expand Up @@ -158,7 +152,6 @@ export type OnBandwidthUpdateData = Readonly<
>;

export interface ReactVideoEvents {
onAdError?: (error: OnAdErrorData) => void; // Android, iOS
onAudioBecomingNoisy?: () => void; //Android, iOS
onAudioFocusChanged?: (e: OnAudioFocusChangedData) => void; // Android
onIdle?: () => void; // Android
Expand Down

0 comments on commit 90d1ca7

Please sign in to comment.