@@ -117,35 +117,39 @@ export function setupDuckPlayerForYouTube(settings, environment, messages) {
117
117
} ;
118
118
119
119
const onInit = ( sideEffects , logger ) => {
120
- messages . subscribeToMediaControl ( ( { pause } ) => {
121
- logger . log ( 'Running media control handler. Pause:' , pause ) ;
122
-
123
- const videoElement = settings . selectors ?. videoElement ;
124
- const videoElementContainer = settings . selectors ?. videoElementContainer ;
125
- if ( ! videoElementContainer || ! videoElement ) {
126
- logger . warn ( 'Missing media control selectors in config' ) ;
127
- return ;
128
- }
129
-
130
- const targetElement = document . querySelector ( videoElementContainer ) ;
131
- if ( targetElement ) {
120
+ sideEffects . add ( 'subscribe to media control' , ( ) => {
121
+ return messages . subscribeToMediaControl ( ( { pause } ) => {
122
+ logger . log ( 'Running media control handler. Pause:' , pause ) ;
123
+
124
+ const videoElement = settings . selectors ?. videoElement ;
125
+ const videoElementContainer = settings . selectors ?. videoElementContainer ;
126
+ if ( ! videoElementContainer || ! videoElement ) {
127
+ logger . warn ( 'Missing media control selectors in config' ) ;
128
+ return ;
129
+ }
132
130
133
- if ( pause ) {
134
- sideEffects . add ( 'stopping video from playing' , ( ) => stopVideoFromPlaying ( videoElement ) ) ;
135
- sideEffects . add ( 'appending thumbnail' , ( ) =>
136
- appendThumbnailOverlay ( /** @type {HTMLElement } */ ( targetElement ) , environment ) ,
137
- ) ;
138
- } else {
139
- sideEffects . destroy ( 'stopping video from playing' ) ;
140
- sideEffects . destroy ( 'appending thumbnail' ) ;
131
+ const targetElement = document . querySelector ( videoElementContainer ) ;
132
+ if ( targetElement ) {
133
+
134
+ if ( pause ) {
135
+ sideEffects . add ( 'stopping video from playing' , ( ) => stopVideoFromPlaying ( videoElement ) ) ;
136
+ sideEffects . add ( 'appending thumbnail' , ( ) =>
137
+ appendThumbnailOverlay ( /** @type {HTMLElement } */ ( targetElement ) , environment ) ,
138
+ ) ;
139
+ } else {
140
+ sideEffects . destroy ( 'stopping video from playing' ) ;
141
+ sideEffects . destroy ( 'appending thumbnail' ) ;
142
+ }
141
143
}
142
- }
143
- } ) ;
144
+ } ) ;
145
+ } )
144
146
145
- messages . subscribeToMuteAudio ( ( { mute } ) => {
146
- logger . log ( 'Running mute audio handler. Mute:' , mute ) ;
147
- muteAudio ( mute ) ;
148
- } ) ;
147
+ sideEffects . add ( 'subscribing to mute audio' , ( ) => {
148
+ return messages . subscribeToMuteAudio ( ( { mute } ) => {
149
+ logger . log ( 'Running mute audio handler. Mute:' , mute ) ;
150
+ muteAudio ( mute ) ;
151
+ } ) ;
152
+ } )
149
153
} ;
150
154
151
155
const duckPlayerNative = new DuckPlayerNative ( {
0 commit comments