Skip to content

Commit

Permalink
Added initObj key to the media mark request. It was missing. (#84)
Browse files Browse the repository at this point in the history
* Added initObj key to the media mark request. It was missing.

* #FEM-1112 #comment [~ziv.hundert] make sure to check if this issue happens in android.

* Fixed issue with initObj in TVPAPI.
* Fixed concurrency event checks.
* Fixed issue with MediaMarkService and BookmarkService
  • Loading branch information
odedk14 authored and Gal Orlanczyk committed Feb 13, 2017
1 parent aaab5e5 commit 42f365b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Plugins/Phoenix/BookmarkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal class BookmarkService {
private static func createBookmark(eventType: String, position: Int32, assetId: String, fileId: String) -> JSON {
var json: JSON = JSON.init(["objectType": "KalturaBookmark"])
json["type"] = JSON("media")
//json["id"] = JSON(assetId)
json["id"] = JSON(assetId)
json["position"] = JSON(position)
json["playerData"] = JSON.init(["action": JSON(eventType), "objectType": JSON("KalturaBookmarkPlayerData"), "fileId": JSON(fileId)])

Expand Down
8 changes: 2 additions & 6 deletions Plugins/Phoenix/MediaMarkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SwiftyJSON
internal class MediaMarkService {

internal static func sendTVPAPIEVent(baseURL: String,
initObj: JSON?,
initObj: [String : Any],
eventType: String,
currentTime: Int32,
assetId: String,
Expand All @@ -21,11 +21,7 @@ internal class MediaMarkService {
if let request: RequestBuilder = RequestBuilder(url: baseURL) {
request
.set(method: "POST")

if let obj = initObj {
request.set(jsonBody: obj)
}
request
.setBody(key: "initObj", value: JSON(initObj))
.setBody(key: "iFileID", value: JSON(fileId))
.setBody(key: "iMediaID", value: JSON(assetId))
.setBody(key: "iLocation", value: JSON(currentTime))
Expand Down
28 changes: 12 additions & 16 deletions Plugins/Phoenix/PhoenixAnalyticsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,22 @@ public class PhoenixAnalyticsPlugin: PKPlugin, KalturaPluginManagerDelegate {
}

if let builder: KalturaRequestBuilder = BookmarkService.actionAdd(baseURL: baseUrl,
partnerId: parterId,
ks: ks,
eventType: action.rawValue.uppercased(),
currentTime: self.player.currentTime.toInt32(),
assetId: mediaEntry.id,
fileId: fileId) {
partnerId: parterId,
ks: ks,
eventType: action.rawValue.uppercased(),
currentTime: self.player.currentTime.toInt32(),
assetId: mediaEntry.id,
fileId: fileId) {
builder.set { (response: Response) in
PKLog.trace("Response: \(response)")
if response.statusCode == 0 {
PKLog.trace("\(response.data)")
if let data : [String: Any] = response.data as! [String : Any]? {
if let result = data["result"] as! [String: Any]? {
if let errorData = result["error"] as! [String: Any]? {
if let errorCode = errorData["code"] as? Int, errorCode == 4001 {

self.kalturaPluginManager.reportConcurrencyEvent()
}
}
}
}
PKLog.trace("\(response.data)")
guard let data = response.data as? [String : Any] else { return }
guard let result = data["result"] as? [String: Any] else { return }
guard let errorData = result["error"] as? [String: Any] else { return }
guard let errorCode = errorData["code"] as? Int, errorCode == 4001 else { return }
self.kalturaPluginManager.reportConcurrencyEvent()
}
}
USRExecutor.shared.send(request: builder.build())
Expand Down
36 changes: 15 additions & 21 deletions Plugins/Phoenix/TVPAPIAnalyticsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,50 +54,44 @@ public class TVPAPIAnalyticsPlugin: PKPlugin, KalturaPluginManagerDelegate {

var fileId = ""
var baseUrl = ""
var initObj : JSON? = nil

guard let initObj = self.config?.params["initObj"] as? [String : Any] else {
PKLog.error("send analytics failed due to no initObj data")
return
}

guard let mediaEntry = self.mediaEntry else {
PKLog.error("send analytics failed due to nil mediaEntry")
return
}

let method = action == .hit ? "MediaHit" : "MediaMark"

if let url = self.config?.params["baseUrl"] as? String {
baseUrl = url
}
if let fId = self.config?.params["fileId"] as? String {
fileId = fId
}
if let obj = self.config?.params["initObj"] as? JSON {
initObj = obj
}


baseUrl = "\(baseUrl)m=\(method)"

guard let mediaEntry = self.mediaEntry else {
PKLog.error("send analytics failed due to nil mediaEntry")
return
}

if let builder: RequestBuilder = MediaMarkService.sendTVPAPIEVent(baseURL: baseUrl,
initObj: initObj,
eventType: action.rawValue,
currentTime: self.player.currentTime.toInt32(),
assetId: mediaEntry.id,
fileId: fileId) {
builder.set { (response: Response) in

PKLog.trace("Response: \(response)")
if response.statusCode == 0 {

PKLog.trace("\(response.data)")
if let data : [String: Any] = response.data as! [String : Any]? {
if let result = data["concurrent"] as! [String: Any]? {
self.kalturaPluginManager.reportConcurrencyEvent()
}
}

guard let data : [String: Any] = response.data as? [String : Any] else { return }
guard let result = data["concurrent"] as? [String : Any] else { return }
self.kalturaPluginManager.reportConcurrencyEvent()
}
}

USRExecutor.shared.send(request: builder.build())

}

}
Expand Down

0 comments on commit 42f365b

Please sign in to comment.