Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ads for video #1057

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions components/lenta/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#lenta .shareinlenta.rendered .sharecnt {
display: block;
}
#lenta .adsCheckbox {
padding-right: 1em;
}
#lenta .optimizationTip {
height: 150px;
display: flex;
Expand Down
248 changes: 185 additions & 63 deletions components/lenta/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var lenta = (function(){
var mid = p.mid;
var making = false, ovf = false;
var w, essenseData, recomended = [], initialized, recommended, mestate, initedcommentes = {}, canloadprev = false,
video = false, isotopeinited = false, videosVolume = 0, fullscreenvideoShowing = null, loadedcachedHeight, lwidth = 0, bannerComment = null;
video = false, isotopeinited = false, videosVolume = 0, fullscreenvideoShowing = null, loadedcachedHeight, lwidth = 0;
var loadertimeout = null
var lastcache = null
var subloaded = false
Expand Down Expand Up @@ -906,7 +906,6 @@ var lenta = (function(){
$(this).closest('.jsPlayerLoading').addClass('loading')
$(this).closest('.js-player-dummy').addClass('js-player-ini')


actions.initVideo(share, function(v){

if (players[share.txid])
Expand All @@ -925,18 +924,19 @@ var lenta = (function(){
button = null
},

initVideo : function(share, clbk, shadow){
initVideo : function(share, clbk, shadow, ads){

if(!share || !share.txid || !el.share[share.txid]) return

var pels = el.share[share.txid].find('.js-player-ini');
var vel = el.share[share.txid].find('.videoWrapper')
var ended = false;

if (pels.closest('.shareTable').attr('stxid') != (share.txid || '')) return

if(!vel.length) return

if (shadow && !players[share.txid]){
if (shadow){

players[share.txid] = {
shadow : true,
Expand Down Expand Up @@ -1015,7 +1015,7 @@ var lenta = (function(){

var startTime = 0;

if (self.app.platform.sdk.videos.historyget && share.itisvideo()){
if (self.app.platform.sdk.videos.historyget && share.itisvideo() && !ads){

var pr = self.app.platform.sdk.videos.historyget(share.txid)

Expand Down Expand Up @@ -1060,6 +1060,7 @@ var lenta = (function(){
fullscreenchange : self.app.mobile.fullscreenmode,

play : function(){

videopaused = false

self.app.actions.playingvideo(players[share.txid].p)
Expand Down Expand Up @@ -1100,6 +1101,12 @@ var lenta = (function(){
self.app.platform.sdk.activity.adduser('video', share.address, 6 * position / duration, share)
}

if (playbackState === 'ended' && ads && !ended){

ended = true;
clbk(true, true);
}

},

error : function(error){
Expand Down Expand Up @@ -1142,6 +1149,7 @@ var lenta = (function(){
s.logoType = self.app.meta.fullname
s.app = self.app
s.light = true

PlyrEx(pels[0], s, callback, readyCallback)

}
Expand Down Expand Up @@ -1575,11 +1583,7 @@ var lenta = (function(){

fullScreenVideo : function(id, clbk, auto){

if (fullscreenvideoShowing) { return }
if (fullscreenvideoShowed) { return }
if (essenseData.openapi){ return }

fullscreenvideoShowing = id
console.log('fullscreenvideo');

var _el = el.share[id]
var share = self.app.platform.sdk.node.shares.getWithTemp(id)
Expand All @@ -1597,88 +1601,198 @@ var lenta = (function(){
share.address = self.app.platform.sdk.address.pnet().address
}*/

var initVideoClbk = function(ads){

if (fullscreenvideoShowing) { return }
if (fullscreenvideoShowed) { return }
if (essenseData.openapi){ return }

actions.initVideo(share, function(res){
fullscreenvideoShowing = id

actions.initVideo(share, function(res, next){

fullscreenvideoShowing = null
if (next){

if(!res){
return
}

if(!players[id]) return;
players[share.txid] = null;

self.app.actions.closepip()
actions.exitFullScreenVideo(id);

fullscreenvideoShowed = id;
renders.url(urlWrapper, share.url, share, function(){

self.app.mobile.reload.destroyparallax()
renders.urlContent(share, function(){

if(!video) actions.initVideoLight(share, null, null, true);

if(isotopeinited) el.shares.isotope()

shareInitingMap[share.txid] = false;

initVideoClbk();

});

})

self.app.pseudofullscreenmode = true
return;
}

_el.addClass('fullScreenVideo')

actions.videoPosition(id)
if (!res){
return;
}

actions.fullScreenVideoParallax(_el, id)
fullscreenvideoShowing = null;

self.app.mobile.statusbar.gallerybackground()
if (ads){

self.app.nav.api.history.addParameters({
v : id
})
videopaused = false;

} else {

var player = players[id]
self.app.actions.closepip()

player.p.prepare().then(() => {
fullscreenvideoShowed = id;

if(!essenseData.openapi && !essenseData.second){
self.app.mobile.reload.destroyparallax()

lastscroll = self.app.lastScrollTop
self.app.actions.offScroll()
self.app.pseudofullscreenmode = true

_el.addClass('fullScreenVideo')

if(!player.p.playing && !auto){
player.p.play()
}
actions.videoPosition(id)

actions.fullScreenVideoParallax(_el, id)

self.app.mobile.statusbar.gallerybackground()

self.app.nav.api.history.addParameters({
v : id
})

if (player.p.enableHotKeys) player.p.enableHotKeys()


actions.addRecommendationsFullScreenVideo(id)
}


actions.setVolume(players[id], videosVolume || 0.5)
var player = players[id]

if(!essenseData.comments && !share.temp && !share.relay){
player.p.prepare().then(() => {

retry(function(){
return initedcommentes[id] || !el.c
}, function(){
if(!essenseData.openapi && !essenseData.second){

if(el.c){
if (initedcommentes[id]){
initedcommentes[id].destroy()
initedcommentes[id] = null
}

renders.comments(id, false, true)
}
lastscroll = self.app.lastScrollTop

if (!ads){
self.app.actions.offScroll();
}


if(!player.p.playing && !auto){
player.p.play()
}

if (player.p.enableHotKeys) player.p.enableHotKeys()


actions.addRecommendationsFullScreenVideo(id)
}

actions.setVolume(players[id], videosVolume || 0.5)

if(!essenseData.comments && !share.temp && !share.relay){

retry(function(){
return initedcommentes[id] || !el.c
}, function(){

if(el.c){
if (initedcommentes[id]){
initedcommentes[id].destroy()
initedcommentes[id] = null
}

renders.comments(id, false, true)
}

})

}




if (clbk)
clbk()

})

}, false, ads)

}

var adsDate = Number(localStorage.getItem('adsDate') || 0);

var status = app.platform.sdk.localshares.status(share.txid);

if (self.app.localization.key === 'ru' && status !== 'saved' && status !== 'saving' && status !== 'paused' && share.settings.ads && adsDate < new Date().getTime()){

const numWeeks = 3;
let weeks = new Date();
weeks.setDate(weeks.getDate() + numWeeks * 7);
weeks = weeks.getTime();

localStorage.setItem('adsDate', weeks);

players[share.txid] = null;

var ads = share.settings.ads;

var urlWrapper = el.share[share.txid].find('.url');

renders.url(urlWrapper, ads, share, function(){

renders.urlContent(share, function(){

if(!video) actions.initVideoLight(share, null, null, true);

if(isotopeinited) el.shares.isotope()

shareInitingMap[share.txid] = false;

urlWrapper.find('.skip-ads').on('click', function(){

players[share.txid] = null;

var id = el.share[share.txid].attr('id');

actions.exitFullScreenVideo(id);

renders.url(urlWrapper, share.url, share, function(){

renders.urlContent(share, function(){

if(!video) actions.initVideoLight(share, null, null, true);

if(isotopeinited) el.shares.isotope()

shareInitingMap[share.txid] = false;

initVideoClbk();

});

})
})

}

initVideoClbk(true);

});

}, ads)

} else {

if (clbk)
clbk()
initVideoClbk();
}

})

})

},

Expand Down Expand Up @@ -3254,7 +3368,6 @@ var lenta = (function(){

promises.push(new Promise((resolve, reject) => {


renders.url(p.el.find('.url'), share.url, share, function(){

renders.urlContent(share, function(){
Expand Down Expand Up @@ -3606,6 +3719,8 @@ var lenta = (function(){

shares : function(shares, clbk, p){

console.log('shares', shares);

if(!p) p = {};


Expand Down Expand Up @@ -3954,7 +4069,12 @@ var lenta = (function(){
}
},

url : function(el, url, share, clbk){
url : function(el, url, share, clbk, ads){

// debugger;

// url = 'peertube://peertube6new.pocketnet.app/8acd9ab2-2159-476e-be14-a2ba4aaeb655';
// share.url = 'peertube://peertube6new.pocketnet.app/8acd9ab2-2159-476e-be14-a2ba4aaeb655';

if (essenseData.nourlload){

Expand All @@ -3978,8 +4098,9 @@ var lenta = (function(){
el : el,
mid : 'sharelenta',
data : {
url : url,
url : ads || url,
og : og,
ads: ads,
share : share,
video : video,
preview : video ? true : false,
Expand All @@ -3994,6 +4115,7 @@ var lenta = (function(){

}, function(_p){


var images = _p.el.find('img');

self.app.nav.api.links(null, _p.el, function(event){
Expand Down
Loading