@@ -324,14 +324,18 @@ const Comms = {
324
324
* To mock, use:
325
325
*
326
326
* `window.postMessage({ alwaysOpenSetting: false })`
327
+ *
328
+ * @param {object } opts
329
+ * @param {ImportMeta['env'] } opts.env
330
+ * @param {ImportMeta['platform'] } opts.platform
327
331
*/
328
- init : ( ) => {
332
+ init : ( opts ) => {
329
333
const messageContext = new MessagingContext ( {
330
334
context : 'specialPages' ,
331
335
featureName : 'duckPlayerPage' ,
332
- env : import . meta . env
336
+ env : opts . env
333
337
} )
334
- if ( import . meta . platform === 'windows' ) {
338
+ if ( opts . platform === 'windows' ) {
335
339
const opts = new WindowsMessagingConfig ( {
336
340
methods : {
337
341
// @ts -expect-error - not in @types/chrome
@@ -344,7 +348,7 @@ const Comms = {
344
348
} )
345
349
const messaging = new Messaging ( messageContext , opts )
346
350
Comms . messaging = new DuckPlayerPageMessages ( messaging )
347
- } else if ( import . meta . platform === 'integration' ) {
351
+ } else if ( opts . platform === 'integration' ) {
348
352
const config = new TestTransportConfig ( {
349
353
notify ( msg ) {
350
354
console . log ( msg )
@@ -541,34 +545,28 @@ const PlayOnYouTube = {
541
545
return document . querySelector ( '.play-on-youtube' )
542
546
} ,
543
547
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
-
562
548
/**
563
549
* If there is a valid video id, set the 'href' of the YouTube button to the
564
550
* video link url
551
+ *
552
+ * @param {object } opts
553
+ * @param {string } opts.base
565
554
*/
566
- init : ( ) => {
555
+ init : ( opts ) => {
567
556
const validVideoId = Comms . getValidVideoId ( )
568
557
const timestamp = Comms . getSanitizedTimestamp ( )
558
+ console . log ( { validVideoId } )
569
559
570
560
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 )
572
570
}
573
571
}
574
572
}
@@ -753,9 +751,15 @@ const MouseMove = {
753
751
*/
754
752
document . addEventListener ( 'DOMContentLoaded' , ( ) => {
755
753
Setting . init ( )
756
- Comms . init ( )
754
+ Comms . init ( {
755
+ platform : import . meta. platform ,
756
+ env : import . meta. env
757
+ } )
757
758
VideoPlayer . init ( )
758
759
Tooltip . init ( )
759
- PlayOnYouTube . init ( )
760
+ PlayOnYouTube . init ( {
761
+ // todo(Shane): platform specific
762
+ base : 'duck://player/openInYoutube'
763
+ } )
760
764
MouseMove . init ( )
761
765
} )
0 commit comments