@@ -99,6 +99,9 @@ export class AmpConnatixPlayer extends AMP.BaseElement {
99
99
100
100
/** @private {boolean} */
101
101
this . muted_ = true ;
102
+
103
+ /** @private {?MutationObserver} */
104
+ this . mutationObserver_ = null ;
102
105
}
103
106
104
107
/**
@@ -330,29 +333,32 @@ export class AmpConnatixPlayer extends AMP.BaseElement {
330
333
// bind to amp consent and send consent info to the iframe content and propagate to player
331
334
this . bindToAmpConsent_ ( ) ;
332
335
336
+ if ( ! this . mutationObserver_ ) {
337
+ const mutationObserverCallback = ( mutationList ) => {
338
+ for ( const mutation of mutationList ) {
339
+ if (
340
+ mutation . type === 'attributes' &&
341
+ mutation . attributeName === 'class'
342
+ ) {
343
+ this . sendCommand_ (
344
+ mutation . target . classList . contains ( 'i-amphtml-video-docked' )
345
+ ? 'dock'
346
+ : 'undock'
347
+ ) ;
348
+ }
349
+ }
350
+ } ;
351
+
352
+ this . mutationObserver_ = new MutationObserver ( mutationObserverCallback ) ;
353
+ }
354
+
333
355
const mutationObserverConfig = {
334
356
attributes : true ,
335
357
childList : false ,
336
358
subtree : false ,
337
359
} ;
338
360
339
- const callback = ( mutationList ) => {
340
- for ( const mutation of mutationList ) {
341
- if (
342
- mutation . type === 'attributes' &&
343
- mutation . attributeName === 'class'
344
- ) {
345
- this . sendCommand_ (
346
- mutation . target . classList . contains ( 'i-amphtml-video-docked' )
347
- ? 'dock'
348
- : 'undock'
349
- ) ;
350
- }
351
- }
352
- } ;
353
-
354
- const observer = new MutationObserver ( callback ) ;
355
- observer . observe ( this . iframe_ , mutationObserverConfig ) ;
361
+ this . mutationObserver_ . observe ( this . iframe_ , mutationObserverConfig ) ;
356
362
357
363
observeContentSize ( this . element , this . onResized_ ) ;
358
364
this . pauseHelper_ . updatePlaying ( true ) ;
@@ -396,6 +402,7 @@ export class AmpConnatixPlayer extends AMP.BaseElement {
396
402
this . playerReadyResolver_ = deferred . resolve ;
397
403
398
404
unobserveContentSize ( this . element , this . onResized_ ) ;
405
+ this . mutationObserver_ . disconnect ( ) ;
399
406
this . pauseHelper_ . updatePlaying ( false ) ;
400
407
401
408
return true ;
0 commit comments