Skip to content

Commit d401be2

Browse files
author
Shane Osbourne
committed
open in windows-specific page for now
1 parent 567ec7b commit d401be2

File tree

3 files changed

+41
-36
lines changed

3 files changed

+41
-36
lines changed

packages/special-pages/pages/duckplayer/src/js/index.js

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,18 @@ const Comms = {
324324
* To mock, use:
325325
*
326326
* `window.postMessage({ alwaysOpenSetting: false })`
327+
*
328+
* @param {object} opts
329+
* @param {ImportMeta['env']} opts.env
330+
* @param {ImportMeta['platform']} opts.platform
327331
*/
328-
init: () => {
332+
init: (opts) => {
329333
const messageContext = new MessagingContext({
330334
context: 'specialPages',
331335
featureName: 'duckPlayerPage',
332-
env: import.meta.env
336+
env: opts.env
333337
})
334-
if (import.meta.platform === 'windows') {
338+
if (opts.platform === 'windows') {
335339
const opts = new WindowsMessagingConfig({
336340
methods: {
337341
// @ts-expect-error - not in @types/chrome
@@ -344,7 +348,7 @@ const Comms = {
344348
})
345349
const messaging = new Messaging(messageContext, opts)
346350
Comms.messaging = new DuckPlayerPageMessages(messaging)
347-
} else if (import.meta.platform === 'integration') {
351+
} else if (opts.platform === 'integration') {
348352
const config = new TestTransportConfig({
349353
notify (msg) {
350354
console.log(msg)
@@ -541,34 +545,28 @@ const PlayOnYouTube = {
541545
return document.querySelector('.play-on-youtube')
542546
},
543547

544-
/**
545-
* Returns the full YouTube source URL for a video, based on video id
546-
* @param {string} videoId
547-
* @param {number|boolean} timestamp
548-
* @returns {string}
549-
*/
550-
getVideoLinkURL: (videoId, timestamp) => {
551-
const url = new URL('/watch', 'https://www.youtube.com')
552-
553-
url.searchParams.set('v', videoId)
554-
555-
if (timestamp) {
556-
url.searchParams.set('t', timestamp + 's')
557-
}
558-
559-
return url.href
560-
},
561-
562548
/**
563549
* If there is a valid video id, set the 'href' of the YouTube button to the
564550
* video link url
551+
*
552+
* @param {object} opts
553+
* @param {string} opts.base
565554
*/
566-
init: () => {
555+
init: (opts) => {
567556
const validVideoId = Comms.getValidVideoId()
568557
const timestamp = Comms.getSanitizedTimestamp()
558+
console.log({ validVideoId })
569559

570560
if (validVideoId) {
571-
PlayOnYouTube.button().setAttribute('href', PlayOnYouTube.getVideoLinkURL(validVideoId, timestamp))
561+
const url = new URL(opts.base)
562+
563+
url.searchParams.set('v', validVideoId)
564+
565+
if (timestamp) {
566+
url.searchParams.set('t', timestamp + 's')
567+
}
568+
569+
PlayOnYouTube.button().setAttribute('href', url.href)
572570
}
573571
}
574572
}
@@ -753,9 +751,15 @@ const MouseMove = {
753751
*/
754752
document.addEventListener('DOMContentLoaded', () => {
755753
Setting.init()
756-
Comms.init()
754+
Comms.init({
755+
platform: import.meta.platform,
756+
env: import.meta.env
757+
})
757758
VideoPlayer.init()
758759
Tooltip.init()
759-
PlayOnYouTube.init()
760+
PlayOnYouTube.init({
761+
// todo(Shane): platform specific
762+
base: 'duck://player/openInYoutube'
763+
})
760764
MouseMove.init()
761765
})

packages/special-pages/tests/duckplayer.spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ test.describe('duckplayer toolbar', () => {
6666
const duckplayer = DuckPlayerPage.create(page, workerInfo)
6767
await duckplayer.openWithVideoID()
6868
await duckplayer.hasLoadedIframe()
69-
await duckplayer.clickPlayOnYouTube()
70-
await duckplayer.navigatedToYouTube()
69+
await duckplayer.opensInYoutube()
7170
})
7271
})
7372

packages/special-pages/tests/page-objects/duck-player.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,16 @@ export class DuckPlayerPage {
155155
expect(await failure).toEqual('duck://settings/duckplayer')
156156
}
157157

158-
async clickPlayOnYouTube () {
159-
await this.page.getByText('Watch on YouTube').click()
160-
}
161-
162-
async navigatedToYouTube (videoID = MOCK_VIDEO_ID) {
163-
const youtubeSrc = new URL('https://www.youtube.com/watch')
164-
youtubeSrc.searchParams.set('v', videoID)
165-
await expect(this.page).toHaveURL(youtubeSrc.toString())
158+
async opensInYoutube () {
159+
// duck:// scheme will fail, but we can assert that it was tried and grab the URL
160+
const failure = new Promise(resolve => {
161+
this.page.context().on('requestfailed', f => {
162+
resolve(f.url())
163+
})
164+
})
165+
await this.page.getByRole('link', { name: 'Watch on YouTube' }).click()
166+
// todo(Shane): platform specific
167+
expect(await failure).toEqual('duck://player/openInYoutube?v=VIDEO_ID')
166168
}
167169

168170
/**

0 commit comments

Comments
 (0)