Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple OVP Session Provider #90

Merged
merged 4 commits into from
Feb 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Classes/Network/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public class RequestBuilder: NSObject {
public func setParam(key: String, value:String) -> Self {

if var params = self.urlParams {
self.urlParams![key] = value
params[key] = value
}else{
self.urlParams = [key:value]
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Network/Result.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit


public class Result<T> {
public class Result<T>: NSObject {

public var data: T? = nil
public var error: Error? = nil
Expand Down
3 changes: 0 additions & 3 deletions Classes/Network/SessionProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ public protocol SessionProvider {
var partnerId: Int64 { get }

func loadKS(completion: @escaping (_ result :Result<String>) -> Void)



}


2 changes: 1 addition & 1 deletion Classes/Player/AssetLoaderDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class AssetLoaderDelegate: NSObject {
PKLog.debug("Got response in \(endTime-startTime) sec")
let ckc = try self.parseServerResponse(data: data, error: error)
callback(Result(data: ckc))
} catch let e as Error {
} catch let e {
callback(Result(error: e))
}
})
Expand Down
1 change: 1 addition & 0 deletions Classes/Player/PlayerLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class PlayerLoader: PlayerDecoratorBase {
override func prepare(_ config: MediaConfig) {
// update all loaded plugins with media config
for (pluginName, loadedPlugin) in loadedPlugins {
PKLog.trace("Preparing plugin", pluginName)
loadedPlugin.plugin.onLoad(mediaConfig: config)
}
super.prepare(config)
Expand Down
2 changes: 1 addition & 1 deletion Classes/Providers/OTT/Session/OTTSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class OTTSessionManager: SessionProvider {
}
}

public func startAnonymouseSession(completion:@escaping (_ error:Error?)->Void) {
public func startAnonymousSession(completion:@escaping (_ error:Error?)->Void) {

let loginRequestBuilder = OTTUserService.anonymousLogin(baseURL: self.serverURL,
partnerId: self.partnerId)
Expand Down
5 changes: 5 additions & 0 deletions Classes/Providers/OVP/OVPMediaProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public class OVPMediaProvider: MediaEntryProvider {


public init(){}

public init(_ sessionProvider: SessionProvider) {
self.set(sessionProvider: sessionProvider)
}

/**
session provider - which resposible for the ks, prtner id, and base server url
*/
Expand Down
18 changes: 9 additions & 9 deletions Classes/Providers/OVP/Session/OVPSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ public class OVPSessionManager: SessionProvider {

private let defaultSessionExpiry = TimeInterval(24*60*60)


public init(serverURL: String, version:String, partnerId: Int64, executor: RequestExecutor?) {

public init(serverURL: String, partnerId: Int64, executor: RequestExecutor? = nil) {
self.serverURL = serverURL
self.partnerId = partnerId
self.version = version
self.version = "api_v3"
self.fullServerPath = self.serverURL.appending("/\(self.version)")

if let exe = executor {
Expand All @@ -55,6 +53,11 @@ public class OVPSessionManager: SessionProvider {
self.executor = USRExecutor.shared
}
}

@available(*, deprecated, message: "Use init(serverURL:partnerId:executor:)")
public convenience init(serverURL: String, version:String, partnerId: Int64, executor: RequestExecutor?) {
self.init(serverURL: serverURL, partnerId: partnerId, executor: executor)
}

public func loadKS(completion: @escaping (_ result :Result<String>) -> Void){
if let ks = self.ks, self.tokenExpiration?.compare(Date()) == ComparisonResult.orderedDescending {
Expand All @@ -72,7 +75,7 @@ public class OVPSessionManager: SessionProvider {
}
else{

self.startAnonymouseSession(completion: { (e:Error?) in
self.startAnonymousSession(completion: { (e:Error?) in
self.ensureKSAfterRefresh(e: e, completion: completion)
})
}
Expand All @@ -94,10 +97,7 @@ public class OVPSessionManager: SessionProvider {
}





public func startAnonymouseSession(completion:@escaping (_ error:Error?)->Void) -> Void {
public func startAnonymousSession(completion:@escaping (_ error:Error?)->Void) -> Void {

let loginRequestBuilder = OVPSessionService.startWidgetSession(baseURL: self.fullServerPath,
partnerId: self.partnerId)?
Expand Down
43 changes: 43 additions & 0 deletions Classes/Providers/OVP/SimpleOVPSessionProvider.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Created by Noam Tamim on 09/02/2017.
//
//

import UIKit

/**
A SessionProvider that just reflects its input parameters -- baseUrl, partnerId, ks.
Unlike the full OVPSessionManager, this class does not attempt to manage (create, renew, validate, clear) a session.
The application is expected to provide a valid KS, which it can update as required via the `ks` property. For some
use cases, the KS can be null (anonymous media playback, if allowed by access-control). Basic usage with a OVPMediaProvider:

let mediaProvider = OVPMediaProvider(SimpleOVPSessionProvider(serverURL: "https://cdnapisec.kaltura.com",
partnerId: 1851571,
ks: applicationKS))
mediaProvider.set(entryId: "0_pl5lbfo0").loadMedia { (entry) in
print("entry:", entry.data ?? "<nil>")
}

*/
public class SimpleOVPSessionProvider: SessionProvider {
public let serverURL: String
public let partnerId: Int64
public var ks: String?

/**
Build an OVP SessionProvider with the specified parameters.
- Parameters:
- serverURL: Kaltura Server URL, such as `"https://cdnapisec.kaltura.com"`.
- partnerId: Kaltura partner id.
- ks: Kaltura Session token.
*/
public init(serverURL: String, partnerId: Int64, ks: String?) {
self.serverURL = serverURL
self.partnerId = partnerId
self.ks = ks
}

public func loadKS(completion: @escaping (Result<String>) -> Void) {
completion(Result(data: ks, error: nil))
}
}