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

Improve remote configuration for Service URL overrides #540

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"tvSiteName": "rsi-player-tvos-apple",
"voiceOverLanguageCode": "it",
"appStoreProductIdentifier": 920753497,
"serviceURL": "https://il.srf.ch",
"playURLs": "{\"rsi\":\"https://www.rsi.ch/play/\",\"rtr\":\"https://www.rtr.ch/play/\",\"rts\":\"https://www.rts.ch/play/\",\"srf\":\"https://www.srf.ch/play/\",\"swi\":\"https://play.swissinfo.ch/play/\"}",
"playServiceURL": "https://www.rsi.ch/play/",
"middlewareURL": "https://playfff.herokuapp.com",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"siteName": "rtr-player-ios-v",
"tvSiteName": "rtr-player-tvos-apple",
"appStoreProductIdentifier": 920754925,
"serviceURL": "https://il.srf.ch",
"playURLs": "{\"rsi\":\"https://www.rsi.ch/play/\",\"rtr\":\"https://www.rtr.ch/play/\",\"rts\":\"https://www.rts.ch/play/\",\"srf\":\"https://www.srf.ch/play/\",\"swi\":\"https://play.swissinfo.ch/play/\"}",
"playServiceURL": "https://www.rtr.ch/play/",
"middlewareURL": "https://playfff.herokuapp.com",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"tvSiteName": "rts-player-tvos-apple",
"voiceOverLanguageCode": "fr",
"appStoreProductIdentifier": 920754415,
"serviceURL": "https://il.srf.ch",
"playURLs": "{\"rsi\":\"https://www.rsi.ch/play/\",\"rtr\":\"https://www.rtr.ch/play/\",\"rts\":\"https://www.rts.ch/play/\",\"srf\":\"https://www.srf.ch/play/\",\"swi\":\"https://play.swissinfo.ch/play/\"}",
"playServiceURL": "https://www.rts.ch/play/",
"middlewareURL": "https://playfff.herokuapp.com",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"tvSiteName": "srf-player-tvos-apple",
"voiceOverLanguageCode": "de",
"appStoreProductIdentifier": 638194352,
"serviceURL": "https://il.srf.ch",
"playURLs": "{\"rsi\":\"https://www.rsi.ch/play/\",\"rtr\":\"https://www.rtr.ch/play/\",\"rts\":\"https://www.rts.ch/play/\",\"srf\":\"https://www.srf.ch/play/\",\"swi\":\"https://play.swissinfo.ch/play/\"}",
"playServiceURL": "https://www.srf.ch/play/",
"middlewareURL": "https://playfff.herokuapp.com",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"tvSiteName": "swi-player-tvos-apple",
"voiceOverLanguageCode": "en",
"appStoreProductIdentifier": 920785201,
"serviceURL": "https://il.srf.ch",
"playURLs": "{\"rsi\":\"https://www.rsi.ch/play/\",\"rtr\":\"https://www.rtr.ch/play/\",\"rts\":\"https://www.rts.ch/play/\",\"srf\":\"https://www.srf.ch/play/\",\"swi\":\"https://play.swissinfo.ch/play/\"}",
"playServiceURL": "https://play.swissinfo.ch/play/",
"middlewareURL": "https://playfff.herokuapp.com",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ OBJC_EXPORT NSString * const ApplicationConfigurationDidChangeNotification;

@property (nonatomic, readonly, copy) NSNumber *appStoreProductIdentifier;

@property (nonatomic, readonly, nullable) NSURL *serviceURL;
@property (nonatomic, readonly) NSURL *playServiceURL;
@property (nonatomic, readonly) NSURL *middlewareURL;
@property (nonatomic, readonly, nullable) NSURL *identityWebserviceURL;
Expand Down Expand Up @@ -114,6 +113,7 @@ OBJC_EXPORT NSString * const ApplicationConfigurationDidChangeNotification;


- (nullable NSURL *)playURLForVendor:(SRGVendor)vendor;
- (nullable NSURL *)serviceURLForId:(NSString *)serviceId;

/**
* URLs to be used for sharing
Expand Down
10 changes: 7 additions & 3 deletions Application/Sources/Configuration/ApplicationConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ @interface ApplicationConfiguration ()

@property (nonatomic, copy) NSNumber *appStoreProductIdentifier;

@property (nonatomic) NSURL *serviceURL;
@property (nonatomic) NSDictionary<NSString *, NSURL *> *serviceURLs;
@property (nonatomic) NSDictionary<NSNumber *, NSURL *> *playURLs;
@property (nonatomic) NSURL *playServiceURL;
@property (nonatomic) NSURL *middlewareURL;
Expand Down Expand Up @@ -450,8 +450,7 @@ - (BOOL)synchronizeWithFirebaseConfiguration:(PlayFirebaseConfiguration *)fireba

self.voiceOverLanguageCode = [firebaseConfiguration stringForKey:@"voiceOverLanguageCode"];

NSString *serviceURLString = [firebaseConfiguration stringForKey:@"serviceURL"];
self.serviceURL = serviceURLString ? [NSURL URLWithString:serviceURLString] : nil;
self.serviceURLs = [firebaseConfiguration serviceURLsForKey:@"serviceURLs"];

NSString *identityWebserviceURLString = [firebaseConfiguration stringForKey:@"identityWebserviceURL"];
self.identityWebserviceURL = identityWebserviceURLString ? [NSURL URLWithString:identityWebserviceURLString] : nil;
Expand Down Expand Up @@ -613,6 +612,11 @@ - (NSURL *)playURLForVendor:(SRGVendor)vendor
return playURLs[@(vendor)];
}

- (NSURL *)serviceURLForId:(NSString *)serviceId
{
return self.serviceURLs[serviceId];
}

- (NSURL *)sharingURLForMedia:(SRGMedia *)media atTime:(CMTime)time
{
if (! media || ! [self playURLForVendor:media.vendor]) {
Expand Down
6 changes: 6 additions & 0 deletions Application/Sources/Configuration/PlayFirebaseConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ OBJC_EXPORT NSArray<NSNumber * /* HomeSection */> * _Nullable FirebaseConfigurat
*/
- (NSDictionary<NSNumber *, NSURL *> *)playURLsForKey:(NSString *)key;

/**
* Service URLs accessor. Return an empty dictionnary if no valid data is found under the specified key.
*/
- (NSDictionary<NSString *, NSURL *> *)serviceURLsForKey:(NSString *)key;


@end

NS_ASSUME_NONNULL_END
24 changes: 24 additions & 0 deletions Application/Sources/Configuration/PlayFirebaseConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#import "PlayFirebaseConfiguration.h"

#import "PlayLogger.h"
#import "PlaySRG-Swift.h"

@import Firebase;
@import SRGAppearance;
Expand Down Expand Up @@ -367,6 +368,29 @@ - (NSDictionary *)JSONDictionaryForKey:(NSString *)key
return playURLs.copy;
}

- (NSDictionary<NSString *, NSURL *> *)serviceURLsForKey:(NSString *)key
{
NSMutableDictionary<NSNumber *, NSURL *> *serviceURLs = [NSMutableDictionary dictionary];
waliid marked this conversation as resolved.
Show resolved Hide resolved

NSDictionary *serviceURLsDictionary = [self JSONDictionaryForKey:key];
for (NSString *key in serviceURLsDictionary) {
if ([ServiceObjC.ids containsObject:key]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the ServiceObjC, we still have ids, which could lead to confusion. Here is a patch. I may have gone a bit too far, so feel free to keep only the necessary changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@waliid I reviewed your patch. ServiceObjC.environments was in my thinking part as well.
Few missing updates in SettingsView.swift and make check-quality failed, so a apply it myself and try to add you as co-author :)

NSURL *URL = [NSURL URLWithString:serviceURLsDictionary[key]];
if (URL) {
serviceURLs[key] = URL;
}
else {
PlayLogWarning(@"configuration", @"Service URL configuration is not valid. The URL of %@ is not valid.", key);
}
}
else {
PlayLogWarning(@"configuration", @"Service URL configuration identifier is not valid. %@ is not valid.", key);
}
}

return serviceURLs.copy;
}

#pragma mark Update

- (void)update
Expand Down
28 changes: 20 additions & 8 deletions Application/Sources/Settings/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,36 @@ struct Service: Identifiable, Equatable {
let name: String
let url: URL

private enum Id {
waliid marked this conversation as resolved.
Show resolved Hide resolved
static let production = "production"
static let stage = "stage"
static let test = "test"
static let mmf = "play mmf"
static let samProduction = "sam production"
static let samStage = "sam stage"
static let samTest = "sam test"
}

static var production = Self(
id: "production",
id: Id.production,
name: NSLocalizedString("Production", comment: "Server setting name"),
url: SRGIntegrationLayerProductionServiceURL()
)

static var stage = Self(
id: "stage",
id: Id.stage,
name: NSLocalizedString("Stage", comment: "Server setting name"),
url: SRGIntegrationLayerStagingServiceURL()
)

static var test = Self(
id: "test",
id: Id.test,
name: NSLocalizedString("Test", comment: "Server setting name"),
url: SRGIntegrationLayerTestServiceURL()
)

static var mmf = Self(
id: "play mmf",
id: Id.mmf,
name: "Play MMF",
url: mmfUrl
)
Expand All @@ -46,19 +56,19 @@ struct Service: Identifiable, Equatable {
}()

static var samProduction = Self(
id: "sam production",
id: Id.samProduction,
name: "SAM \(NSLocalizedString("Production", comment: "Server setting name"))",
url: SRGIntegrationLayerProductionServiceURL().appendingPathComponent("sam")
)

static var samStage = Self(
id: "sam stage",
id: Id.samStage,
name: "SAM \(NSLocalizedString("Stage", comment: "Server setting name"))",
url: SRGIntegrationLayerStagingServiceURL().appendingPathComponent("sam")
)

static var samTest = Self(
id: "sam test",
id: Id.samTest,
name: "SAM \(NSLocalizedString("Test", comment: "Server setting name"))",
url: SRGIntegrationLayerTestServiceURL().appendingPathComponent("sam")
)
Expand All @@ -78,11 +88,13 @@ struct Service: Identifiable, Equatable {
}

@objc class ServiceObjC: NSObject {
@objc static var ids = Service.services.map(\.id)

@objc static func name(forServiceId serviceId: String) -> String {
Service.service(forId: serviceId).name
}

@objc static func url(forServiceId serviceId: String) -> URL {
ApplicationConfiguration().serviceURL ?? Service.service(forId: serviceId).url
ApplicationConfiguration().serviceURL(forId: serviceId) ?? Service.service(forId: serviceId).url
}
}
2 changes: 1 addition & 1 deletion docs/REMOTE_CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ If a remote configuration is found to be invalid (usually a mandatory parameter
* `faqURL` (optional, string): The URL of the FAQs.
* `dataProtectionURL` (optional, string): The URL of the data protection information page.
* `impressumURL` (optional, string): The URL of the impressum page. If none is provided, the corresponding menu entry will not be displayed.
* `serviceURL` (optional, string): The URL of the Content service (DataProvider). If set, it overrides the local server option available in beta builds only.
* `serviceURLs` (optional, JSON): A JSON dictionary describing all URLs of the DataProvider services. Key (string) is the identifier of the service, value (string) is the base URL of the DataProvider service. If the key matches a service id, it overrides the default URL for this service. See `Service.swift` for available ids.
* `identityWebserviceURL` (optional, string): The URL of the identity webservices.
* `identityWebsiteURL` (optional, string): The URL of the identity web portal.
* `userDataServiceURL` (optional, string): The URL of the service with which user data can be synchronized (history, preferences, playlists).
Expand Down