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

[CORE-5162] Implementation for Bitmovin analytics #27

Merged
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
5 changes: 4 additions & 1 deletion Sources/PlaybackSDK/PlayBackSDKManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,27 @@ public class PlayBackSDKManager {
- Parameters:
- entryID: The unique identifier of the video entry to be loaded.
- authorizationToken: The token used for authorization to access the video content.
- analyticsViewerId: User identifier to be tracked in analytics

- Returns: A view representing the video player configured with the provided entry ID and authorization token.

Example usage:
```swift
let playerView = loadPlayer(entryID: "exampleEntryID", authorizationToken: "exampleToken")
let playerView = loadPlayer(entryID: "exampleEntryID", authorizationToken: "exampleToken", analyticsViewerId: "1234abcd")
*/
public func loadPlayer(
entryID: String,
authorizationToken: String? = nil,
mediaTitle: String? = nil,
analyticsViewerId: String? = nil,
onError: ((PlayBackAPIError) -> Void)?
) -> some View {

PlaybackUIView(
entryId: entryID,
authorizationToken: authorizationToken,
mediaTitle: mediaTitle,
analyticsViewerId: analyticsViewerId,
onError: onError
)
.id(entryID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public struct BitMovinPlayerView: View {
public init(hlsURLString: String, playerConfig: PlayerConfig, title: String) {

self.hlsURLString = hlsURLString

let uiConfig = BitmovinUserInterfaceConfig()
uiConfig.hideFirstFrame = true
playerConfig.styleConfig.userInterfaceConfig = uiConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,23 @@ public class BitmovinPlayerPlugin: VideoPlayerPlugin {
playerConfig.styleConfig.userInterfaceConfig = uiConfig
}

public func playerView(hlsURLString: String, title: String = "") -> AnyView {
private func createAnalyticsConfig(analyticsViewerId: String? = nil) -> AnalyticsPlayerConfig {
guard let licenseKey = PlayBackSDKManager.shared.bitmovinLicense else {
return .disabled
}
let defaultMetadata = DefaultMetadata(cdnProvider: "PlaybackSDK", customUserId: analyticsViewerId)
let analytics: BitmovinPlayerAnalytics.AnalyticsPlayerConfig = licenseKey != nil
? .enabled(analyticsConfig: AnalyticsConfig(licenseKey: licenseKey), defaultMetadata: defaultMetadata)
: .disabled
return analytics
}

public func playerView(hlsURLString: String, title: String = "", analyticsViewerId: String? = nil) -> AnyView {

// Create player based on player and analytics configurations
let player = PlayerFactory.createPlayer(
playerConfig: playerConfig
playerConfig: playerConfig,
analytics: self.createAnalyticsConfig(analyticsViewerId: analyticsViewerId)
)

self.player = player
Expand Down
2 changes: 1 addition & 1 deletion Sources/PlaybackSDK/Player Plugin/VideoPlayerPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public protocol VideoPlayerPlugin: AnyObject {
// TODO: add event
/// func handleEvent(event: BitmovinPlayerCore.PlayerEvent)

func playerView(hlsURLString: String, title: String) -> AnyView
func playerView(hlsURLString: String, title: String, analyticsViewerId: String?) -> AnyView

func play()

Expand Down
10 changes: 8 additions & 2 deletions Sources/PlaybackSDK/PlayerUIView/PlaybackUIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ internal struct PlaybackUIView: View {
/// Optional authorization token if required to fetch the video details.
private var authorizationToken: String?

/// Optional user ID to be tracked in analytics
private var analyticsViewerId: String?

/// Observed object to manage the video player plugins.
@ObservedObject private var pluginManager = VideoPlayerPluginManager.shared

Expand All @@ -40,11 +43,12 @@ internal struct PlaybackUIView: View {
- entryId: The entry ID of the video to be played.
- authorizationToken: Optional authorization token if required to fetch the video details.
*/
internal init(entryId: String, authorizationToken: String?, mediaTitle: String?, onError: ((PlayBackAPIError) -> Void)?) {
internal init(entryId: String, authorizationToken: String?, mediaTitle: String?, analyticsViewerId: String?, onError: ((PlayBackAPIError) -> Void)?) {
self.entryId = entryId
self.authorizationToken = authorizationToken
self.onError = onError
self.mediaTitle = mediaTitle
self.analyticsViewerId = analyticsViewerId
}

/// The body of the view.
Expand All @@ -58,7 +62,9 @@ internal struct PlaybackUIView: View {
} else {
if let videoURL = videoURL {
if let plugin = pluginManager.selectedPlugin {
plugin.playerView(hlsURLString: videoURL.absoluteString, title: self.mediaTitle ?? "")
plugin.playerView(hlsURLString: videoURL.absoluteString,
title: self.mediaTitle ?? "",
analyticsViewerId: self.analyticsViewerId)
} else {
ErrorUIView(errorMessage: "No plugin selected")
.background(Color.white)
Expand Down
2 changes: 1 addition & 1 deletion Tests/PlaybackSDKTests/TestConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import Foundation

internal struct TestConfig {
static let testAPIKey = "EJEZPIezBkaf0EQ7ey5Iu2MDA2ARUkgc79eyDOnG"
static let testEntryID = "0_qt9cy11s"
static let testEntryID = "0_cmk35zei"
}