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

Remove custom server initializer #1133

Merged
merged 1 commit into from
Feb 5, 2025
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
15 changes: 3 additions & 12 deletions Demo/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -379,22 +379,13 @@
"URN" : {

},
"URN (IL Production)" : {
"URN (Production)" : {

},
"URN (IL Stage)" : {
"URN (Stage)" : {

},
"URN (IL Test)" : {

},
"URN (SAM Production)" : {

},
"URN (SAM Stage)" : {

},
"URN (SAM Test)" : {
"URN (Test)" : {

},
"Use a proxy tool to observe events." : {
Expand Down
4 changes: 2 additions & 2 deletions Demo/Sources/ContentLists/ContentListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private struct LoadedView: View {
@EnvironmentObject private var router: Router

@AppStorage(UserDefaults.DemoSettingKey.serverSetting.rawValue)
private var serverSetting: ServerSetting = .ilProduction
private var serverSetting: ServerSetting = .production

var body: some View {
CustomList(data: contents) { content in
Expand Down Expand Up @@ -65,7 +65,7 @@ private struct ContentCell: View {
let content: ContentListViewModel.Content

@AppStorage(UserDefaults.DemoSettingKey.serverSetting.rawValue)
private var serverSetting: ServerSetting = .ilProduction
private var serverSetting: ServerSetting = .production

@EnvironmentObject private var router: Router

Expand Down
2 changes: 1 addition & 1 deletion Demo/Sources/ContentLists/ContentListsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI
// Behavior: h-exp, v-exp
struct ContentListsView: View {
@AppStorage(UserDefaults.DemoSettingKey.serverSetting.rawValue)
private var selectedServerSetting: ServerSetting = .ilProduction
private var selectedServerSetting: ServerSetting = .production

var body: some View {
CustomList {
Expand Down
41 changes: 14 additions & 27 deletions Demo/Sources/Examples/ExamplesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@ private struct MediaEntryView: View {
case url
case tokenProtected
case encrypted
case ilProductionUrn
case ilStageUrn
case ilTestUrn
case samProductionUrn
case samStageUrn
case samTestUrn
case productionUrn
case stageUrn
case testUrn
}

@State private var kind: Kind = .url
Expand All @@ -74,18 +71,12 @@ private struct MediaEntryView: View {
case .encrypted:
guard let url, let certificateUrl else { return URLMedia.unknown }
return .init(title: "Encrypted", type: .encryptedUrl(url, certificateUrl: certificateUrl))
case .ilProductionUrn:
return .init(title: trimmedText, type: .urn(trimmedText, serverSetting: .ilProduction))
case .ilStageUrn:
return .init(title: trimmedText, type: .urn(trimmedText, serverSetting: .ilStage))
case .ilTestUrn:
return .init(title: trimmedText, type: .urn(trimmedText, serverSetting: .ilTest))
case .samProductionUrn:
return .init(title: trimmedText, type: .urn(trimmedText, serverSetting: .samProduction))
case .samStageUrn:
return .init(title: trimmedText, type: .urn(trimmedText, serverSetting: .samStage))
case .samTestUrn:
return .init(title: trimmedText, type: .urn(trimmedText, serverSetting: .samTest))
case .productionUrn:
return .init(title: trimmedText, type: .urn(trimmedText, serverSetting: .production))
case .stageUrn:
return .init(title: trimmedText, type: .urn(trimmedText, serverSetting: .stage))
case .testUrn:
return .init(title: trimmedText, type: .urn(trimmedText, serverSetting: .test))
}
}

Expand All @@ -103,7 +94,7 @@ private struct MediaEntryView: View {

private var textPlaceholder: String {
switch kind {
case .ilProductionUrn, .ilStageUrn, .ilTestUrn, .samProductionUrn, .samStageUrn, .samTestUrn:
case .productionUrn, .stageUrn, .testUrn:
return "URN"
default:
return "URL"
Expand All @@ -112,7 +103,7 @@ private struct MediaEntryView: View {

private var isValid: Bool {
switch kind {
case .ilProductionUrn, .ilStageUrn, .ilTestUrn, .samProductionUrn, .samStageUrn, .samTestUrn:
case .productionUrn, .stageUrn, .testUrn:
return !text.isEmpty
case .encrypted:
return url != nil && certificateUrl != nil
Expand Down Expand Up @@ -146,13 +137,9 @@ private struct MediaEntryView: View {
Text("URL with SRG SSR token protection").tag(Kind.tokenProtected)
Text("URL with SRG SSR DRM encryption").tag(Kind.encrypted)
Divider()
Text("URN (IL Production)").tag(Kind.ilProductionUrn)
Text("URN (IL Stage)").tag(Kind.ilStageUrn)
Text("URN (IL Test)").tag(Kind.ilTestUrn)
Divider()
Text("URN (SAM Production)").tag(Kind.samProductionUrn)
Text("URN (SAM Stage)").tag(Kind.samStageUrn)
Text("URN (SAM Test)").tag(Kind.samTestUrn)
Text("URN (Production)").tag(Kind.productionUrn)
Text("URN (Stage)").tag(Kind.stageUrn)
Text("URN (Test)").tag(Kind.testUrn)
}
#if os(tvOS)
.pickerStyle(.navigationLink)
Expand Down
2 changes: 1 addition & 1 deletion Demo/Sources/Model/Media.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct Media: Hashable {
case urn(String, serverSetting: ServerSetting)

static func urn(_ urn: String) -> Self {
.urn(urn, serverSetting: .ilProduction)
.urn(urn, serverSetting: .production)
}
}

Expand Down
91 changes: 20 additions & 71 deletions Demo/Sources/Model/ServerSetting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,95 +9,44 @@ import SRGDataProvider

@objc
enum ServerSetting: Int, CaseIterable {
case ilProduction
case ilStage
case ilTest

case ilProductionCH
case ilStageCH
case ilTestCH

case ilProductionWW
case ilStageWW
case ilTestWW

case samProduction
case samStage
case samTest
case production
case stage
case test

var title: String {
switch self {
case .ilProduction:
return "IL Production"
case .ilStage:
return "IL Stage"
case .ilTest:
return "IL Test"
case .ilProductionCH:
return "IL Production - CH"
case .ilStageCH:
return "IL Stage - CH"
case .ilTestCH:
return "IL Test - CH"
case .ilProductionWW:
return "IL Production - WW"
case .ilStageWW:
return "IL Stage - WW"
case .ilTestWW:
return "IL Test - WW"
case .samProduction:
return "SAM Production"
case .samStage:
return "SAM Stage"
case .samTest:
return "SAM Test"
case .production:
return "Production"
case .stage:
return "Stage"
case .test:
return "Test"
}
}

var dataProvider: SRGDataProvider {
let dataProvider = SRGDataProvider(serviceURL: baseUrl)
dataProvider.globalParameters = globalParameters
return dataProvider
.init(serviceURL: baseUrl)
}

private var baseUrl: URL {
switch self {
case .ilProduction, .ilProductionCH, .ilProductionWW:
case .production:
return SRGIntegrationLayerProductionServiceURL()
case .ilStage, .ilStageCH, .ilStageWW:
case .stage:
return SRGIntegrationLayerStagingServiceURL()
case .ilTest, .ilTestCH, .ilTestWW:
case .test:
return SRGIntegrationLayerTestServiceURL()
case .samProduction:
return SRGIntegrationLayerProductionServiceURL().appending(component: "sam")
case .samStage:
return SRGIntegrationLayerStagingServiceURL().appending(component: "sam")
case .samTest:
return SRGIntegrationLayerTestServiceURL().appending(component: "sam")
}
}

private var globalParameters: [String: String] {
.init(uniqueKeysWithValues: queryItems.compactMap { item in
guard let value = item.value else { return nil }
return (item.name, value)
})
}

private var queryItems: [URLQueryItem] {
var server: Server {
switch self {
case .ilProductionCH, .ilStageCH, .ilTestCH:
return [URLQueryItem(name: "forceLocation", value: "CH")]
case .ilProductionWW, .ilStageWW, .ilTestWW:
return [URLQueryItem(name: "forceLocation", value: "WW")]
case .samProduction, .samStage, .samTest:
return [URLQueryItem(name: "forceSAM", value: "true")]
default:
return []
case .production:
return .production
case .stage:
return .stage
case .test:
return .test
}
}

var server: Server {
.init(baseUrl: baseUrl, queryItems: queryItems)
}
}
4 changes: 2 additions & 2 deletions Demo/Sources/Settings/UserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extension UserDefaults {
}

@objc dynamic var serverSetting: ServerSetting {
.init(rawValue: integer(forKey: DemoSettingKey.serverSetting.rawValue)) ?? .ilProduction
.init(rawValue: integer(forKey: DemoSettingKey.serverSetting.rawValue)) ?? .production
}

@objc dynamic var qualitySetting: QualitySetting {
Expand All @@ -55,7 +55,7 @@ extension UserDefaults {
DemoSettingKey.presenterModeEnabled.rawValue: false,
DemoSettingKey.seekBehaviorSetting.rawValue: SeekBehaviorSetting.immediate.rawValue,
DemoSettingKey.smartNavigationEnabled.rawValue: true,
DemoSettingKey.serverSetting.rawValue: ServerSetting.ilProduction.rawValue,
DemoSettingKey.serverSetting.rawValue: ServerSetting.production.rawValue,
DemoSettingKey.qualitySetting.rawValue: QualitySetting.high.rawValue
])
}
Expand Down
23 changes: 2 additions & 21 deletions Sources/CoreBusiness/DataProvider/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,13 @@ public struct Server {
public static let test = Self(baseUrl: URL(string: "https://il-test.srgssr.ch")!)

private let baseUrl: URL
private let queryItems: [URLQueryItem]

/// This API will be removed in a future Pillarbox release. Do not use.
///
/// > Warning: This API will be removed in a future Pillarbox release. Do not use.
public init(baseUrl: URL, queryItems: [URLQueryItem] = []) {
// FIXME: This initializer must be made private after SAM replaces the IL. The assertion must be removed at
// the same time.
assert(Bundle.main.allowsReservedInitializer, "This API will be removed in a future Pillarbox release. Do not use.")
self.baseUrl = baseUrl
self.queryItems = queryItems
}

func mediaCompositionRequest(forUrn urn: String) -> URLRequest {
let url = baseUrl.appending(path: "integrationlayer/2.1/mediaComposition/byUrn/\(urn)")
guard var components = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
return .init(url: url)
}
components.queryItems = queryItems + [
components.queryItems = [
URLQueryItem(name: "onlyChapters", value: "true"),
URLQueryItem(name: "vector", value: Self.vector)
]
Expand All @@ -56,7 +44,7 @@ public struct Server {
) else {
return url
}
components.queryItems = queryItems + [
components.queryItems = [
URLQueryItem(name: "imageUrl", value: url.absoluteString),
URLQueryItem(name: "format", value: "jpg"),
URLQueryItem(name: "width", value: String(width.rawValue))
Expand All @@ -69,10 +57,3 @@ public struct Server {
}
}
}

private extension Bundle {
var allowsReservedInitializer: Bool {
guard let bundleIdentifier = Bundle.main.bundleIdentifier else { return false }
return bundleIdentifier.hasPrefix("ch.srgssr.Pillarbox-demo") || bundleIdentifier.hasPrefix("com.apple.dt.xctest.tool")
}
}