@@ -27,6 +27,7 @@ import {
2727 getChapters ,
2828 toPlaybackIdFromSrc ,
2929 toPlaybackIdParts ,
30+ fetchMetadata ,
3031 // isMuxVideoSrc,
3132} from '@mux/playback-core' ;
3233import type {
@@ -70,6 +71,7 @@ export const Attributes = {
7071 ASSET_START_TIME : 'asset-start-time' ,
7172 ASSET_END_TIME : 'asset-end-time' ,
7273 METADATA_URL : 'metadata-url' ,
74+ METADATA : 'metadata' ,
7375 PLAYBACK_ID : 'playback-id' ,
7476 PLAYER_SOFTWARE_NAME : 'player-software-name' ,
7577 PLAYER_SOFTWARE_VERSION : 'player-software-version' ,
@@ -113,10 +115,15 @@ class MuxVideoBaseElement extends CustomVideoElement implements Partial<MuxMedia
113115 #errorTranslator?: ( errorEvent : any ) => any ;
114116 #logo: string = '' ;
115117
118+ static getLogoHTML ( logoValue : string | null ) : string {
119+ if ( ! logoValue || logoValue === 'false' ) return '' ;
120+ return logoValue === 'default' ? muxLogo : `<img class="logo" part="logo" src="${ logoValue } " />` ;
121+ }
122+
116123 static getTemplateHTML ( attrs : Record < string , string > = { } ) {
117124 const template = super . getTemplateHTML ( attrs ) ;
118125
119- const logoHTML = this . prototype . getLogoHTML ( attrs [ Attributes . LOGO ] ?? null ) ;
126+ const logoHTML = this . getLogoHTML ( attrs [ Attributes . LOGO ] ?? null ) ;
120127 return `
121128 ${ template }
122129 <style>
@@ -743,7 +750,6 @@ class MuxVideoBaseElement extends CustomVideoElement implements Partial<MuxMedia
743750 }
744751
745752 set logo ( val ) {
746- console . log ( 'must set logo' ) ;
747753 if ( val ) {
748754 this . setAttribute ( Attributes . LOGO , val ) ;
749755 } else {
@@ -825,22 +831,7 @@ class MuxVideoBaseElement extends CustomVideoElement implements Partial<MuxMedia
825831 }
826832 case Attributes . METADATA_URL :
827833 if ( newValue ) {
828- fetch ( newValue )
829- . then ( ( resp ) => resp . json ( ) )
830- . then ( ( json ) => {
831- this . metadata = json ;
832- const metadata = json ?. [ 0 ] ?. metadata ?? [ ] ;
833- const planMeta = metadata . find ( ( m : { value : string } ) => m . value === 'mux-free-plan' ) ;
834-
835- if ( planMeta ) {
836- const event = new Event ( 'setdefaultlogo' , {
837- bubbles : true ,
838- composed : true ,
839- } ) ;
840- this . dispatchEvent ( event ) ;
841- }
842- } )
843- . catch ( ( ) => console . error ( `Unable to load or parse metadata JSON from metadata-url ${ newValue } !` ) ) ;
834+ fetchMetadata ( this as HTMLMediaElement , newValue ) ;
844835 }
845836 break ;
846837 case Attributes . STREAM_TYPE :
@@ -866,19 +857,12 @@ class MuxVideoBaseElement extends CustomVideoElement implements Partial<MuxMedia
866857 }
867858 }
868859
869- getLogoHTML ( logoValue : string | null = null ) : string {
870- const logo = logoValue ?? this . #logo ?? this . logo ;
871- if ( ! logo || logo === 'false' ) return '' ;
872-
873- return logo === 'default' ? muxLogo : `<img class="logo" part="logo" src="${ logo } " />` ;
874- }
875-
876860 updateLogo ( ) {
877861 if ( ! this . shadowRoot ) return ;
878862 const slotLogo = this . shadowRoot . querySelector ( 'slot[name="logo"]' ) ;
879863 if ( ! slotLogo ) return ;
880864
881- const logoHTML = this . getLogoHTML ( ) ;
865+ const logoHTML = ( this . constructor as typeof MuxVideoElement ) . getLogoHTML ( ! ! this . #logo ? this . #logo : this . logo ) ;
882866 ( slotLogo as HTMLElement ) . innerHTML = logoHTML ;
883867 }
884868
0 commit comments