@ -30,6 +30,7 @@ import appImManager from '../lib/appManagers/appImManager';
import { SearchSuperContext } from './appSearchSuper.' ;
import { SearchSuperContext } from './appSearchSuper.' ;
import rootScope from '../lib/rootScope' ;
import rootScope from '../lib/rootScope' ;
import { onVideoLoad } from '../helpers/files' ;
import { onVideoLoad } from '../helpers/files' ;
import { animateSingle } from '../helpers/animation' ;
const MAX_VIDEO_AUTOPLAY_SIZE = 50 * 1024 * 1024 ; // 50 MB
const MAX_VIDEO_AUTOPLAY_SIZE = 50 * 1024 * 1024 ; // 50 MB
@ -55,7 +56,6 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
let spanTime : HTMLElement ;
let spanTime : HTMLElement ;
if ( ! noInfo ) {
if ( ! noInfo ) {
if ( doc . type !== 'round' ) {
spanTime = document . createElement ( 'span' ) ;
spanTime = document . createElement ( 'span' ) ;
spanTime . classList . add ( 'video-time' ) ;
spanTime . classList . add ( 'video-time' ) ;
container . append ( spanTime ) ;
container . append ( spanTime ) ;
@ -63,7 +63,7 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
if ( doc . type !== 'gif' ) {
if ( doc . type !== 'gif' ) {
spanTime . innerText = ( doc . duration + '' ) . toHHMMSS ( false ) ;
spanTime . innerText = ( doc . duration + '' ) . toHHMMSS ( false ) ;
if ( ! noPlayButton ) {
if ( ! noPlayButton && doc . type !== 'round' ) {
if ( canAutoplay ) {
if ( canAutoplay ) {
spanTime . classList . add ( 'tgico' , 'can-autoplay' ) ;
spanTime . classList . add ( 'tgico' , 'can-autoplay' ) ;
} else {
} else {
@ -76,7 +76,6 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
spanTime . innerText = 'GIF' ;
spanTime . innerText = 'GIF' ;
}
}
}
}
}
let res : {
let res : {
thumb? : typeof photoRes ,
thumb? : typeof photoRes ,
@ -108,80 +107,110 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
video . remove ( ) ;
video . remove ( ) ;
} * /
} * /
const video = /* doc.type === 'round' ? appMediaPlaybackController.addMedia(message.peerId, doc, message.mid) as HTMLVideoElement : */ document . createElement ( 'video' ) ;
const video = document . createElement ( 'video' ) ;
video . classList . add ( 'media-video' ) ;
video . classList . add ( 'media-video' ) ;
video . muted = true ;
video . setAttribute ( 'playsinline' , 'true' ) ;
video . setAttribute ( 'playsinline' , 'true' ) ;
video . muted = true ;
if ( doc . type === 'round' ) {
if ( doc . type === 'round' ) {
//video.classList.add('z-depth-1');
const globalVideo = appMediaPlaybackController . addMedia ( message . peerId , doc , message . mid ) as HTMLVideoElement ;
const globalVideo = appMediaPlaybackController . addMedia ( message . peerId , doc , message . mid ) ;
video . classList . add ( 'z-depth-1' ) ;
const divRound = document . createElement ( 'div' ) ;
divRound . classList . add ( 'media-round' , 'z-depth-1' ) ;
onVideoLoad ( video ) . then ( ( ) = > {
divRound . innerHTML = ` <svg class="progress-ring" width="200px" height="200px">
if ( globalVideo . currentTime !== globalVideo . duration ) {
< circle class = "progress-ring__circle" stroke = "white" stroke - opacity = "0.3" stroke - width = "3.5" cx = "100" cy = "100" r = "93" fill = "transparent" transform = "rotate(-90, 100, 100)" / >
video . currentTime = globalVideo . currentTime ;
< / svg > ` ;
}
const circle = divRound . querySelector ( '.progress-ring__circle' ) as SVGCircleElement ;
const radius = circle . r . baseVal . value ;
const circumference = 2 * Math . PI * radius ;
circle . style . strokeDasharray = circumference + ' ' + circumference ;
circle . style . strokeDashoffset = '' + circumference ;
spanTime . classList . add ( 'tgico' ) ;
const canvas = document . createElement ( 'canvas' ) ;
canvas . width = canvas . height = doc . w /* * window.devicePixelRatio */ ;
divRound . prepend ( canvas , spanTime ) ;
container . append ( divRound ) ;
const ctx = canvas . getContext ( '2d' ) ;
/ * c t x . b e g i n P a t h ( ) ;
ctx . arc ( canvas . width / 2 , canvas . height / 2 , canvas . width / 2 , 0 , Math . PI * 2 ) ;
ctx . clip ( ) ; * /
if ( ! globalVideo . paused ) {
const clear = ( ) = > {
// с закоментированными настройками - хром выключал видео при скролле, для этого нужно было включить видео - выйти из диалога, зайти заново и проскроллить вверх
( appImManager . chat . setPeerPromise || Promise . resolve ( ) ) . finally ( ( ) = > {
//video.autoplay = true;
if ( isInDOM ( globalVideo ) ) {
//video.loop = false;
return ;
video . play ( ) ;
}
}
globalVideo . removeEventListener ( 'play' , onPlay ) ;
globalVideo . removeEventListener ( 'timeupdate' , onTimeUpdate ) ;
globalVideo . removeEventListener ( 'pause' , onPaused ) ;
} ) ;
} ) ;
} ;
const clear = ( ) = > {
const onFrame = ( ) = > {
//console.log('clearing video');
ctx . drawImage ( globalVideo , 0 , 0 ) ;
const offset = circumference - globalVideo . currentTime / globalVideo . duration * circumference ;
circle . style . strokeDashoffset = '' + offset ;
globalVideo . removeEventListener ( 'timeupdate' , onGlobalTimeUpdate ) ;
return ! globalVideo . paused ;
globalVideo . removeEventListener ( 'play' , onGlobalPlay ) ;
globalVideo . removeEventListener ( 'pause' , onGlobalPause ) ;
video . removeEventListener ( 'play' , onVideoPlay ) ;
video . removeEventListener ( 'pause' , onVideoPause ) ;
} ;
} ;
const onGlobalTimeUpdate = ( e : Event ) = > {
const onTimeUpdate = ( ) = > {
//console.log('video global timeupdate event', e, globalVideo.currentTime, globalVideo.duration);
if ( ! globalVideo . duration ) return ;
if ( ! isInDOM ( video ) ) {
if ( ! isInDOM ( globalVideo ) ) {
clear ( ) ;
clear ( ) ;
return ;
}
}
spanTime . innerText = ( globalVideo . duration - globalVideo . currentTime + '' ) . toHHMMSS ( false ) ;
} ;
} ;
const onGlobalPlay = ( e : Event ) = > {
const onPlay = ( ) = > {
//console.log('video global play event', e);
video . remove ( ) ;
video . play ( ) ;
divRound . classList . remove ( 'is-paused' ) ;
animateSingle ( onFrame , canvas ) ;
} ;
} ;
const onGlobalPause = ( e : Event ) = > {
const onPaused = ( ) = > {
//console.trace('video global pause event', e, globalVideo.paused, e.eventPhase);
if ( ! isInDOM ( globalVideo ) ) {
video . pause ( ) ;
clear ( ) ;
return ;
}
divRound . classList . add ( 'is-paused' ) ;
} ;
} ;
const onVideoPlay = ( e : Event ) = > {
globalVideo . addEventListener ( 'play' , onPlay ) ;
//console.log('video play event', e);
globalVideo . addEventListener ( 'timeupdate' , onTimeUpdate ) ;
globalVideo . addEventListener ( 'pause' , onPaused ) ;
attachClickEvent ( canvas , ( e ) = > {
cancelEvent ( e ) ;
if ( globalVideo . paused ) {
if ( globalVideo . paused ) {
globalVideo . currentTime = video . currentTime ;
globalVideo . play ( ) ;
globalVideo . play ( ) ;
} else {
globalVideo . pause ( ) ;
}
}
} ;
} ) ;
// * this will fire when video unmounts
if ( globalVideo . paused ) {
const onVideoPause = ( e : Event ) = > {
if ( globalVideo . duration && globalVideo . currentTime !== globalVideo . duration ) {
//console.trace('video pause event', e);
onFrame ( ) ;
if ( isInDOM ( video ) ) {
onTimeUpdate ( ) ;
globalVideo . pause ( ) ;
globalVideo . currentTime = video . currentTime ;
} else {
} else {
clear ( ) ;
onPaused ( ) ;
}
} else {
onPlay ( ) ;
}
}
} ;
globalVideo . addEventListener ( 'timeupdate' , onGlobalTimeUpdate ) ;
globalVideo . addEventListener ( 'play' , onGlobalPlay ) ;
globalVideo . addEventListener ( 'pause' , onGlobalPause ) ;
video . addEventListener ( 'play' , onVideoPlay ) ;
video . addEventListener ( 'pause' , onVideoPause ) ;
} else {
} else {
video . autoplay = true ; // для safari
video . autoplay = true ; // для safari
}
}
@ -276,7 +305,7 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
/ * i f ( ! v i d e o . p a u s e d ) {
/ * i f ( ! v i d e o . p a u s e d ) {
video . pause ( ) ;
video . pause ( ) ;
} * /
} * /
if ( doc . type !== 'round' && group ) {
if ( group ) {
animationIntersector . addAnimation ( video , group ) ;
animationIntersector . addAnimation ( video , group ) ;
}
}
@ -297,24 +326,16 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
deferred . resolve ( ) ;
deferred . resolve ( ) ;
} ) ;
} ) ;
if ( doc . type !== 'round' ) {
video . muted = true ;
video . muted = true ;
video . loop = true ;
video . loop = true ;
//video.play();
//video.play();
video . autoplay = true ;
video . autoplay = true ;
}
renderImageFromUrl ( video , doc . url ) ;
renderImageFromUrl ( video , doc . url ) ;
return Promise . all ( [ loadPromise , deferred ] ) ;
return Promise . all ( [ loadPromise , deferred ] ) ;
} ;
} ;
if ( doc . type === 'round' ) {
video . dataset . ckin = 'circle' ;
video . dataset . overlay = '1' ;
new VideoPlayer ( video , undefined , undefined , doc . duration ) ;
}
/ * i f ( d o c . s i z e > = 2 0 e 6 & & ! d o c . d o w n l o a d e d ) {
/ * i f ( d o c . s i z e > = 2 0 e 6 & & ! d o c . d o w n l o a d e d ) {
let downloadDiv = document . createElement ( 'div' ) ;
let downloadDiv = document . createElement ( 'div' ) ;
downloadDiv . classList . add ( 'download' ) ;
downloadDiv . classList . add ( 'download' ) ;