let parentIframeContainer = window.document.getElementsByTagName('body')[0] const videojsWrapper = document.getElementById('stream1'); const videojsContainer = document.getElementById('container-stream1'); let videoPlayerContainer; let adsVideoButtons; const adsVideoContainer = document.getElementById('ads-video-container-stream1'); let modalType; let firstTime = true; let adPlayed = false; let videoAdPlayed = []; let videoAdPlayedIndex = 0; let videoAdRepeatEach = 900; // seconds let timePrev = 0; let timeNext = 0; const mf = Math.floor; let adPlaybackController; let isSeeking = false; let timerMediascope; let prevTimeMediascope = 0; let getRequest = function({ type, view, fts }) { const cid = 'ren_tv'; const tms = 'ren_tv'; const idc = 171; let url = 'https://tns-counter.ru/e/ec01&cid=' + cid + '&typ=1&tms=' + tms + '&idc=' + idc + '&idlc=v-1234567&ver=0&type={*type*}&view={*view*}&fts={*fts*}'; const xhr = new XMLHttpRequest(); xhr.open('GET', url.replace('{*type*}', type).replace('{*view*}', view).replace('{*fts*}', fts), true); xhr.send(); } const root = document.getElementById(`container-stream1`); let rootUIModal; let sharedData; let relatedData; const showRelated = function () { modalType = 'related'; if (!relatedData) return; if ( !rootUIModal.el().querySelector('.fp-related-data') ) { rootUIModal.el().append(relatedData); } toggleModal(); }; const toggleModal = function () { const fpModal = rootUIModal.el(); const fpModalType = root.querySelector('.vjs-'+ modalType +'-button'); if (fpModal.classList.contains('is-active')) { fpModal.classList.remove('is-active'); } else { fpModal.classList.add('is-active'); } if (fpModalType.classList.contains('is-active')) { fpModalType.classList.remove('is-active'); } else { fpModalType.classList.add('is-active'); } if (root.classList.contains('shown-'+ modalType)) { root.classList.remove('shown-'+ modalType); } else { root.classList.add('shown-'+ modalType); } }; const toggleFullscreen = function (elem) { if (elem.requestFullscreen) { elem.requestFullscreen(); } else if (elem.webkitRequestFullscreen) { elem.webkitRequestFullscreen(); } else if (elem.msRequestFullscreen) { elem.msRequestFullscreen(); } } var videoAdsPlay = function (video, videojsContainer, index, playOnceTNS) { ya.videoAd .loadModule('AdLoader') // 1) Создаем экземпляр AdLoader с рекламными параметрами .then(function (module) { return module.AdLoader.create( { adFoxParameters: { containerId: 'container-stream1', ownerId: '264443', // partnerId: '264443', // category: '0', // showGuiForVpaid: true, // impId: '1', params: { p1: 'bzipx', p2: 'fuki', puid1: '283', puid2: '229103', puid3: '187681', puid4: 'ren.tv', puid5: '99', puid6: '9999', puid50: '9999', puid51: '99', // puid7: '', puid8: '', puid9: '7', // puid10: '', puid11: '187643', puid12: '0', puid13: '186102', // puid15: '', // puid16: '', // puid20: '', puid21: 1, puid26: '0', extid_tag: 'izvestia', dl: window.location.href, 'target-ref': 0 ? document.referrer : window.location.href } } }, ); }) // 2) Загружаем рекламу .then(function (adLoader) { return adLoader.loadAd(); }) // 4) Запускаем рекламу .then(function (adViewer) { // Создаем контроллер воспроизведения adPlaybackController = adViewer.createPlaybackController(adsVideoContainer, videojsContainer); adsVideoContainer.classList.add('embedded'); videoPlayerContainer.classList.add('d-none'); // Подписываемся на событие окончания рекламы adPlaybackController.subscribe('AdStopped', function () { videoAdPlayedIndex = index + 1; videoAdPlayed[videoAdPlayedIndex] = true; adsVideoContainer.style.display = 'none'; adsVideoContainer.classList.remove('embedded'); if (false) { showRelated(); } else { video.play(); } videoPlayerContainer.classList.remove('d-none'); }); // Запускаем проигрывание рекламы adPlaybackController.playAd(); if (videoJSPlayer.isFullscreen()) { const timer = setTimeout(function() { adsVideoButtons = document.querySelector('.video-js-player > div:last-child'); // toggleFullscreen(adsVideoButtons); clearTimeout(timer); }, 0); } if (true) { setTimeout(function() { var isSafari = navigator.userAgent.indexOf('Mac OS') > -1 || navigator.userAgent.indexOf('iPad') > -1 || navigator.userAgent.indexOf('iPhone') > -1; if (isSafari) { adPlaybackController.setAdVolume(parseFloat(0)); } else { adPlaybackController.setAdVolume(parseFloat(1)); } adPlaybackController.resumeAd(); }, 250); } if (playOnceTNS) { (new Image()).src = '//www.tns-counter.ru/V13a***R>' + document.referrer.replace(/\*/g,'%2a') + '*everest_ru/ru/UTF-8/tmsec=everest_network/' + Math.round(Math.random()*1E9) if (false) { (new Image()).src = '//www.tns-counter.ru/V13a***R>' + document.referrer.replace(/\*/g,'%2a') + '*everest_ru/ru/UTF-8/tmsec=everest_sport/' + Math.round(Math.random()*1E9) } } }) // Если что-то пошло не так, логируем ошибку в консоль .catch(function (error) { videoAdPlayedIndex = index + 1; videoAdPlayed[videoAdPlayedIndex] = true; adsVideoContainer.style.display = 'none'; if (false) { showRelated(); } else { video.play(); } }); } let hasAdv = 1; let isIOS = (/iPad|iPhone|iPod/.test(navigator.platform) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) && !window.MSStream || navigator.userAgent.indexOf('Mac OS X') != -1 let videoJSPlayer = videojs('video-js-container-stream1', { controls: true, preload: 'none', muted: isIOS || false, playsinline: isIOS || false, autoplay : false, fullscreen: true, poster : 'https://cdn.ren.tv/images/default-1200x675.png', // nativeControlsForTouch: false, userActions: { hotkeys: function(event) { window.addEventListener('keydown', function(e) { if ([32, 37, 38, 39, 40].includes(event.which)) { e.stopImmediatePropagation(); e.preventDefault(); } }); const volume = this.volume(); const ended = this.ended(); const paused = this.paused(); const seeking = this.currentTime(); const duration = this.duration(); if (event.which === 39) { // Arrow Right this.currentTime(seeking + 10 >= duration ? duration : seeking + 10); } if (event.which === 37) { // Arrow Left this.currentTime(seeking - 10 <= 0 ? 0 : seeking - 10); } if (event.which === 38) { // Arrow Up this.volume(volume + 0.2 >= 1 ? 1 : volume + 0.2); } if (event.which === 40) { // Arrow Down this.volume(volume - 0.2 <= 0 ? 0 : volume - 0.2); } if (event.which === 32 && !ended) { // Space if (paused) { this.play(); } else { this.pause(); } } } }, controlBar: { children: (true) ? [ 'playToggle', 'volumePanel', 'fullscreenToggle' ] : ( (false) ? [ 'volumePanel', 'playToggle', 'currentTimeDisplay', 'timeDivider', 'durationDisplay', 'fullscreenToggle', 'progressControl' ] : [ 'progressControl', 'playToggle', 'volumePanel', 'currentTimeDisplay', 'timeDivider', 'durationDisplay', // 'liveDisplay', // 'seekToLive', // 'remainingTimeDisplay', // 'customControlSpacer', // 'playbackRateMenuButton', // 'chaptersButton', // 'descriptionsButton', // 'subsCapsButton', // 'audioTrackButton', 'fullscreenToggle' ] ) } }) videoJSPlayer.ready(function() { videoPlayerContainer = document.querySelector('.video-js-container.video-js'); const vjsFullscreenControl = document.querySelector('#video-js-container-stream1 .vjs-fullscreen-control'); /* vjsFullscreenControl.addEventListener('mouseup', () => { if (!videoJSPlayer.isFullscreen()) { const timer = setTimeout(function() { // toggleFullscreen(adsVideoContainer); clearTimeout(timer); }, 500); } }); */ addEventListener('touchmove', onTouchMove, { passive: false }); function onTouchMove(e) { e.preventDefault } /* vjsFullscreenControl.addEventListener('touchstart', () => { if (!videoJSPlayer.isFullscreen()) { const timer = setTimeout(function() { // toggleFullscreen(adsVideoContainer); clearTimeout(timer); }, 500); } }); */ const video = this.player(); root.classList.add('is-hovered'); let isPaused = false; let startPlaying = false; let timeout; let allTitled = root.querySelectorAll('[title]'); allTitled.forEach(function(itemTitle) { try { itemTitle.setAttribute('title', ''); } catch(error) {} }) root.addEventListener('mousemove', function() { root.classList.add('is-hovered'); clearTimeout(timeout); timeout = setTimeout(function() { root.classList.remove('is-hovered'); }, 2600); }) root.addEventListener('touchstart', function() { root.classList.add('is-hovered'); clearTimeout(timeout); timeout = setTimeout(function() { root.classList.remove('is-hovered'); }, 2600); }) /* root.addEventListener('mouseleave', function() { timeout = setTimeout(function() { root.classList.remove('is-hovered'); }, 2600); }) */ root.addEventListener('touchend', function() { timeout = setTimeout(function() { root.classList.remove('is-hovered'); }, 2600); }) this.on('play', function(e) { if (parentIframeContainer) { parentIframeContainer.setAttribute('data-played', '0'); } if (!startPlaying) { clearTimeout(timeout) timeout = setTimeout(function() { root.classList.remove('is-hovered') }, 2500); } const time = Math.round(this.currentTime()); if(true && firstTime) { ym(25969384, 'init', { defer: true }); ym(25969384, 'hit', `/stream/embed/1`); } firstTime = false; ym(25969384,'reachGoal','VIDEO_PLAY'); ym(25969384,'reachGoal','VIDEO_PLAY_1'); if ( (!isSeeking || (isSeeking && time !== prevTimeMediascope)) || time === 0 ) { getRequest({ type: '2', view: '1', fts: time }); } const that = this; timerMediascope = setInterval(function() { getRequest({ type: '2', view: '2', fts: Math.round(that.currentTime()) }); }, 30000); isSeeking = false; isPaused = false; root.classList.remove('is-paused'); startPlaying = true; }) this.on('pause', function(e) { isPaused = true; if(!adPlayed && parentIframeContainer && parentIframeContainer.getAttribute('data-played') === '0' ) { parentIframeContainer.setAttribute('data-played', ''); } root.classList.add('is-paused'); if (false) { if(!adPlayed && parentIframeContainer && parentIframeContainer.getAttribute('data-played') === '0' ) { parentIframeContainer && parentIframeContainer.setAttribute('data-played', ''); } } clearInterval(timerMediascope); const time = Math.round(this.currentTime()); if (this.currentTime() === this.duration()) { getRequest({ type: '2', view: '0', fts: time }); isSeeking = true; } else { ym(25969384,'reachGoal','VIDEO_PAUSE'); ym(25969384,'reachGoal','VIDEO_PAUSE_1'); const timer = setTimeout(function() { if (!isSeeking && startPlaying) { getRequest({ type: '2', view: '3', fts: time }); isSeeking = false; } clearTimeout(timer); }, 0); } }) this.on('waiting', function(e) { if (!videojsWrapper.classList.contains('is-progress')) { videojsWrapper.classList.add('is-progress'); } }) this.on('canplay', function(e) { if (videojsWrapper.classList.contains('is-progress')) { videojsWrapper.classList.remove('is-progress'); } /* if (true) { videoJSPlayer.muted(false); videoJSPlayer.volume(window.localStorage.getItem('volume') || 0.5); } */ }) function throttle (callback, limit) { var waiting = false; // Initially, we're not waiting return function () { // We return a throttled function if (!waiting) { // If we're not waiting callback.apply(this, arguments); // Execute users function waiting = true; // Prevent future invocations const timer = setTimeout(function () { // After a period of time waiting = false; // And allow future invocations clearTimeout(timer); }, limit); } } } this.on('timeupdate', throttle(function() { if (!isSeeking) { prevTimeMediascope = Math.round(this.currentTime()); } }, 240)); this.on('seeking', throttle(function() { if (!isSeeking) { const time = Math.round(this.currentTime()); getRequest({ type: '2', view: '0', fts: prevTimeMediascope }); isSeeking = true; } // isPaused = true; }, 500)); this.on('playing', function() { if (true) { // true : false /* this.on('playing', function(e) { if (true && !videoAdPlayed[videoAdPlayedIndex] && window.ya && ya.videoAd) { // videoAdPlayed[videoAdPlayedIndex] = true; // video.pause(); // videoAdsPlay(video, videojsContainer, videoAdPlayedIndex, true); // adsVideoContainer.style.display = 'block'; } }); */ } if (false) { if(parentIframeContainer) { parentIframeContainer.setAttribute('data-played', '0'); } } }); this.on('ended', function(e) { if (true) { // true : false if (videoAdPlayed[videoAdPlayedIndex]) { // videoAdPlayed[videoAdPlayedIndex] = false; videoAdPlayedIndex = 0; videoAdPlayed = []; } if (false && !videoAdPlayed[videoAdPlayedIndex] && window.ya && ya.videoAd) { videoAdPlayed[videoAdPlayedIndex] = true; video.pause(); videoAdsPlay(video, videojsContainer, videoAdPlayedIndex, true); adsVideoContainer.style.display = 'block'; } if (true) { showRelated(); } } /* if (false) { // showRelated(); } */ }); this.on(video, 'volumechange', function(vol) { window.localStorage.setItem('volume', Math.round(videoJSPlayer.volume() * 100) / 100); }); const controlBar = videoJSPlayer.getChild('controlBar'); const Component = videojs.getComponent('Component'); const opts = {}; class RootUI extends Component { constructor(player, opts) { super(player, opts) } createEl() { return super.createEl('div', { className: 'vjs-ui' }, { 'role': 'group' }) } } let rootUI = videoJSPlayer.addChild(new RootUI(videoJSPlayer, opts)); class RootUIModal extends Component { constructor(player, opts) { super(player, opts) } createEl() { return super.createEl('div', { className: 'vjs-modal' }, { 'role': 'group' }) } } rootUIModal = rootUI.addChild(new RootUIModal(videoJSPlayer, opts)); sharedData = root.querySelector('.fp-shared-data'); relatedData = root.querySelector('.fp-related-data'); const button = videojs.getComponent('Button'); const spacerButton = videojs.extend(button, { constructor: function() { button.apply(this, arguments); this.addClass('vjs-spacer'); }, handleClick: function() { } }) videojs.registerComponent('spacerButton', spacerButton) if (true) { const pos = (true) ? 2 : 6 controlBar.addChild('spacerButton', { }, pos); } const modalClose = videojs.extend(button, { constructor: function() { button.apply(this, arguments); this.controlText('Закрыть'); this.addClass('vjs-modal-close'); }, handleClick: function() { if (!isPaused) { video.play(); } toggleModal(); modalType = ''; isPaused = false; } }) videojs.registerComponent('modalClose', modalClose); rootUIModal.addChild('modalClose', { }); if (false) { const sharedButton = videojs.extend(button, { constructor: function() { button.apply(this, arguments); this.controlText('Поделиться'); this.addClass('vjs-custom-button'); this.addClass('vjs-shared-button'); }, handleClick: function() { if ( !rootUIModal.el().querySelector('.fp-shared-data') ) { rootUIModal.el().append(sharedData); } modalType = 'shared'; isPaused = videoJSPlayer.paused(); video.pause(); toggleModal(); } }) videojs.registerComponent('sharedButton', sharedButton); rootUI.addChild('sharedButton', { }); } if (false) { const relatedButton = videojs.extend(button, { constructor: function() { button.apply(this, arguments) this.controlText('Похожее') this.addClass('vjs-custom-button') this.addClass('vjs-related-button') }, handleClick: function() { isPaused = videoJSPlayer.paused(); video.pause(); showRelated(); } }) videojs.registerComponent('relatedButton', relatedButton); rootUI.addChild('relatedButton', { }); } if (false) { const miniPlayerButton = videojs.extend(button, { constructor: function() { button.apply(this, arguments) this.addClass('vjs-mini-player') }, handleClick: function() { } }) videojs.registerComponent('miniPlayerButton', miniPlayerButton); const pos = (true) ? 3 : 7 controlBar.addChild('miniPlayerButton', { }, pos); // Paused Played video if Open Other const callback = (mutationsList, observer) => { for (const mutation of mutationsList) { if (mutation.type === 'attributes' && mutation.attributeName === 'data-played') { const playedId = +mutation.target.dataset.played if (playedId !== 0) { video.pause(); adPlaybackController && adPlaybackController.pauseAd(); } } } }; const observer = new MutationObserver(callback); observer.observe(parentIframeContainer, { attributes: true }); } if (true) { // true : false /* this.on('playing', function(e) { if (true && !videoAdPlayed[videoAdPlayedIndex] && window.ya && ya.videoAd) { // videoAdPlayed[videoAdPlayedIndex] = true; // video.pause(); // videoAdsPlay(video, videojsContainer, videoAdPlayedIndex, true); // adsVideoContainer.style.display = 'block'; } }); */ this.on('timeupdate', function(e) { timeNext = mf(this.currentTime()); if( false && timeNext > 0 && timePrev !== timeNext && timeNext % videoAdRepeatEach === 0 && videoAdPlayed[videoAdPlayedIndex] ) { // video.pause(); // adsVideoContainer.style.display = 'block'; // videoAdsPlay(video, videojsContainer, videoAdPlayedIndex, false); } timePrev = timeNext; }); } }) // [.ready()] videoJSPlayer.src([ { "src": "https://live.ren.tv/ren/stream1/playlist.m3u8", "type": "application/x-mpegurl" } ]);