diff --git a/3p/viqeoplayer.js b/3p/viqeoplayer.js index 79bc71597bc2b..0b7f2397aebf5 100644 --- a/3p/viqeoplayer.js +++ b/3p/viqeoplayer.js @@ -13,35 +13,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -import {assertAbsoluteHttpOrHttpsUrl, tryDecodeUriComponent} from '../src/url'; import {getData} from '../src/event-helper'; import {loadScript} from './3p'; -import {parseJson} from '../src/json'; -import {setStyles} from '../src/style'; +import {tryDecodeUriComponent} from '../src/url'; /** * @param {Window} global - * @param {boolean} autoplay * @param {Object} VIQEO - * @param {function(Object)} VIQEO.getPlayers - returns viqeo player - * @param {function(function(Object), Object)} VIQEO.subscribeTracking - subscriber * @private */ -function viqeoPlayerInitLoaded(global, autoplay, VIQEO) { - const {canonicalUrl, pageViewId} = global.context; - VIQEO['setConfig']({url: canonicalUrl, amp: {pageViewId}}); +function viqeoPlayerInitLoaded(global, VIQEO) { + const {canonicalUrl, pageViewId, sourceUrl} = global.context; + const data = getData(global.context); let viqeoPlayerInstance; + VIQEO['setConfig']({url: sourceUrl, amp: {pageViewId, canonicalUrl}}); + VIQEO['subscribeTracking'](params => { + viqeoPlayerInstance = params['player']; + }, 'Player:added'); + VIQEO['createPlayer']({ + videoId: data['videoid'], + profileId: data['profileid'], + parent: global.document.getElementById('c'), + }); + global.addEventListener('message', parseMessage, false); - subscribe('added', 'ready', () => { - const players = VIQEO['getPlayers']({container: 'stdPlayer'}); - viqeoPlayerInstance = players && players[0]; - }); - subscribe('started', 'started', () => { - // if autoplay is off then player will be paused as it just has been started - !autoplay && viqeoPlayerInstance && viqeoPlayerInstance.pause(); - }); + subscribe('videoLoaded', 'ready'); + subscribe('previewLoaded', 'ready'); + subscribe('started', 'started'); subscribe('paused', 'pause'); subscribe('played', 'play'); subscribe('replayed', 'play'); @@ -54,19 +53,12 @@ function viqeoPlayerInitLoaded(global, autoplay, VIQEO) { * Subscribe on viqeo's events * @param {string} playerEventName * @param {string} targetEventName - * @param {function()|undefined|null} extraHandler * @private */ - function subscribe(playerEventName, targetEventName, extraHandler = null) { + function subscribe(playerEventName, targetEventName) { VIQEO['subscribeTracking']( - () => { - sendMessage(targetEventName); - if (extraHandler) { - extraHandler(); - } - }, - {eventName: `Player:${playerEventName}`, container: 'stdPlayer'} - ); + () => { sendMessage(targetEventName); }, + `Player:${playerEventName}`); } /** @@ -79,7 +71,9 @@ function viqeoPlayerInitLoaded(global, autoplay, VIQEO) { const name = params && params['trackingParams'] && params['trackingParams'].name; const targetEventName = eventsDescription[name]; - sendMessage(targetEventName); + if (targetEventName) { + sendMessage(targetEventName); + } }, 'Player:userAction'); } @@ -123,17 +117,6 @@ function viqeoPlayerInitLoaded(global, autoplay, VIQEO) { */ export function viqeoplayer(global) { const data = getData(global.context); - let autoplay = false; - try { - autoplay = parseJson(global.name)['attributes']._context['autoplay']; - } catch (e) { - // do nothing - } - const videoId = data['videoid']; - const profileId = data['profileid']; - - const markTagsAdvancedParams = data['tag-settings']; - const kindIsProd = data['data-kind'] !== 'stage'; let scriptPlayerInit = data['script-url']; @@ -143,56 +126,11 @@ export function viqeoplayer(global) { ) || (kindIsProd - ? 'https://cdn.viqeo.tv/js/vq_player_init.js?amp=true' - : 'https://static.viqeo.tv/js/vq_player_init.js?branch=dev1&=true' + ? 'https://cdn.viqeo.tv/js/vq_starter.js' + : 'https://static.viqeo.tv/js/vq_player_init.js?branch=dev1' ); - // embed preview url - let previewUrl = data['player-url']; - previewUrl = - (previewUrl - && previewUrl.length && decodeURI(previewUrl) - ) - || (kindIsProd ? 'https://cdn.viqeo.tv/embed' : 'https://stage.embed.viqeo.tv'); - - // Create preview iframe source path - previewUrl = assertAbsoluteHttpOrHttpsUrl( - `${previewUrl}/?vid=${videoId}&=true`); - const doc = global.document; - const mark = doc.createElement('div'); - - const markTagsStyle = Object.assign({ - position: 'relative', - width: '100%', - height: '0', - paddingBottom: '100%', - }, markTagsAdvancedParams); - - setStyles(mark, markTagsStyle); - - mark.setAttribute('data-vnd', videoId); - mark.setAttribute('data-profile', profileId); - mark.classList.add('viqeo-embed'); - - const iframe = doc.createElement('iframe'); - - iframe.setAttribute('width', '100%'); - iframe.setAttribute('height', '100%'); - iframe.setAttribute('style', 'position: absolute'); - iframe.setAttribute('frameBorder', '0'); - iframe.setAttribute('allowFullScreen', ''); - iframe.src = previewUrl; - - mark.appendChild(iframe); - - doc.getElementById('c').appendChild(mark); - - loadScript(global, scriptPlayerInit, () => { - if (!global['VIQEO']) { - global['onViqeoLoad'] = - viqeoPlayerInitLoaded.bind(null, global, autoplay); - } else { - viqeoPlayerInitLoaded(global, autoplay, global['VIQEO']); - } - }); + global['onViqeoLoad'] = VIQEO => + viqeoPlayerInitLoaded(global, VIQEO); + loadScript(global, scriptPlayerInit); } diff --git a/examples/viqeo.amp.html b/examples/viqeo.amp.html index 8493019ad7aee..24ea5647357e8 100644 --- a/examples/viqeo.amp.html +++ b/examples/viqeo.amp.html @@ -73,7 +73,6 @@