Skip to content

Commit

Permalink
Migrating from getUserValues to initialSetup on Duck Player overlays (#…
Browse files Browse the repository at this point in the history
…989)

* Migrating from getUserValues to initialSetup on Duck Player overlays

* Renamed overlay settings type

---------

Co-authored-by: Shane Osbourne <[email protected]>
  • Loading branch information
mgurgel and shakyShane authored Jul 8, 2024
1 parent bbcad33 commit 1fe725c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
10 changes: 9 additions & 1 deletion integration-test/playwright/page-objects/duckplayer-overlays.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ export class DuckplayerOverlays {
async userSettingIs (setting) {
await this.page.addInitScript(mockResponses, {
responses: {
getUserValues: userValues[setting]
initialSetup: {
userValues: userValues[setting]
}
}
})
}
Expand Down Expand Up @@ -445,6 +447,12 @@ export class DuckplayerOverlays {
featureName: 'duckPlayer'
},
responses: {
initialSetup: {
userValues: {
privatePlayerMode: { alwaysAsk: {} },
overlayInteracted: false
}
},
getUserValues: {
privatePlayerMode: { alwaysAsk: {} },
overlayInteracted: false
Expand Down
7 changes: 6 additions & 1 deletion src/features/duck-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* #### Messages:
*
* On Page Load
* - {@link DuckPlayerOverlayMessages.getUserValues} is initially called to get the current settings
* - {@link DuckPlayerOverlayMessages.initialSetup} is initially called to get the current settings
* - {@link DuckPlayerOverlayMessages.onUserValuesChanged} subscription begins immediately - it will continue to listen for updates
*
* Then the following message can be sent at any time
Expand Down Expand Up @@ -45,6 +45,11 @@ import { Environment, initOverlays } from './duckplayer/overlays.js'
* @property {boolean} overlayInteracted - always a boolean
*/

/**
* @typedef OverlaysInitialSettings - The initial payload used to communicate render-blocking information
* @property {UserValues} userValues
*/

/**
* @internal
*/
Expand Down
1 change: 1 addition & 0 deletions src/features/duckplayer/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const MSG_NAME_INITIAL_SETUP = 'initialSetup'
export const MSG_NAME_SET_VALUES = 'setUserValues'
export const MSG_NAME_READ_VALUES = 'getUserValues'
export const MSG_NAME_READ_VALUES_SERP = 'readUserValues'
Expand Down
7 changes: 7 additions & 0 deletions src/features/duckplayer/overlay-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export class DuckPlayerOverlayMessages {
this.messaging = messaging
}

/**
* @returns {Promise<import("../duck-player.js").OverlaysInitialSettings>}
*/
initialSetup () {
return this.messaging.request(constants.MSG_NAME_INITIAL_SETUP)
}

/**
* Inform the native layer that an interaction occurred
* @param {import("../duck-player.js").UserValues} userValues
Expand Down
10 changes: 6 additions & 4 deletions src/features/duckplayer/overlays.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@ export async function initOverlays (settings, environment, messages) {
// bind early to attach all listeners
const domState = new DomState()

/** @type {import("../duck-player.js").UserValues} */
let userValues
/** @type {import("../duck-player.js").OverlaysInitialSettings} */
let initialSetup
try {
userValues = await messages.getUserValues()
initialSetup = await messages.initialSetup()
} catch (e) {
console.error(e)
return
}

if (!userValues) {
if (!initialSetup) {
console.error('cannot continue without user settings')
return
}

let { userValues } = initialSetup

/**
* Create the instance - this might fail if settings or user preferences prevent it
* @type {Thumbnails|undefined}
Expand Down

0 comments on commit 1fe725c

Please sign in to comment.