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

♻️ Move RTC manager to a service #32728

Merged
merged 1 commit into from
Feb 22, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions build-system/externs/amp.extern.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,6 @@ AMP.AmpAdUIHandler = class {
constructor(baseInstance) {}
};

AMP.RealTimeConfigManager;

/**
* Actual filled values for this exists in
* src/service/real-time-config/real-time-config-impl.js
Expand Down
3 changes: 3 additions & 0 deletions build-system/test-configs/dep-check-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ exports.rules = [
'src/service/variable-source.js',
'extensions/amp-a4a/0.1/amp-a4a.js->' +
'src/service/url-replacements-impl.js',
// Real time config.
'extensions/amp-a4a/0.1/amp-a4a.js->' +
'src/service/real-time-config/real-time-config-impl.js',
// Parsing extension urls.
'extensions/amp-a4a/0.1/head-validation.js->' +
'src/service/extension-location.js',
Expand Down
43 changes: 18 additions & 25 deletions extensions/amp-a4a/0.1/amp-a4a.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
installFriendlyIframeEmbed,
isSrcdocSupported,
} from '../../../src/friendly-iframe-embed';
import {installRealTimeConfigServiceForDoc} from '../../../src/service/real-time-config/real-time-config-impl';
import {installUrlReplacementsForEmbed} from '../../../src/service/url-replacements-impl';
import {
intersectionEntryToJson,
Expand Down Expand Up @@ -2376,31 +2377,23 @@ export class AmpA4A extends AMP.BaseElement {
* @return {Promise<!Array<!rtcResponseDef>>|undefined}
*/
tryExecuteRealTimeConfig_(consentState, consentString, consentMetadata) {
if (!!AMP.RealTimeConfigManager) {
return this.getBlockRtc_().then((shouldBlock) => {
if (shouldBlock) {
return;
}
try {
return new AMP.RealTimeConfigManager(
this.getAmpDoc()
).maybeExecuteRealTimeConfig(
this.element,
this.getCustomRealTimeConfigMacros_(),
consentState,
consentString,
consentMetadata,
this.verifyStillCurrent()
);
} catch (err) {
user().error(TAG, 'Could not perform Real Time Config.', err);
}
});
} else if (this.element.getAttribute('rtc-config')) {
powerivq marked this conversation as resolved.
Show resolved Hide resolved
user().error(
TAG,
'RTC not supported for ad network ' +
`${this.element.getAttribute('type')}`
if (this.element.getAttribute('rtc-config')) {
installRealTimeConfigServiceForDoc(this.getAmpDoc());
return this.getBlockRtc_().then((shouldBlock) =>
shouldBlock
? undefined
: Services.realTimeConfigForDoc(
Copy link
Member

Choose a reason for hiding this comment

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

should we leave this wrapped in a try/catch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It used to be:

if (!! AMP.RealTimeConfigManager) {
    try {
      return new AMP.RealTimeConfigManager(
...

The try/catch, at that time, would prevent rtc issues from breaking the entire runtime. Now that everything is wrapped in the promise and ran asynchronously, the consequence of not using try/catch is much smaller. Throwing exceptions should not be the expected thing anyways, so I feel keeping try/catch nowadays is unnecessarily defensive.

this.getAmpDoc()
).then((realTimeConfig) =>
realTimeConfig.maybeExecuteRealTimeConfig(
this.element,
this.getCustomRealTimeConfigMacros_(),
consentState,
consentString,
consentMetadata,
this.verifyStillCurrent()
)
)
);
}
}
Expand Down