Skip to content

Commit

Permalink
Merge branch 'main' into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
francodriansetti committed Mar 21, 2024
2 parents 9710cc6 + c73bf28 commit 9c4474b
Show file tree
Hide file tree
Showing 99 changed files with 569 additions and 455 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/branch-protection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "Branch protection"
on:
pull_request:
types: [opened, edited, reopened, synchronize]

jobs:
test_job:
runs-on: ubuntu-latest
name: Branch naming protection check.
steps:
- uses: knawat/github-actions-gitflow@v1
20 changes: 20 additions & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This workflow will build a Swift project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift

name: SPM Build and Test

on:
push:
branches: [ "feature/unit-test" ]
pull_request:
branches: [ "feature/unit-test" ]

jobs:
build:

runs-on: macos-latest

steps:
- uses: actions/checkout@v4
- name: Build and run tests
run: xcodebuild test -scheme PlaybackSDK -destination 'platform=iOS Simulator,name=iPhone 13'
66 changes: 66 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/PlaybackSDK-Package.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "PlaybackSDK"
BuildableName = "PlaybackSDK"
BlueprintName = "PlaybackSDK"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "PlaybackSDK"
BuildableName = "PlaybackSDK"
BlueprintName = "PlaybackSDK"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
22 changes: 22 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/PlaybackSDKTests.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<CommandLineArguments>
<CommandLineArgument
argument = "API_KEY=f3Beljhmlz2ea7M9TfErE6mKPsAcY3BrasMMEG24"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "ENTRY_ID=0_k3mz0mf8"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
<EnvironmentVariables>
<EnvironmentVariable
key = "API_KEY"
value = "f3Beljhmlz2ea7M9TfErE6mKPsAcY3BrasMMEG24"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "ENTRY_ID"
value = "0_k3mz0mf8"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Playback SDK
------------

[![Swift](https://github.com/StreamAMG/playback-sdk-ios/actions/workflows/swift.yml/badge.svg)](https://github.com/StreamAMG/playback-sdk-ios/actions/workflows/swift.yml)

[![pages-build-deployment](https://github.com/StreamAMG/playback-sdk-ios/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/StreamAMG/playback-sdk-ios/actions/workflows/pages/pages-build-deployment)

This library simplifies integrating video playback functionalities into OTT applications. It provides a unified interface for interacting with video APIs and managing playback logic.

**Key Features:**
Expand All @@ -13,6 +17,13 @@ This library simplifies integrating video playback functionalities into OTT appl

- Platforms: iOS 14 and later

**Getting Started**

To initialize the SDK, you will need an **API key**, which can be obtained by contacting your StreamAMG account manager. Additionally, to use the playback default plugin, your app needs to be **whitelisted**. Please communicate the bundle ID of your app to your StreamAMG account manager for whitelisting.

Once you have obtained the API key and your app has been whitelisted, you can proceed with the initialisation of the SDK in your project.


**Installation**

1. Add the Playback SDK dependency to your project using Swift Package Manager.
Expand All @@ -21,12 +32,12 @@ Swift

```
dependencies: [
.package(url: "https://github.com/your-organization/playback-sdk.git", .branch("master"))
.package(url: "https://github.com/StreamAMG/playback-sdk-ios", .branch("main"))
]
```

1. Import the `PlaybackSDK` module in your Swift files.
2. Import the `PlaybackSDK` module in your Swift files.

Swift

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ struct PlayerTestView: View {

private func handlePlaybackError(_ error: PlaybackError) {
switch error {
case .apiError(let statusCode, let errorMessage):
case .apiError(let statusCode, let errorMessage, let reason):
print("\(errorMessage) Status Code \(statusCode)")
errorMessage = "\(errorMessage) Status Code \(statusCode)"
errorMessage = "\(errorMessage) Status Code \(statusCode) Reason \(reason)"
default:
print("Error loading HLS stream in PlaybackUIView: \(error.localizedDescription)")
errorMessage = "Error code and errorrMessage not found: \(error.localizedDescription)"
Expand Down
4 changes: 2 additions & 2 deletions Sources/PlaybackSDK/PlayBack API/PlayBackAPIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ internal class PlayBackAPIService: PlayBackAPI {
default:
let decoder = JSONDecoder()
if let errorResponse = try? decoder.decode(PlaybackResponseModel.self, from: data) {
throw PlayBackAPIError.apiError(statusCode: httpResponse.statusCode, message: errorResponse.message ?? "Unknown authentication error message")
throw PlayBackAPIError.apiError(statusCode: httpResponse.statusCode, message: errorResponse.message ?? "Unknown authentication error message", reason: errorResponse.reason ?? "Unknown authentication error reason")
} else {
throw PlayBackAPIError.apiError(statusCode: httpResponse.statusCode, message: "Unknown authentication error")
throw PlayBackAPIError.apiError(statusCode: httpResponse.statusCode, message: "Unknown authentication error", reason: "Unknown authentication error reason")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
// Struct representing the response model for playback data, conforming to the Decodable protocol.
internal struct PlaybackResponseModel: Decodable {
let message: String?
let reason: String?
let id: String?
let name: String?
let description: String?
Expand Down
4 changes: 2 additions & 2 deletions Sources/PlaybackSDK/PlayBackSDKManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public enum PlayBackAPIError: Error {
case loadHLSStreamError

case networkError(Error)
case apiError(statusCode: Int, message: String)
case apiError(statusCode: Int, message: String, reason: String)
}


Expand Down Expand Up @@ -96,7 +96,7 @@ public class PlayBackSDKManager {
```swift
let playerView = loadPlayer(entryID: "exampleEntryID", authorizationToken: "exampleToken")
*/
public func loadPlayer(entryID: String, authorizationToken: String, onError: ((PlayBackAPIError) -> Void)?) -> some View {
public func loadPlayer(entryID: String, authorizationToken: String? = nil, onError: ((PlayBackAPIError) -> Void)?) -> some View {
return PlaybackUIView(entryId: entryID, authorizationToken: authorizationToken, onError: onError)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public class BitmovinPlayerPlugin: VideoPlayerPlugin {
}

public func removePlayer() {
player?.player.destroy()
player = nil
// TODO: Remove properly
}
}

Expand Down
4 changes: 0 additions & 4 deletions Sources/PlaybackSDK/PlayerUIView/UtilsUIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,4 @@ internal struct ErrorUIView: View {
.padding()
}
}

#Preview {
ErrorUIView(errorMessage: "Error message")
}
#endif
39 changes: 0 additions & 39 deletions Tests/PlaybackSDKTests/MockPlayerInformationAPI.swift

This file was deleted.

42 changes: 37 additions & 5 deletions Tests/PlaybackSDKTests/PlayBackSDKManagerTests.swift.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// PlayBackSDKManagerTests.swift.swift
//
//
//
// Created by Franco Driansetti on 29/02/2024.
//
Expand All @@ -14,12 +14,15 @@ class PlayBackSDKManagerTests: XCTestCase {
var cancellables = Set<AnyCancellable>()
var manager: PlayBackSDKManager!
var apiKey: String!
var entryID: String!

override func setUpWithError() throws {
try super.setUpWithError()
manager = PlayBackSDKManager()
apiKey = ProcessInfo.processInfo.environment["API_KEY"]
apiKey = TestConfig.testAPIKey
XCTAssertNotNil(apiKey, "API key should be provided via environment variable")
entryID = TestConfig.testEntryID
XCTAssertNotNil(entryID, "Entry ID should be provided via environment variable")
}

override func tearDownWithError() throws {
Expand All @@ -40,7 +43,6 @@ class PlayBackSDKManagerTests: XCTestCase {
case .success(let license):
XCTAssertNotNil(license, "Bitmovin license should not be nil")
XCTAssertFalse(license.isEmpty, "Bitmovin license should not be empty")
XCTAssertEqual(license, "12345678-1111-1111-1111-123456789012", "Expected Bitmovin license not received")
expectation.fulfill()
case .failure(let error):
XCTFail("Initialization failed with error: \(error.localizedDescription)")
Expand All @@ -50,6 +52,32 @@ class PlayBackSDKManagerTests: XCTestCase {
waitForExpectations(timeout: 5, handler: nil)
}

func testLoadHLSStream() {
let initializationExpectation = expectation(description: "SDK initialization")
manager.initialize(apiKey: apiKey) { result in
switch result {
case .success:
initializationExpectation.fulfill()
case .failure(let error):
XCTFail("SDK initialization failed with error: \(error.localizedDescription)")
}
}
waitForExpectations(timeout: 5, handler: nil)

let hlsExpectation = expectation(description: "HLS stream loading expectation")
manager.loadHLSStream(forEntryId: entryID, andAuthorizationToken: nil) { result in
switch result {
case .success(let hlsURL):
XCTAssertNotNil(hlsURL, "HLS stream URL should not be nil")
hlsExpectation.fulfill()
case .failure(let error):
XCTFail("Loading HLS stream failed with error: \(error.localizedDescription)")
}
}

waitForExpectations(timeout: 5, handler: nil)
}

func testInitializeWithEmptyAPIKey() {
let expectation = expectation(description: "Initialization expectation")

Expand All @@ -65,6 +93,10 @@ class PlayBackSDKManagerTests: XCTestCase {

waitForExpectations(timeout: 5, handler: nil)
}

// Add more tests for other functionalities as needed

func testLoadPlayer() {
let playerView = manager.loadPlayer(entryID: "exampleEntryID", authorizationToken: "exampleToken", onError: { _ in })
// Assert that playerView is not nil or do further UI testing if possible
XCTAssertNotNil(playerView)
}
}
13 changes: 13 additions & 0 deletions Tests/PlaybackSDKTests/TestConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// File.swift
//
//
// Created by Franco Driansetti on 01/03/2024.
//

import Foundation

internal struct TestConfig {
static let testAPIKey = "f3Beljhmlz2ea7M9TfErE6mKPsAcY3BrasMMEG24"
static let testEntryID = "0_k3mz0mf8"
}
9 changes: 9 additions & 0 deletions docs/css/523.e9a069b0.css

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions docs/css/675.40c3bcb2.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9c4474b

Please sign in to comment.