Skip to content

Commit

Permalink
minor change
Browse files Browse the repository at this point in the history
  • Loading branch information
cristisilav committed Jan 8, 2024
1 parent 65248c5 commit 6fc4076
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions extensions/amp-connatix-player/0.1/amp-connatix-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export class AmpConnatixPlayer extends AMP.BaseElement {

/** @private {boolean} */
this.muted_ = true;

/** @private {?MutationObserver} */
this.mutationObserver_ = null;
}

/**
Expand Down Expand Up @@ -330,29 +333,32 @@ export class AmpConnatixPlayer extends AMP.BaseElement {
// bind to amp consent and send consent info to the iframe content and propagate to player
this.bindToAmpConsent_();

if (!this.mutationObserver_) {
const mutationObserverCallback = (mutationList) => {
for (const mutation of mutationList) {
if (
mutation.type === 'attributes' &&
mutation.attributeName === 'class'
) {
this.sendCommand_(
mutation.target.classList.contains('i-amphtml-video-docked')
? 'dock'
: 'undock'
);
}
}
};

this.mutationObserver_ = new MutationObserver(mutationObserverCallback);
}

const mutationObserverConfig = {
attributes: true,
childList: false,
subtree: false,
};

const callback = (mutationList) => {
for (const mutation of mutationList) {
if (
mutation.type === 'attributes' &&
mutation.attributeName === 'class'
) {
this.sendCommand_(
mutation.target.classList.contains('i-amphtml-video-docked')
? 'dock'
: 'undock'
);
}
}
};

const observer = new MutationObserver(callback);
observer.observe(this.iframe_, mutationObserverConfig);
this.mutationObserver_.observe(this.iframe_, mutationObserverConfig);

observeContentSize(this.element, this.onResized_);
this.pauseHelper_.updatePlaying(true);
Expand Down Expand Up @@ -396,6 +402,7 @@ export class AmpConnatixPlayer extends AMP.BaseElement {
this.playerReadyResolver_ = deferred.resolve;

unobserveContentSize(this.element, this.onResized_);
this.mutationObserver_.disconnect();
this.pauseHelper_.updatePlaying(false);

return true;
Expand Down

0 comments on commit 6fc4076

Please sign in to comment.