@@ -1266,102 +1266,14 @@ function sepiaFW_build_ui_cards(){
12661266 cardBody . appendChild ( linkCardEle ) ;
12671267
12681268 //Experimenting with web players - note: use data.embedded ?
1269- console . error ( "TEST" , "embedWebPlayer" , data ) ; //DEBUG
12701269 var embedWebPlayer = data . type && ( data . type == "musicSearch" || data . type == "videoSearch" )
12711270 && data . typeData && Cards . canEmbedWebPlayer ( data . typeData . service ) ;
12721271 if ( embedWebPlayer ) {
1273- var allowIframe ;
1274- if ( isSafeSource ) {
1275- allowIframe = 'autoplay *; encrypted-media *;' ;
1276- } else {
1277- allowIframe = 'encrypted-media *;' ;
1278- }
12791272 //Embedded player
1280- if ( data . brand == "default" ) {
1281- addEmbeddedPlayerToCard ( cardBody , data . type , data . typeData ) ;
1282-
1283- //Spotify
1284- } else if ( data . brand == "Spotify" ) {
1285- var webPlayerDiv = document . createElement ( 'DIV' ) ;
1286- webPlayerDiv . className = "spotifyWebPlayer embeddedWebPlayer cardBodyItem fullWidthItem" ;
1287- var contentUrl = "https://" + linkUrl . replace ( "spotify:" , "open.spotify.com/embed/" ) . replace ( ":play" , "" ) . replace ( / : / g, "/" ) . trim ( ) ;
1288- webPlayerDiv . innerHTML = '<iframe '
1289- + 'src="" width="100%" height="80" frameborder="0" allowtransparency="true" '
1290- + 'allow="' + allowIframe + '" '
1291- + 'sandbox="allow-forms allow-popups allow-same-origin allow-scripts" ' + '>'
1292- + '</iframe>' ;
1293- $ ( webPlayerDiv ) . find ( "iframe" ) . attr ( "src" , contentUrl ) ;
1294- cardBody . appendChild ( webPlayerDiv ) ;
1295- //Apple Music
1296- } else if ( data . brand == "Apple Music" ) {
1297- var webPlayerDiv = document . createElement ( 'DIV' ) ;
1298- webPlayerDiv . className = "appleMusicWebPlayer embeddedWebPlayer cardBodyItem fullWidthItem" ;
1299- var contentUrl ;
1300- if ( linkUrl . indexOf ( "/artist/" ) > 0 ) {
1301- contentUrl = linkUrl . replace ( / ^ h t t p s : \/ \/ .* ?\/ / , "https://geo.itunes.apple.com/" ) ;
1302- } else {
1303- contentUrl = linkUrl . replace ( / ^ h t t p s : \/ \/ .* ?\/ / , "https://embed.music.apple.com/" ) ;
1304- }
1305- webPlayerDiv . innerHTML = '<iframe '
1306- + 'allow="' + allowIframe + '" '
1307- + 'frameborder="0" height="150" '
1308- + 'style="width:100%;max-width:660px;overflow:hidden;background:transparent;" '
1309- + 'sandbox="allow-forms allow-popups allow-same-origin allow-scripts '
1310- + ( ( SepiaFW . ui . isSafari ) ? 'allow-storage-access-by-user-activation' : '' )
1311- + ' allow-top-navigation-by-user-activation" '
1312- + 'src="">'
1313- + '</iframe>' ;
1314- $ ( webPlayerDiv ) . find ( "iframe" ) . attr ( "src" , contentUrl ) ;
1315- cardBody . appendChild ( webPlayerDiv ) ;
1316- //YouTube
1317- } else if ( data . brand == "YouTube" ) {
1318- //console.log('YouTube'); //DEBUG
1319- var webPlayerDiv = document . createElement ( 'DIV' ) ;
1320- var playerId = currentLinkItemId ++ ;
1321- webPlayerDiv . className = "youTubeWebPlayer embeddedWebPlayer cardBodyItem fullWidthItem"
1322- var f = document . createElement ( 'iframe' ) ;
1323- f . id = 'youTubeWebPlayer-' + playerId ;
1324- f . allow = allowIframe ;
1325- f . sandbox = "allow-same-origin allow-scripts allow-presentation allow-popups" ;
1326- f . frameBorder = 0 ;
1327- f . style . width = "100%" ; f . style . height = "280px" ; f . style . overflow = "hidden" ;
1328- f . style . border = "4px solid" ; f . style . borderColor = "#212121" ;
1329- if ( data . autoplay ) {
1330- //console.log('add controls'); //DEBUG
1331- if ( isSafeSource ) {
1332- //stop all previous audio first
1333- if ( SepiaFW . client . controls ) {
1334- SepiaFW . client . controls . media ( {
1335- action : "stop" ,
1336- skipFollowUp : true
1337- } ) ;
1338- } else {
1339- SepiaFW . audio . stop ( ) ;
1340- }
1341- //add controls and start
1342- addYouTubeControls ( f , true ) ;
1343- } else {
1344- //add controls only
1345- addYouTubeControls ( f , false ) ;
1346- }
1347- } else {
1348- //add controls only
1349- addYouTubeControls ( f , false ) ;
1350- }
1351- if ( linkUrl . indexOf ( "/embed" ) < 0 ) {
1352- //convert e.g.: https://www.youtube.com/results?search_query=purple+haze%2C+jimi+hendrix
1353- f . src = "https://www.youtube.com/embed?autoplay=1&enablejsapi=1&playsinline=1&iv_load_policy=3&fs=1&listType=search&list="
1354- + linkUrl . replace ( / .* ?s e a r c h _ q u e r y = / , "" ) . trim ( ) ;
1355- } else {
1356- f . src = linkUrl ; //TODO: fix URL security
1357- }
1358- if ( ! isSafeSource ) {
1359- //remove autoplay flag
1360- f . src = f . src . replace ( "autoplay=1" , "autoplay=0" ) ;
1361- }
1362- cardBody . appendChild ( webPlayerDiv ) ;
1363- webPlayerDiv . appendChild ( f ) ;
1364- }
1273+ addEmbeddedPlayerToCard ( cardBody , data . type , data . typeData , isSafeSource , {
1274+ brand : data . brand ,
1275+ autoplay : data . autoplay
1276+ } ) ;
13651277 }
13661278
13671279 //link button(s)
@@ -2167,12 +2079,18 @@ function sepiaFW_build_ui_cards(){
21672079 } ) ;
21682080 cardBody . appendChild ( cardEle ) ;
21692081 }
2170- function addEmbeddedPlayerToCard ( cardBody , type , data ) {
2171- //cardBody class should be -> 'sepiaFW-embedded-player-container'
2082+ function addEmbeddedPlayerToCard ( cardBody , type , data , isSafeSource , options ) {
2083+ if ( ! options ) options = { } ;
2084+ //type: musicSearch, videoSearch (currently same)
2085+ var widget = data . service ? data . service . split ( "_" ) [ 0 ] : "default" ;
21722086 var player = new SepiaFW . ui . cards . embed . MediaPlayer ( {
21732087 parentElement : cardBody ,
2174- widget : "default"
2088+ widget : widget ,
2089+ autoplay : options . autoplay ,
2090+ safeRequest : isSafeSource , //came from assistant or private channel?
2091+ brand : options . brand
21752092 } ) ;
2093+ return player ;
21762094 }
21772095
21782096 //-- Plot cards --
0 commit comments