Skip to content

Commit

Permalink
Brid player consent support (#32097)
Browse files Browse the repository at this point in the history
  • Loading branch information
grajzer committed Mar 3, 2021
1 parent df5f2f3 commit 0689340
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions extensions/amp-brid-player/0.1/amp-brid-player.js
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import {CONSENT_POLICY_STATE} from '../../../src/consent-state';
import {Deferred} from '../../../src/utils/promise';
import {Services} from '../../../src/services';
import {VideoEvents} from '../../../src/video-interface';
Expand All @@ -32,6 +33,10 @@ import {
isFullscreenElement,
removeElement,
} from '../../../src/dom';
import {
getConsentPolicyInfo,
getConsentPolicyState,
} from '../../../src/consent';
import {getData, listen} from '../../../src/event-helper';
import {htmlFor} from '../../../src/static-template';
import {installVideoManagerForDoc} from '../../../src/service/video-manager-impl';
Expand Down Expand Up @@ -268,6 +273,52 @@ class AmpBridPlayer extends AMP.BaseElement {
});
}

/**
* Requests consent data from consent module
* and forwards information to player
* @private
*/
getConsentData_() {
const consentPolicy = this.getConsentPolicy() || 'default';
const consentStatePromise = getConsentPolicyState(
this.element,
consentPolicy
);
const consentStringPromise = getConsentPolicyInfo(
this.element,
consentPolicy
);

return Promise.all([consentStatePromise, consentStringPromise]).then(
(consents) => {
let consentData;
switch (consents[0]) {
case CONSENT_POLICY_STATE.SUFFICIENT:
consentData = {
'gdprApplies': true,
'userConsent': 1,
'gdprString': consents[1],
};
break;
case CONSENT_POLICY_STATE.INSUFFICIENT:
case CONSENT_POLICY_STATE.UNKNOWN:
consentData = {
'gdprApplies': true,
'userConsent': 0,
'gdprString': consents[1],
};
break;
case CONSENT_POLICY_STATE.UNKNOWN_NOT_REQUIRED:
default:
consentData = {
'gdprApplies': false,
};
}
this.sendCommand_('setAMPGDPR', JSON.stringify(consentData));
}
);
}

/**
* @param {!Event} event
* @private
Expand All @@ -289,6 +340,9 @@ class AmpBridPlayer extends AMP.BaseElement {
if (params[3] == 'ready') {
this.playerReadyResolver_(this.iframe_);
}
if (params[3] == 'requestAMPGDPR') {
this.getConsentData_();
}
redispatch(element, params[3], {
'ready': VideoEvents.LOAD,
'play': VideoEvents.PLAYING,
Expand Down

0 comments on commit 0689340

Please sign in to comment.