Skip to content

Commit

Permalink
✨Consent: Pass consent string and metadata to amp-delight-player (#29876
Browse files Browse the repository at this point in the history
)

* Request and send consent data to player iframe

* send consent data as early as possible on PLAYER_READY event

* add missing semicolon
  • Loading branch information
xymw committed Sep 10, 2020
1 parent c36edcc commit cb94cad
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions extensions/amp-delight-player/0.1/amp-delight-player.js
Expand Up @@ -24,6 +24,12 @@ import {
redispatch,
} from '../../../src/iframe-video';
import {dict} from '../../../src/utils/object';
import {
getConsentMetadata,
getConsentPolicyInfo,
getConsentPolicySharedData,
getConsentPolicyState,
} from '../../../src/consent';
import {getData, listen, listenOncePromise} from '../../../src/event-helper';
import {htmlFor} from '../../../src/static-template';
import {installVideoManagerForDoc} from '../../../src/service/video-manager-impl';
Expand Down Expand Up @@ -65,6 +71,8 @@ const DelightEvent = {
DISABLE_INTERFACE: 'x-dl8-to-iframe-disable-interface',
SEEK: 'x-dl8-to-iframe-seek',
CUSTOM_TICK: 'x-dl8-to-parent-amp-custom-tick',
CONSENT_DATA: 'x-dl8-to-iframe-consent-data',
PLAYER_READY: 'x-dl8-to-parent-player-ready',

PING: 'x-dl8-ping',
PONG: 'x-dl8-pong',
Expand Down Expand Up @@ -301,6 +309,10 @@ class AmpDelightPlayer extends AMP.BaseElement {
this.playerReadyResolver_(this.iframe_);
break;
}
case DelightEvent.PLAYER_READY: {
this.sendConsentData_();
break;
}
case DelightEvent.TIME_UPDATE: {
const payload = data['payload'];
this.currentTime_ = payload.currentTime;
Expand Down Expand Up @@ -505,6 +517,42 @@ class AmpDelightPlayer extends AMP.BaseElement {
}
}

/**
* Requests consent data from consent module
* and forwards information to iframe
* @private
*/
sendConsentData_() {
const consentPolicyId = super.getConsentPolicy() || 'default';
const consentStringPromise = getConsentPolicyInfo(
this.element,
consentPolicyId
);
const metadataPromise = getConsentMetadata(this.element, consentPolicyId);
const consentPolicyStatePromise = getConsentPolicyState(
this.element,
consentPolicyId
);
const consentPolicySharedDataPromise = getConsentPolicySharedData(
this.element,
consentPolicyId
);

Promise.all([
metadataPromise,
consentStringPromise,
consentPolicyStatePromise,
consentPolicySharedDataPromise,
]).then((consents) => {
this.sendCommand_(DelightEvent.CONSENT_DATA, {
'consentMetadata': consents[0],
'consentString': consents[1],
'consentPolicyState': consents[2],
'consentPolicySharedData': consents[3],
});
});
}

// VideoInterface Implementation. See ../src/video-interface.VideoInterface

/** @override */
Expand Down

0 comments on commit cb94cad

Please sign in to comment.