@@ -6,7 +6,7 @@ import { setupDuckPlayerForNoCookie, setupDuckPlayerForSerp, setupDuckPlayerForY
66import { Environment } from './duckplayer-native/environment.js' ;
77
88/**
9- * @import {DuckPlayerNative } from './duckplayer-native/duckplayer-native.js'
9+ * @import {DuckPlayerNativePage } from './duckplayer-native/duckplayer-native.js'
1010 * @import {DuckPlayerNativeSettings} from '@duckduckgo/privacy-configuration/schema/features/duckplayer-native.js'
1111 * @import {UrlChangeSettings} from './duckplayer-native/messages.js'
1212 */
@@ -15,23 +15,20 @@ import { Environment } from './duckplayer-native/environment.js';
1515 * @typedef InitialSettings - The initial payload used to communicate render-blocking information
1616 * @property {string } locale - UI locale
1717 * @property {UrlChangeSettings['pageType'] } pageType - The type of the current page
18+ * @property {boolean } playbackPaused - Should video start playing or paused
1819 */
1920
2021export class DuckPlayerNativeFeature extends ContentFeature {
21- /** @type {DuckPlayerNative } */
22- current ;
22+ /** @type {DuckPlayerNativePage } */
23+ currentPage ;
2324
2425 async init ( args ) {
2526 console . log ( 'DUCK PLAYER NATIVE LOADING' , args , window . location . href ) ; // TODO: REMOVE
2627
27- // TODO: May depend on page type
2828 /**
2929 * This feature never operates in a frame
3030 */
31- if ( isBeingFramed ( ) ) {
32- console . log ( 'FRAMED. ABORTING.' ) ; // TODO: REMOVE
33- return ;
34- }
31+ if ( isBeingFramed ( ) ) return ;
3532
3633 const selectors = this . getFeatureSetting ( 'selectors' ) ;
3734 console . log ( 'DUCK PLAYER NATIVE SELECTORS' , selectors ) ; // TODO: REMOVE
@@ -44,17 +41,16 @@ export class DuckPlayerNativeFeature extends ContentFeature {
4441 locale,
4542 } ) ;
4643
47- // TODO: Decide which feature to run
48-
4944 if ( env . isIntegrationMode ( ) ) {
5045 // TODO: Better way than patching transport?
5146 this . messaging . transport = mockTransport ( ) ;
5247 }
5348
5449 const messages = new DuckPlayerNativeMessages ( this . messaging ) ;
5550 messages . subscribeToURLChange ( ( { pageType } ) => {
51+ const playbackPaused = false ; // TODO: Get this from the native notification too?
5652 console . log ( 'GOT PAGE TYPE' , pageType ) ;
57- this . urlChangeHandler ( pageType , selectors , env , messages ) ;
53+ this . urlChanged ( pageType , selectors , playbackPaused , env , messages ) ;
5854 } ) ;
5955
6056 /** @type {InitialSettings } */
@@ -71,45 +67,48 @@ export class DuckPlayerNativeFeature extends ContentFeature {
7167 console . log ( 'INITIAL SETUP' , initialSetup ) ;
7268
7369 if ( initialSetup . pageType ) {
70+ const playbackPaused = initialSetup . playbackPaused || false ;
7471 console . log ( 'GOT INITIAL PAGE TYPE' , initialSetup . pageType ) ; // TODO: REMOVE
75- this . urlChangeHandler ( initialSetup . pageType , selectors , env , messages ) ;
72+ this . urlChanged ( initialSetup . pageType , selectors , playbackPaused , env , messages ) ;
7673 }
7774 }
7875
7976 /**
8077 *
8178 * @param {UrlChangeSettings['pageType'] } pageType
8279 * @param {DuckPlayerNativeSettings['selectors'] } selectors
80+ * @param {boolean } playbackPaused
8381 * @param {Environment } env
8482 * @param {DuckPlayerNativeMessages } messages
8583 */
86- urlChangeHandler ( pageType , selectors , env , messages ) {
87- let next ;
84+ urlChanged ( pageType , selectors , playbackPaused , env , messages ) {
85+ /** @type {DuckPlayerNativePage | null } */
86+ let nextPage = null ;
8887
8988 switch ( pageType ) {
9089 case 'NOCOOKIE' :
91- next = setupDuckPlayerForNoCookie ( selectors , env , messages ) ;
90+ nextPage = setupDuckPlayerForNoCookie ( selectors , env , messages ) ;
9291 break ;
9392 case 'YOUTUBE' :
94- next = setupDuckPlayerForYouTube ( selectors , env , messages ) ;
93+ nextPage = setupDuckPlayerForYouTube ( selectors , playbackPaused , env , messages ) ;
9594 break ;
9695 case 'SERP' :
97- next = setupDuckPlayerForSerp ( selectors , env , messages ) ;
96+ nextPage = setupDuckPlayerForSerp ( selectors , env , messages ) ;
9897 break ;
9998 case 'UNKNOWN' :
10099 default :
101100 console . warn ( 'No known pageType' ) ;
102101 }
103102
104- if ( this . current ) {
105- console . log ( 'DESTROYING CURRENT INSTANCE' , this . current ) ;
106- this . current . destroy ( ) ;
103+ if ( this . currentPage ) {
104+ console . log ( 'DESTROYING CURRENT INSTANCE' , this . currentPage ) ;
105+ this . currentPage . destroy ( ) ;
107106 }
108107
109- if ( next ) {
110- console . log ( 'LOADING NEXT INSTANCE' , next ) ;
111- next . init ( ) ;
112- this . current = next ;
108+ if ( nextPage ) {
109+ console . log ( 'LOADING NEXT INSTANCE' , nextPage ) ;
110+ nextPage . init ( ) ;
111+ this . currentPage = nextPage ;
113112 }
114113 }
115114}
0 commit comments