-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathKavaPluginConfig.swift
More file actions
131 lines (114 loc) · 4.78 KB
/
Copy pathKavaPluginConfig.swift
File metadata and controls
131 lines (114 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// ===================================================================================================
// Copyright (C) 2017 Kaltura Inc.
//
// Licensed under the AGPLv3 license, unless a different license for a
// particular library is specified in the applicable library path.
//
// You may obtain a copy of the License at
// https://www.gnu.org/licenses/agpl-3.0.html
// ===================================================================================================
import Foundation
import PlayKit
/************************************************************/
// MARK: KavaPluginConfig
/************************************************************/
@objc public class KavaPluginConfig: NSObject {
/************************************************************/
// MARK: - Enum
/************************************************************/
@objc public enum PlaybackType : Int {
case unknown
case live
case vod
}
/************************************************************/
// MARK: - Properties
/************************************************************/
private let defaultBaseUrl = "http://analytics.kaltura.com/api_v3/index.php"
/// application ID.
let applicationId = Bundle.main.bundleIdentifier
/// The partner account ID on Kaltura's platform.
@objc public var partnerId: Int
/// The media's entry ID.
@objc public var entryId: String?
/// The player id and configuration the content was played on.
@objc public var uiconfId: Int
/// The Kaltura encoded session data.
@objc public var ks: String?
/// The category id describing the current played context.
@objc public var playbackContext: String?
/// Received from plugin config if nothing there take app id wit relavant prefix.
@objc public var referrer: String?
/// Kaltura api base url
@objc public var baseUrl: String
/// Optional vars
@objc public var customVar1, customVar2, customVar3: String?
/// If not using providers user must mention playback type (live/ vod)
/// Set by defualt to unknown
@objc public var playbackType: PlaybackType = .unknown
/// DVR Threshold set by default to 2 minutes.
@objc public var dvrThreshold = 120
/// The application version.
@objc public var applicationVersion: String?
/// The playlist Id.
@objc public var playlistId: String?
/************************************************************/
// MARK: Internal Properties
/************************************************************/
var sessionStartTime: String?
var isLive: Bool?
var hasDVR: Bool?
/************************************************************/
// MARK: - Initialization
/************************************************************/
@objc public init(partnerId: Int, entryId: String?, ks: String?, playbackContext: String?, referrer: String?, applicationVersion: String?, playlistId: String?, customVar1: String?, customVar2: String?, customVar3: String?) {
self.baseUrl = defaultBaseUrl
// uiconfId is optional, set to -1 as default
// can be overridden
self.uiconfId = -1
self.partnerId = partnerId
self.entryId = entryId
self.ks = ks
self.playbackContext = playbackContext
self.applicationVersion = applicationVersion
self.playlistId = playlistId
self.customVar1 = customVar1
self.customVar2 = customVar2
self.customVar3 = customVar3
super.init()
if let sentReferrer = referrer, self.isValidReferrer(sentReferrer) {
self.referrer = sentReferrer
} else {
if referrer != nil {
PKLog.warning("Invalid referrer argument. Should start with app:// or http:// or https://")
}
if let appId = applicationId {
self.referrer = "app://" + appId
} else {
PKLog.warning("The app's bundle identifier is not set")
}
}
}
/************************************************************/
// MARK: Private Implementation
/************************************************************/
private func isValidReferrer(_ referrer: String) -> Bool {
let validPrefixes = ["app://", "http://", "https://"]
var isValid = false
for p in validPrefixes {
if referrer.hasPrefix(p) {
isValid = true
break
}
}
return isValid
}
}
/************************************************************/
// MARK: - Extensions
/************************************************************/
extension String {
func toBase64() -> String {
return Data(self.utf8).base64EncodedString()
}
}