Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Eliza Sapir committed Mar 15, 2017
2 parents 6465dd2 + 7ec6f96 commit ff5f2fa
Show file tree
Hide file tree
Showing 53 changed files with 1,497 additions and 1,106 deletions.
55 changes: 19 additions & 36 deletions Addons/GoogleCast/BasicCastBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@
import UIKit
import GoogleCast



/**

TVPAPICastBuilder this component will help you to comunicate with Kaltura-custom-receiver.

*/
public class BasicCastBuilder: NSObject {


public enum StreamType {
@objc public class BasicCastBuilder: NSObject {
@objc public enum StreamType: Int {
case live
case vod
}
Expand All @@ -31,30 +27,28 @@ public class BasicCastBuilder: NSObject {
case missingUIConfId
case missingStreamType
}


internal var contentId: String!
internal var webPlayerURL: String?
internal var partnerID: String?
internal var uiconfID: String?
internal var adTagURL: String?
internal var streamType: GCKMediaStreamType!
internal var metaData: GCKMediaMetadata?
@objc public var contentId: String!
@objc public var webPlayerURL: String?
@objc public var partnerID: String?
@objc public var uiconfID: String?
@objc public var adTagURL: String?
@objc public private(set) var streamType = GCKMediaStreamType.none
@objc public var metaData: GCKMediaMetadata?


/**
Set - stream type
- Parameter contentId: receiver contentId to play ( Entry id, or Asset id )
*/
@discardableResult
public func set(streamType: StreamType?) -> Self{
@objc public func set(streamType: StreamType) -> Self{

switch streamType {
case .live? :
case .live:
self.streamType = .live
default:
case .vod:
self.streamType = .buffered

}
return self
}
Expand All @@ -64,7 +58,7 @@ public class BasicCastBuilder: NSObject {
- Parameter contentId: receiver contentId to play ( Entry id, or Asset id )
*/
@discardableResult
public func set(contentId: String?) -> Self{
@nonobjc public func set(contentId: String?) -> Self{

guard contentId != nil,
contentId?.isEmpty == false
Expand All @@ -82,7 +76,7 @@ public class BasicCastBuilder: NSObject {
- Parameter adTagURL: that advertisments url to play
*/
@discardableResult
public func set(adTagURL: String?) -> Self {
@nonobjc public func set(adTagURL: String?) -> Self {

guard adTagURL != nil,
adTagURL?.isEmpty == false
Expand All @@ -100,7 +94,7 @@ public class BasicCastBuilder: NSObject {
- Parameter webPlayerURL: the location of the web player the receiver will use to play content
*/
@discardableResult
public func set(webPlayerURL: String?) -> Self {
@nonobjc public func set(webPlayerURL: String?) -> Self {

guard webPlayerURL != nil,
webPlayerURL?.isEmpty == false
Expand All @@ -120,7 +114,7 @@ public class BasicCastBuilder: NSObject {
- Parameter partnerID: the client partner id
*/
@discardableResult
public func set(partnerID: String?) -> Self {
@nonobjc public func set(partnerID: String?) -> Self {

guard partnerID != nil,
partnerID?.isEmpty == false
Expand All @@ -138,7 +132,7 @@ public class BasicCastBuilder: NSObject {
- Parameter uiconfID: the receiver uiconf id thet has the configuration for the layout and plugins
*/
@discardableResult
public func set(uiconfID: String?) -> Self {
@nonobjc public func set(uiconfID: String?) -> Self {

guard uiconfID != nil,
uiconfID?.isEmpty == false
Expand All @@ -157,7 +151,7 @@ public class BasicCastBuilder: NSObject {
- Parameter metaData: the receiver google meta data
*/
@discardableResult
public func set(metaData: GCKMediaMetadata?) -> Self{
@nonobjc public func set(metaData: GCKMediaMetadata?) -> Self{

guard metaData != nil
else {
Expand Down Expand Up @@ -186,7 +180,7 @@ public class BasicCastBuilder: NSObject {
/**
Build GCKMediaInformation a google-cast-sdk object to send through the load google-API
*/
public func build() throws -> GCKMediaInformation {
@objc public func build() throws -> GCKMediaInformation {

try self.validate()
let customData = self.customData()
Expand Down Expand Up @@ -264,14 +258,3 @@ public class BasicCastBuilder: NSObject {
return plugin
}
}











26 changes: 9 additions & 17 deletions Addons/GoogleCast/TVPAPICastBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,27 @@

import UIKit


/**

TVPAPICastBuilder this component will help you to comunicate with Kaltura-custom-receiver with TVPAPI Server.

*/
public class TVPAPICastBuilder: BasicCastBuilder {


enum BasicBuilderDataError: Error {
case missingInitObject
case missingFormat
}

internal var initObject: [String:Any]!
internal var initObject: [String: Any]!
internal var format: String!


/**
Set - initObject
- Parameter initObject: that the receiver will use to represent the user
*/
@discardableResult
public func set(initObject: [String:Any]?) -> Self {
public func set(initObject: [String: Any]?) -> Self {

guard initObject != nil
else {
Expand Down Expand Up @@ -62,7 +59,6 @@ public class TVPAPICastBuilder: BasicCastBuilder {


/**

In order to comunicate with Kaltura receiver you should have init object and format this will throw exception if the input is not valid
*/
override func validate() throws {
Expand All @@ -79,7 +75,6 @@ public class TVPAPICastBuilder: BasicCastBuilder {

}


internal override func flashVars() -> [String: Any] {

var flashVars = super.flashVars()
Expand All @@ -91,25 +86,22 @@ public class TVPAPICastBuilder: BasicCastBuilder {
return flashVars
}



/**
Adding the data relevent for the OTT
*/
internal func proxyData() -> [String:Any]? {
internal func proxyData() -> [String: Any]? {

let flavorAssets = ["filters":["include":["Format":[self.format!]]]]
var config : [String : Any] = ["flavorassets":flavorAssets]
let flavorAssets = ["filters": ["include": ["Format": [self.format!]]]]
let config: [String: Any] = ["flavorassets": flavorAssets]

var proxyData = ["MediaID":self.contentId!,
"iMediaID":self.contentId!,
"mediaType":0,
"withDynamic":false] as [String : Any]
var proxyData = ["MediaID": self.contentId!,
"iMediaID": self.contentId!,
"mediaType": 0,
"withDynamic": false] as [String: Any]

proxyData["config"] = config
proxyData["initObj"] = self.initObject!
return proxyData

}
}

Expand Down
34 changes: 34 additions & 0 deletions Classes/Extensions/ArrayExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// ArrayExtension.swift
// Pods
//
// Created by Gal Orlanczyk on 07/03/2017.
//
//

import Foundation

extension Array where Element: Equatable {

/**
Remove an element from the array and invalidates all indexes.

- parameter element: The element to remove.
*/
mutating func remove(element: Element) {
if let index = self.index(of: element) {
self.remove(at: index)
}
}

/**
Removes elements from the array and invalidates all indexes.

- parameter elements: The array with the elements to delete.
*/
mutating func remove(elements: [Element]) {
for element in elements {
remove(element: element)
}
}
}
2 changes: 1 addition & 1 deletion Classes/Managers/LocalAssetsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import AVFoundation
@objc public func prepareForDownload(asset: AVURLAsset, mediaSource: MediaSource) {

// This function is a noop if no DRM data or DRM is not FairPlay.
guard let drmData = mediaSource.drmData?.first as? FairPlayDRMData else {return}
guard let drmData = mediaSource.drmData?.first as? FairPlayDRMParams else {return}

PKLog.debug("Preparing asset for download; asset.url:", asset.url)

Expand Down
18 changes: 14 additions & 4 deletions Classes/Managers/PlayKitManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,31 @@ import UIKit
///
/// - Parameter config: The configuration object to load the player with.
/// - Returns: A player loaded using the provided configuration.
@objc public func loadPlayer(pluginConfig: PluginConfig?) -> Player {
@objc public func loadPlayer(pluginConfig: PluginConfig?) throws -> Player {
let loader = PlayerLoader()
loader.load(pluginConfig: pluginConfig)
try loader.load(pluginConfig: pluginConfig)
return loader
}

@objc public func registerPlugin(_ pluginClass: BasePlugin.Type) {
if let pluginWarmUp = pluginClass as? PKPluginWarmUp.Type {
pluginWarmUp.warmUp()
}
pluginRegistry[pluginClass.pluginName] = pluginClass
}

func createPlugin(name: String, player: Player, pluginConfig: Any?, messageBus: MessageBus) throws -> PKPlugin {
guard let pluginClass = pluginRegistry[name] else {
PKLog.error("plugin with name: \(name) doesn't exist in pluginRegistry")
throw PKPluginError.failedToCreatePlugin
throw PKPluginError.failedToCreatePlugin(pluginName: name).asNSError
}
return try pluginClass.init(player: player, pluginConfig: pluginConfig, messageBus: messageBus)
}

/// sets the logging level for our logger.
@objc public static var logLevel: PKLogLevel = .debug {
didSet {
PKLog.minLevel = logLevel.toLoggerLevel
}
return pluginClass.init(player: player, pluginConfig: pluginConfig, messageBus: messageBus)
}
}
32 changes: 20 additions & 12 deletions Classes/MessageBus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,30 @@ import Foundation

private struct Observation {
weak var observer: AnyObject?
let block: (PKEvent)->Void
let observeOn: DispatchQueue
let block: (PKEvent) -> Void
}

@objc public class MessageBus: NSObject {
private var observations = [String: [Observation]]()
private let lock: AnyObject = UUID().uuidString as AnyObject

@objc public func addObserver(_ observer: AnyObject, events: [PKEvent.Type], block: @escaping (PKEvent)->Void) {
@objc public func addObserver(_ observer: AnyObject, events: [PKEvent.Type], block: @escaping (PKEvent) -> Void) {
self.add(observer: observer, events: events, block: block)
}

@objc public func addObserver(_ observer: AnyObject, events: [PKEvent.Type], observeOn dispatchQueue: DispatchQueue, block: @escaping (PKEvent)->Void) {
self.add(observer: observer, events: events, observeOn: dispatchQueue, block: block)
}

private func add(observer: AnyObject, events: [PKEvent.Type], observeOn dispatchQueue: DispatchQueue = DispatchQueue.main, block: @escaping (PKEvent)->Void) {
sync {
PKLog.debug("Add observer: \(observer) for events: \(events)")
events.forEach { (et) in
let typeId = NSStringFromClass(et)
var array: [Observation]? = observations[typeId]

if array == nil {
array = []
}

array!.append(Observation(observer: observer, block: block))
observations[typeId] = array
var observationList: [Observation] = observations[typeId] ?? []
observationList.append(Observation(observer: observer, observeOn: dispatchQueue, block: block))
observations[typeId] = observationList
}
}
}
Expand All @@ -50,15 +54,19 @@ private struct Observation {
}

@objc public func post(_ event: PKEvent) {
DispatchQueue.main.async { [weak self] in
DispatchQueue.global().async { [weak self] in
PKLog.info("Post event: \(event)")
let typeId = NSStringFromClass(type(of: event))

if let array = self?.observations[typeId] {
// remove nil observers replace current observations with new ones, and call block with the event
let newObservations = array.filter { $0.observer != nil }
self?.observations[typeId] = newObservations
newObservations.forEach { $0.block(event) }
newObservations.forEach { observation in
observation.observeOn.async {
observation.block(event)
}
}
}
}
}
Expand Down
Loading

0 comments on commit ff5f2fa

Please sign in to comment.