-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #430 from THEOplayer/feature/omid
[WIP] Feature/omid
- Loading branch information
Showing
12 changed files
with
241 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// THEOplayerRCTAdsAPI+Omid.swift | ||
|
||
import Foundation | ||
import THEOplayerSDK | ||
import UIKit | ||
|
||
let PROP_OMID_VIEW: String = "view" | ||
let PROP_OMID_PURPOSE: String = "purpose" | ||
let PROP_OMID_REASON: String = "reason" | ||
|
||
extension THEOplayerRCTAdsAPI { | ||
|
||
#if canImport(THEOplayerGoogleIMAIntegration) | ||
@objc(addFriendlyObstruction:obstruction:) | ||
func addFriendlyObstruction(_ node: NSNumber, obstruction: NSDictionary) { | ||
DispatchQueue.main.async { | ||
if let obstructionNode = obstruction[PROP_OMID_VIEW] as? NSNumber, | ||
let purposeString = obstruction[PROP_OMID_PURPOSE] as? String, | ||
let theView = self.bridge.uiManager.view(forReactTag: node) as? THEOplayerRCTView, | ||
let obstructionView = self.bridge.uiManager.view(forReactTag: obstructionNode), | ||
let ads = theView.ads() { | ||
let obstruction = OmidFriendlyObstruction(view: obstructionView, | ||
purpose: THEOplayerRCTTypeUtils.omidFriendlyObstructionPurposeFromString(purposeString), | ||
detailedReason: obstruction[PROP_OMID_REASON] as? String) | ||
ads.omid.addFriendlyObstruction(friendlyObstruction: obstruction) | ||
} | ||
} | ||
} | ||
|
||
@objc(removeAllFriendlyObstructions:) | ||
func removeAllFriendlyObstructions(_ node: NSNumber) { | ||
DispatchQueue.main.async { | ||
if let theView = self.bridge.uiManager.view(forReactTag: node) as? THEOplayerRCTView, | ||
let ads = theView.ads() { | ||
ads.omid.removeFriendlyObstructions() | ||
} | ||
} | ||
} | ||
|
||
#else | ||
|
||
@objc(addFriendlyObstruction:obstruction:) | ||
func addFriendlyObstruction(_ node: NSNumber, obstruction: NSDictionary) { | ||
if DEBUG_ADS_API { print(ERROR_MESSAGE_ADS_UNSUPPORTED_FEATURE) } | ||
} | ||
|
||
@objc(removeAllFriendlyObstructions:) | ||
func removeAllFriendlyObstructions(_ node: NSNumber) { | ||
if DEBUG_ADS_API { print(ERROR_MESSAGE_ADS_UNSUPPORTED_FEATURE) } | ||
} | ||
|
||
#endif | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from 'react'; | ||
import { View } from 'react-native'; | ||
|
||
export enum OmidFriendlyObstructionPurpose { | ||
/** | ||
* The video overlay is one of the video player's control button. | ||
*/ | ||
VIDEO_CONTROLS = 'videoControls', | ||
|
||
/** | ||
* The video overlay is for the purpose of closing the advertisement. | ||
*/ | ||
CLOSE_AD = 'closeAd', | ||
|
||
/** | ||
* The video overlay is transparent and will not affect viewability. | ||
*/ | ||
NOT_VISIBLE = 'notVisible', | ||
|
||
/** | ||
* The video overlay is meant for other purposes. | ||
*/ | ||
OTHER = 'other', | ||
} | ||
|
||
export interface OmidFriendlyObstruction { | ||
/** | ||
* The View of the friendly obstruction. | ||
*/ | ||
view: React.RefObject<View>; | ||
|
||
/** | ||
* The {@link OmidFriendlyObstructionPurpose} of the friendly obstruction. | ||
*/ | ||
purpose: OmidFriendlyObstructionPurpose; | ||
|
||
/** | ||
* The optional reason for the friendly obstruction. | ||
*/ | ||
reason?: string; | ||
} | ||
|
||
/** | ||
* The Omid API, which can be used to add as well as remove friendly video controls overlay obstructions. | ||
*/ | ||
export interface Omid { | ||
|
||
/** | ||
* Adds an {@link OmidFriendlyObstruction}. | ||
* @param obstruction | ||
*/ | ||
addFriendlyObstruction(obstruction: OmidFriendlyObstruction): void; | ||
|
||
/** | ||
* Removes all {@link OmidFriendlyObstruction}s. | ||
*/ | ||
removeAllFriendlyObstructions(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { THEOplayerView } from 'react-native-theoplayer'; | ||
import { findNodeHandle, NativeModules } from 'react-native'; | ||
import { Omid, OmidFriendlyObstruction } from '../../../api/ads/Omid'; | ||
|
||
const NativeAdsModule = NativeModules.THEORCTAdsModule; | ||
|
||
export class THEOplayerNativeOmid implements Omid { | ||
public constructor(private readonly _player: THEOplayerView) {} | ||
|
||
addFriendlyObstruction(obstruction: OmidFriendlyObstruction): void { | ||
NativeAdsModule.addFriendlyObstruction(this._player.nativeHandle, { | ||
view: findNodeHandle(obstruction.view.current), | ||
purpose: obstruction.purpose, | ||
reason: obstruction.reason, | ||
}); | ||
} | ||
|
||
removeAllFriendlyObstructions(): void { | ||
NativeAdsModule.removeAllFriendlyObstructions(this._player.nativeHandle); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters