From d637e14f5e7047fd1fbcd5b36991d6117b6425a3 Mon Sep 17 00:00:00 2001 From: Artem Yelizarov Date: Tue, 11 Jun 2024 15:53:35 +0300 Subject: [PATCH] Describe user-agent header configuration --- .../Resources/PlayBackDemoApp.swift | 11 +++--- .../PlayBackDemoAppWithUserAgent.swift | 38 +++++++++++++++++++ .../Tutorial/GetStarted.tutorial | 11 ++++-- 3 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 Sources/PlaybackSDK/Documentation.docc/Resources/PlayBackDemoAppWithUserAgent.swift diff --git a/Sources/PlaybackSDK/Documentation.docc/Resources/PlayBackDemoApp.swift b/Sources/PlaybackSDK/Documentation.docc/Resources/PlayBackDemoApp.swift index a1bec0f..dc1847a 100644 --- a/Sources/PlaybackSDK/Documentation.docc/Resources/PlayBackDemoApp.swift +++ b/Sources/PlaybackSDK/Documentation.docc/Resources/PlayBackDemoApp.swift @@ -3,7 +3,7 @@ import PlaybackSDK @main struct PlayBackDemoApp: App { - + let sdkManager = PlayBackSDKManager() let apiKey = "API_KEY" var body: some Scene { @@ -11,7 +11,7 @@ struct PlayBackDemoApp: App { HomeView() } } - + init() { // Initialize the Playback SDK with the provided API key and base URL PlayBackSDKManager.shared.initialize(apiKey: apiKey) { result in @@ -19,16 +19,17 @@ struct PlayBackDemoApp: App { case .success(let license): // Obtained license upon successful initialization print("SDK initialized with license: \(license)") - + // Register the video player plugin let bitmovinPlugin = BitmovinPlayerPlugin() VideoPlayerPluginManager.shared.registerPlugin(bitmovinPlugin) - + case .failure(let error): // Print an error message and set initializationError flag upon initialization failure print("SDK initialization failed with error: \(error)") - + } } } } + diff --git a/Sources/PlaybackSDK/Documentation.docc/Resources/PlayBackDemoAppWithUserAgent.swift b/Sources/PlaybackSDK/Documentation.docc/Resources/PlayBackDemoAppWithUserAgent.swift new file mode 100644 index 0000000..8a04146 --- /dev/null +++ b/Sources/PlaybackSDK/Documentation.docc/Resources/PlayBackDemoAppWithUserAgent.swift @@ -0,0 +1,38 @@ +import SwiftUI +import PlaybackSDK +import Alamofire + +@main +struct PlayBackDemoApp: App { + + let sdkManager = PlayBackSDKManager() + let apiKey = "API_KEY" + var body: some Scene { + WindowGroup { + HomeView() + } + } + + init() { + // Get the user-agent set by Alamofire + let userAgent = AF.session.configuration.httpAdditionalHeaders?["User-Agent"] + + // Initialize the Playback SDK with the provided API key and custom user-agent + PlayBackSDKManager.shared.initialize(apiKey: apiKey, userAgent: userAgent) { result in + switch result { + case .success(let license): + // Obtained license upon successful initialization + print("SDK initialized with license: \(license)") + + // Register the video player plugin + let bitmovinPlugin = BitmovinPlayerPlugin() + VideoPlayerPluginManager.shared.registerPlugin(bitmovinPlugin) + + case .failure(let error): + // Print an error message and set initializationError flag upon initialization failure + print("SDK initialization failed with error: \(error)") + + } + } + } +} diff --git a/Sources/PlaybackSDK/Documentation.docc/Tutorial/GetStarted.tutorial b/Sources/PlaybackSDK/Documentation.docc/Tutorial/GetStarted.tutorial index 8ce0857..75f5176 100644 --- a/Sources/PlaybackSDK/Documentation.docc/Tutorial/GetStarted.tutorial +++ b/Sources/PlaybackSDK/Documentation.docc/Tutorial/GetStarted.tutorial @@ -16,14 +16,20 @@ @Steps { @Step { - **Step 1:** Initialize the Playback SDK by providing your API key and register the default player plugin. + Initialize the Playback SDK by providing your API key and register the default player plugin. **Make sure this step is done when the app starts.** @Code(name: "PlayBackDemoApp.swift", file: PlayBackDemoApp.swift) } @Step { - **Step 2:** + Add custom `user-agent` header. + + This step is only required for content that needs a token, when using Alamofire or other 3rd party frameworks that overwrite the standard `user-agent` header with their own. + If the content requires starting a CloudPay session, it's important that the request to start the session has the same `user-agent` header as the video loading requests from the player. This can be achieved either by disabling the overwriting behaviour in the 3rd party networking framework you're using, or by passing a `userAgent` parameter to the `initialize` method, like in this example with Alamofire. + @Code(name: "PlayBackDemoAppWithUserAgent.swift", file: PlayBackDemoAppWithUserAgent.swift, previousFile: PlayBackDemoApp.swift) + } + @Step { Load the player using the Playback SDK and handle any playback errors. In this step, the code utilizes the **loadPlayer** function provided by the Playback SDK to initialize and load the video player. The function takes the entry ID and authorization token as parameters. Additionally, it includes a closure to handle any potential playback errors that may occur during the loading process. @@ -35,7 +41,6 @@ @Code(name: "PlayerTestView.swift", file: PlayerTestView.swift) } @Step { - **Step 3:** Handle the playback errors from Playback SDK. This step describes enum for error handling. Above is the error enum returned by the SDK, where the apiError also has the reason code and message for the API error. The playback API is returning the reason code in the response. For the list of the error codes and reasons, please refer to [Get Video Playback Data | Playback](https://streamamg.stoplight.io/docs/playback-documentation-portal/ec642e6dcbb13-get-video-playback-data)