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 1 commit
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
4 changes: 2 additions & 2 deletions Sources/PlaybackSDK/PlayBackSDKManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ public class PlayBackSDKManager {
entryID: String,
authorizationToken: String? = nil,
mediaTitle: String? = nil,
userId: String? = nil,
viewerId: String? = nil,
KharchenkoAlex marked this conversation as resolved.
Show resolved Hide resolved
onError: ((PlayBackAPIError) -> Void)?
) -> some View {

PlaybackUIView(
entryId: entryID,
authorizationToken: authorizationToken,
mediaTitle: mediaTitle,
userId: userId,
viewerId: viewerId,
onError: onError
)
.id(entryID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@ public class BitmovinPlayerPlugin: VideoPlayerPlugin {
playerConfig.styleConfig.userInterfaceConfig = uiConfig
}

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

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

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

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, userId: String?) -> AnyView
func playerView(hlsURLString: String, title: String, viewerId: String?) -> AnyView

func play()

Expand Down
8 changes: 4 additions & 4 deletions Sources/PlaybackSDK/PlayerUIView/PlaybackUIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal struct PlaybackUIView: View {
private var authorizationToken: String?

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

/// Observed object to manage the video player plugins.
@ObservedObject private var pluginManager = VideoPlayerPluginManager.shared
Expand All @@ -43,12 +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?, userId: String?, onError: ((PlayBackAPIError) -> Void)?) {
internal init(entryId: String, authorizationToken: String?, mediaTitle: String?, viewerId: String?, onError: ((PlayBackAPIError) -> Void)?) {
self.entryId = entryId
self.authorizationToken = authorizationToken
self.onError = onError
self.mediaTitle = mediaTitle
self.userId = userId
self.viewerId = viewerId
}

/// The body of the view.
Expand All @@ -62,7 +62,7 @@ internal struct PlaybackUIView: View {
} else {
if let videoURL = videoURL {
if let plugin = pluginManager.selectedPlugin {
plugin.playerView(hlsURLString: videoURL.absoluteString, title: self.mediaTitle ?? "", userId: self.userId)
plugin.playerView(hlsURLString: videoURL.absoluteString, title: self.mediaTitle ?? "", viewerId: self.viewerId)
} else {
ErrorUIView(errorMessage: "No plugin selected")
.background(Color.white)
Expand Down