Skip to content

Commit

Permalink
#FEM-1437 Move IMA plugin to a separate repo/module (#176)
Browse files Browse the repository at this point in the history
* #FEM-1437

* Added public modifiers for AdEvents to be able to integrate other ad players and posting ad events.
* Moved `PKPlaybackInfo` + `PKAdInfo` + `PKAdCuePoints` to "/Events/EventsPayload"

* fixed codacy issues

* FEM-1437 #comment Added public modifiers

* FEM-1437 #comment remove IMA subspec & IMA files from PlayKit

* FEM-1437 #comment remove pod IMA subspec

* FEM-1437 #comment add open modifier + fix example issue

* remove ima plugin reference from PlayKitFramework Podfile

* extra space removment after comma
  • Loading branch information
gal-orlanczyk authored and ElizaSapir committed Jun 13, 2017
1 parent 6f70d00 commit 3a27852
Show file tree
Hide file tree
Showing 29 changed files with 458 additions and 1,397 deletions.
187 changes: 187 additions & 0 deletions Classes/Events/AdEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
//
// AdEvent.swift
// Pods
//
// Created by Gal Orlanczyk on 28/05/2017.
//
//

import Foundation

@objc public class AdEvent: PKEvent {

/************************************************************/
// MARK: - Events Type
/************************************************************/

@objc public static let allEventTypes: [AdEvent.Type] = [
adBreakReady, allAdsCompleted, adComplete, adClicked, adCuePointsUpdate, adFirstQuartile, adLoaded, adLog, adMidpoint, adPaused, adResumed, adSkipped, adStarted, adTapped, adThirdQuartile, adDidProgressToTime, adDidRequestContentPause, adDidRequestContentResume, adWebOpenerWillOpenExternalBrowser, adWebOpenerWillOpenInAppBrowser, adWebOpenerDidOpenInAppBrowser, adWebOpenerWillCloseInAppBrowser, adWebOpenerDidCloseInAppBrowser, requestTimedOut
]

@objc public static let adBreakReady: AdEvent.Type = AdBreakReady.self
@objc public static let allAdsCompleted: AdEvent.Type = AllAdsCompleted.self
@objc public static let adComplete: AdEvent.Type = AdComplete.self
@objc public static let adClicked: AdEvent.Type = AdClicked.self
@objc public static let adFirstQuartile: AdEvent.Type = AdFirstQuartile.self
@objc public static let adLoaded: AdEvent.Type = AdLoaded.self
@objc public static let adLog: AdEvent.Type = AdLog.self
@objc public static let adMidpoint: AdEvent.Type = AdMidpoint.self
@objc public static let adPaused: AdEvent.Type = AdPaused.self
@objc public static let adResumed: AdEvent.Type = AdResumed.self
@objc public static let adSkipped: AdEvent.Type = AdSkipped.self
@objc public static let adStarted: AdEvent.Type = AdStarted.self
@objc public static let adTapped: AdEvent.Type = AdTapped.self
@objc public static let adThirdQuartile: AdEvent.Type = AdThirdQuartile.self
@objc public static let adDidProgressToTime: AdEvent.Type = AdDidProgressToTime.self
/// Ad requested the content to pause (before ad starts playing)
@objc public static let adDidRequestContentPause: AdEvent.Type = AdDidRequestContentPause.self
/// Ad requested content resume (when finished playing ads or when error occurs and playback needs to continue)
@objc public static let adDidRequestContentResume: AdEvent.Type = AdDidRequestContentResume.self
@objc public static let webOpenerEvent: AdEvent.Type = WebOpenerEvent.self
@objc public static let adWebOpenerWillOpenExternalBrowser: AdEvent.Type = AdWebOpenerWillOpenExternalBrowser.self
@objc public static let adWebOpenerWillOpenInAppBrowser: AdEvent.Type = AdWebOpenerWillOpenInAppBrowser.self
@objc public static let adWebOpenerDidOpenInAppBrowser: AdEvent.Type = AdWebOpenerDidOpenInAppBrowser.self
@objc public static let adWebOpenerWillCloseInAppBrowser: AdEvent.Type = AdWebOpenerWillCloseInAppBrowser.self
@objc public static let adWebOpenerDidCloseInAppBrowser: AdEvent.Type = AdWebOpenerDidCloseInAppBrowser.self
@objc public static let adCuePointsUpdate: AdEvent.Type = AdCuePointsUpdate.self
/// Sent when an ad started buffering
@objc public static let adStartedBuffering: AdEvent.Type = AdStartedBuffering.self
/// Sent when ad finished buffering and ready for playback
@objc public static let adPlaybackReady: AdEvent.Type = AdPlaybackReady.self
/// Sent when the ads request timed out.
@objc public static let requestTimedOut: AdEvent.Type = RequestTimedOut.self
/// delivered when ads request was sent.
@objc public static let adsRequested: AdEvent.Type = AdsRequested.self
/// Sent when an error occurs.
@objc public static let error: AdEvent.Type = Error.self

/************************************************************/
// MARK: - Events
/************************************************************/

public class AdStarted: AdEvent {
public convenience init(adInfo: PKAdInfo) {
self.init([AdEventDataKeys.adInfo: adInfo])
}
}

public class AdLoaded: AdEvent {
public convenience init(adInfo: PKAdInfo) {
self.init([AdEventDataKeys.adInfo: adInfo])
}
}

public class AdBreakReady: AdEvent {}
public class AllAdsCompleted: AdEvent {}
public class AdComplete: AdEvent {}
public class AdClicked: AdEvent {}
public class AdFirstQuartile: AdEvent {}
public class AdLog: AdEvent {}
public class AdMidpoint: AdEvent {}
public class AdPaused: AdEvent {}
public class AdResumed: AdEvent {}
public class AdSkipped: AdEvent {}
public class AdTapped: AdEvent {}
public class AdThirdQuartile: AdEvent {}

public class AdStartedBuffering: AdEvent {}
public class AdPlaybackReady: AdEvent {}

// `AdCuePointsUpdate` event is received when ad cue points were updated. only sent when there is more then 0.
public class AdCuePointsUpdate: AdEvent {
public convenience init(adCuePoints: PKAdCuePoints) {
self.init([AdEventDataKeys.adCuePoints: adCuePoints])
}
}

public class Error: AdEvent {
public convenience init(nsError: NSError) {
self.init([AdEventDataKeys.error: nsError])
}
}

public class AdDidProgressToTime: AdEvent {
public convenience init(mediaTime: TimeInterval, totalTime: TimeInterval) {
self.init([AdEventDataKeys.mediaTime: NSNumber(value: mediaTime),
AdEventDataKeys.totalTime: NSNumber(value: totalTime)])
}
}

public class AdDidRequestContentPause: AdEvent {}
public class AdDidRequestContentResume: AdEvent {}

/// Sent when the ads request timed out.
public class RequestTimedOut: AdEvent {}

/// delivered when ads request was sent.
public class AdsRequested: AdEvent {
public convenience init(adTagUrl: String) {
self.init([AdEventDataKeys.adTagUrl: adTagUrl])
}
}

public class WebOpenerEvent: AdEvent {
public convenience init(webOpener: NSObject!) {
self.init([AdEventDataKeys.webOpener: webOpener])
}
}

public class AdWebOpenerWillOpenExternalBrowser: WebOpenerEvent {}
public class AdWebOpenerWillOpenInAppBrowser: WebOpenerEvent {}
public class AdWebOpenerDidOpenInAppBrowser: WebOpenerEvent {}
public class AdWebOpenerWillCloseInAppBrowser: WebOpenerEvent {}
public class AdWebOpenerDidCloseInAppBrowser: WebOpenerEvent {}
}

/************************************************************/
// MARK: - PKEvent Data Accessors Extension
/************************************************************/

/// AdEvent data keys, used to access/put data in `AdEvent`.
@objc public class AdEventDataKeys: NSObject {
public static let mediaTime = "mediaTime"
public static let totalTime = "totalTime"
public static let webOpener = "webOpener"
public static let error = "error"
public static let adCuePoints = "adCuePoints"
public static let adInfo = "adInfo"
public static let adTagUrl = "adTagUrl"
}

extension PKEvent {

/// MediaTime, PKEvent Ad Data Accessor
@objc public var adMediaTime: NSNumber? {
return self.data?[AdEventDataKeys.mediaTime] as? NSNumber
}

/// TotalTime, PKEvent Ad Data Accessor
@objc public var adTotalTime: NSNumber? {
return self.data?[AdEventDataKeys.totalTime] as? NSNumber
}

/// WebOpener, PKEvent Ad Data Accessor
@objc public var adWebOpener: NSObject? {
return self.data?[AdEventDataKeys.webOpener] as? NSObject
}

/// Associated error from error event, PKEvent Ad Data Accessor
@objc public var adError: NSError? {
return self.data?[AdEventDataKeys.error] as? NSError
}

/// Ad cue points, PKEvent Ad Data Accessor
@objc public var adCuePoints: PKAdCuePoints? {
return self.data?[AdEventDataKeys.adCuePoints] as? PKAdCuePoints
}

/// TotalTime, PKEvent Ad Data Accessor
@objc public var adTagUrl: String? {
return self.data?[AdEventDataKeys.adTagUrl] as? String
}

/// Ad info, PKEvent Ad Data Accessor
@objc public var adInfo: PKAdInfo? {
return self.data?[AdEventDataKeys.adInfo] as? PKAdInfo
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation

@objc public private(set) var cuePoints: [TimeInterval]

init(cuePoints: [TimeInterval]) {
public init(cuePoints: [TimeInterval]) {
self.cuePoints = cuePoints.sorted() // makes sure array is sorted
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ import Foundation
/// `PKAdInfo` represents ad information.
@objc public class PKAdInfo: NSObject {

@objc public var adDescription: String
@objc public var duration: TimeInterval
@objc public var title: String
/// The position of the pod in the content in seconds. Pre-roll returns 0,
/// post-roll returns -1 and mid-rolls return the scheduled time of the pod.
@objc public var timeOffset: TimeInterval

@objc public var adDescription: String
@objc public var isSkippable: Bool
@objc public var contentType: String
@objc public var adId: String
Expand All @@ -32,9 +36,6 @@ import Foundation
@objc public var totalAds: Int
/// The position of this ad within an ad pod. Will be 1 for standalone ads.
@objc public var adPosition: Int
/// The position of the pod in the content in seconds. Pre-roll returns 0,
/// post-roll returns -1 and mid-rolls return the scheduled time of the pod.
@objc public var timeOffset: TimeInterval
@objc public var isBumper: Bool
// The index of the pod, where pre-roll pod is 0, mid-roll pods are 1 .. N
// and the post-roll is -1.
Expand All @@ -51,7 +52,7 @@ import Foundation
}
}

init(adDescription: String,
public init(adDescription: String,
adDuration: TimeInterval,
title: String,
isSkippable: Bool,
Expand Down Expand Up @@ -82,11 +83,3 @@ import Foundation
self.podIndex = podIndex
}
}

extension PKEvent {
/// Ad info, PKEvent Ad Data Accessor
@objc public var adInfo: PKAdInfo? {
return self.data?[AdEventDataKeys.adInfo] as? PKAdInfo
}
}

41 changes: 41 additions & 0 deletions Classes/Events/EventsPayloads/PKPlaybackInfo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// PKPlaybackInfo.swift
// Pods
//
// Created by Gal Orlanczyk on 28/05/2017.
//
//

import Foundation
import AVFoundation

/// `PKPlaybackInfo` represents a playback info object.
@objc public class PKPlaybackInfo: NSObject {

/// The actual bitrate of the playback.
public let bitrate: Double
/// The selected track indicated bitrate.
public let indicatedBitrate: Double
/// The throughput of the playback (download speed)
public let observedBitrate: Double

init(bitrate: Double, indicatedBitrate: Double, observedBitrate: Double) {
self.bitrate = bitrate
self.indicatedBitrate = indicatedBitrate
self.observedBitrate = observedBitrate
}

convenience init(logEvent: AVPlayerItemAccessLogEvent) {
let bitrate: Double
if logEvent.segmentsDownloadedDuration > 0 {
// bitrate is equal to:
// (amount of bytes transfered) * 8 (bits in byte) / (amount of time took to download the transfered bytes)
bitrate = Double(logEvent.numberOfBytesTransferred * 8) / logEvent.segmentsDownloadedDuration
} else {
bitrate = logEvent.indicatedBitrate
}
let indicatedBitrate = logEvent.indicatedBitrate
let observedBitrate = logEvent.observedBitrate
self.init(bitrate: bitrate, indicatedBitrate: indicatedBitrate, observedBitrate: observedBitrate)
}
}
Loading

0 comments on commit 3a27852

Please sign in to comment.