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

breaking: remove MediaPlaybackRequiresUserAction and update MediaTypesRequiringUserActionForPlayback to proper variable types #797

Merged
merged 2 commits into from
Feb 27, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,23 @@ - (WKWebViewConfiguration*) createConfigurationFromSettings:(NSDictionary*)setti

configuration.allowsInlineMediaPlayback = [settings cordovaBoolSettingForKey:@"AllowInlineMediaPlayback" defaultValue:NO];

// Check for usage of the older preference key, alert, and use.
BOOL mediaTypesRequiringUserActionForPlayback = [settings cordovaBoolSettingForKey:@"MediaTypesRequiringUserActionForPlayback" defaultValue:YES];
NSString *mediaPlaybackRequiresUserActionKey = [settings cordovaSettingForKey:@"MediaPlaybackRequiresUserAction"];
if(mediaPlaybackRequiresUserActionKey != nil) {
mediaTypesRequiringUserActionForPlayback = [settings cordovaBoolSettingForKey:@"MediaPlaybackRequiresUserAction" defaultValue:YES];
// Set the media types that are required for user action for playback
WKAudiovisualMediaTypes mediaType = WKAudiovisualMediaTypeAll; // default

// targetMediaType will always exist, either from user's "config.xml" or default ("defaults.xml").
id targetMediaType = [settings cordovaSettingForKey:@"MediaTypesRequiringUserActionForPlayback"];
if ([targetMediaType isEqualToString:@"none"]) {
mediaType = WKAudiovisualMediaTypeNone;
} else if ([targetMediaType isEqualToString:@"audio"]) {
mediaType = WKAudiovisualMediaTypeAudio;
} else if ([targetMediaType isEqualToString:@"video"]) {
mediaType = WKAudiovisualMediaTypeVideo;
} else if ([targetMediaType isEqualToString:@"all"]) {
mediaType = WKAudiovisualMediaTypeAll;
} else {
NSLog(@"Invalid \"MediaTypesRequiringUserActionForPlayback\" was detected. Fallback to default value of \"all\" types.");
}
configuration.mediaTypesRequiringUserActionForPlayback = mediaTypesRequiringUserActionForPlayback;
configuration.mediaTypesRequiringUserActionForPlayback = mediaType;

configuration.suppressesIncrementalRendering = [settings cordovaBoolSettingForKey:@"SuppressesIncrementalRendering" defaultValue:NO];

Expand Down
2 changes: 1 addition & 1 deletion bin/templates/scripts/cordova/defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<preference name="DisallowOverscroll" value="false" />
<preference name="EnableViewportScale" value="false" />
<preference name="KeyboardDisplayRequiresUserAction" value="true" />
<preference name="MediaTypesRequiringUserActionForPlayback" value="false" />
<preference name="MediaTypesRequiringUserActionForPlayback" value="none" />
<preference name="SuppressesIncrementalRendering" value="false" />
<preference name="SuppressesLongPressGesture" value="false" />
<preference name="Suppresses3DTouchGesture" value="false" />
Expand Down
33 changes: 26 additions & 7 deletions bin/templates/scripts/cordova/lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,21 +522,40 @@ function updateFileResources (cordovaProject, locations) {

function alertDeprecatedPreference (configParser) {
const deprecatedToNewPreferences = {
MediaPlaybackRequiresUserAction: 'MediaTypesRequiringUserActionForPlayback',
MediaPlaybackAllowsAirPlay: 'AllowsAirPlayForMediaPlayback'
MediaPlaybackRequiresUserAction: {
newPreference: 'MediaTypesRequiringUserActionForPlayback',
isDeprecated: true
},
MediaPlaybackAllowsAirPlay: {
newPreference: 'AllowsAirPlayForMediaPlayback',
isDeprecated: false
}
};

Object.keys(deprecatedToNewPreferences).forEach(oldKey => {
if (configParser.getPreference(oldKey)) {
const log = [`The preference name "${oldKey}" is being deprecated.`];

if (deprecatedToNewPreferences[oldKey]) {
log.push(`It is recommended to update this preference with "${deprecatedToNewPreferences[oldKey]}."`);
const isDeprecated = deprecatedToNewPreferences[oldKey].isDeprecated;
const verb = isDeprecated ? 'has been' : 'is being';
const newPreferenceKey = deprecatedToNewPreferences[oldKey].newPreference;

// Create the Log Message
const log = [`The preference name "${oldKey}" ${verb} deprecated.`];
if (newPreferenceKey) {
log.push(`It is recommended to replace this preference with "${newPreferenceKey}."`);
} else {
log.push(`There is no replacement for this preference.`);
}

log.push(`Please note that this preference will be removed in the near future.`);
/**
* If the preference has been deprecated, the usage of the old preference is no longer used.
* Therefore, the following line is not appended. It is added only if the old preference is still used.
* We are only keeping the top lines for deprecated items only for an additional major release when
* the pre-warning was not provided in a past major release due to a necessary quick deprecation.
* Typically caused by implementation nature or third-party requirement changes.
*/
if (!isDeprecated) {
log.push(`Please note that this preference will be removed in the near future.`);
}

events.emit('warn', log.join(' '));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/CordovaLibTests/CDVWebViewEngineTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ - (void) testUpdateInfo {
NSDictionary* preferences = @{
[@"MinimumFontSize" lowercaseString] : @1.1, // default is 0.0
[@"AllowInlineMediaPlayback" lowercaseString] : @YES, // default is NO
[@"MediaTypesRequiringUserActionForPlayback" lowercaseString] : @YES, // default is NO
[@"MediaTypesRequiringUserActionForPlayback" lowercaseString] : @"all", // default is NO
[@"SuppressesIncrementalRendering" lowercaseString] : @YES, // default is NO
[@"AllowsAirPlayForMediaPlayback" lowercaseString] : @NO, // default is YES
[@"DisallowOverscroll" lowercaseString] : @YES, // so bounces is to be NO. defaults to NO
Expand Down Expand Up @@ -133,7 +133,7 @@ - (void) testConfigurationFromSettings {
NSDictionary* settings = @{
[@"MinimumFontSize" lowercaseString] : @1.1, // default is 0.0
[@"AllowInlineMediaPlayback" lowercaseString] : @YES, // default is NO
[@"MediaTypesRequiringUserActionForPlayback" lowercaseString] : @YES, // default is NO
[@"MediaTypesRequiringUserActionForPlayback" lowercaseString] : @"all", // default is NO
[@"SuppressesIncrementalRendering" lowercaseString] : @YES, // default is NO
[@"AllowsAirPlayForMediaPlayback" lowercaseString] : @NO, // default is YES
[@"DisallowOverscroll" lowercaseString] : @YES, // so bounces is to be NO. defaults to NO
Expand Down