@ -30,6 +30,7 @@ import appImManager from '../lib/appManagers/appImManager';
@@ -30,6 +30,7 @@ import appImManager from '../lib/appManagers/appImManager';
import { SearchSuperContext } from './appSearchSuper.' ;
import rootScope from '../lib/rootScope' ;
import { onVideoLoad } from '../helpers/files' ;
import { animateSingle } from '../helpers/animation' ;
const MAX_VIDEO_AUTOPLAY_SIZE = 50 * 1024 * 1024 ; // 50 MB
@ -55,7 +56,6 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
@@ -55,7 +56,6 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
let spanTime : HTMLElement ;
if ( ! noInfo ) {
if ( doc . type !== 'round' ) {
spanTime = document . createElement ( 'span' ) ;
spanTime . classList . add ( 'video-time' ) ;
container . append ( spanTime ) ;
@ -63,7 +63,7 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
@@ -63,7 +63,7 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
if ( doc . type !== 'gif' ) {
spanTime . innerText = ( doc . duration + '' ) . toHHMMSS ( false ) ;
if ( ! noPlayButton ) {
if ( ! noPlayButton && doc . type !== 'round' ) {
if ( canAutoplay ) {
spanTime . classList . add ( 'tgico' , 'can-autoplay' ) ;
} else {
@ -76,7 +76,6 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
@@ -76,7 +76,6 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
spanTime . innerText = 'GIF' ;
}
}
}
let res : {
thumb? : typeof photoRes ,
@ -108,80 +107,110 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
@@ -108,80 +107,110 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
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 . muted = true ;
video . setAttribute ( 'playsinline' , 'true' ) ;
video . muted = true ;
if ( doc . type === 'round' ) {
//video.classList.add('z-depth-1');
const globalVideo = appMediaPlaybackController . addMedia ( message . peerId , doc , message . mid ) ;
const globalVideo = appMediaPlaybackController . addMedia ( message . peerId , doc , message . mid ) as HTMLVideoElement ;
video . classList . add ( 'z-depth-1' ) ;
const divRound = document . createElement ( 'div' ) ;
divRound . classList . add ( 'media-round' , 'z-depth-1' ) ;
onVideoLoad ( video ) . then ( ( ) = > {
if ( globalVideo . currentTime !== globalVideo . duration ) {
video . currentTime = globalVideo . currentTime ;
}
divRound . innerHTML = ` <svg class="progress-ring" width="200px" height="200px">
< 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)" / >
< / 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 ) {
// с закоментированными настройками - хром выключал видео при скролле, для этого нужно было включить видео - выйти из диалога, зайти заново и проскроллить вверх
//video.autoplay = true;
//video.loop = false;
video . play ( ) ;
const clear = ( ) = > {
( appImManager . chat . setPeerPromise || Promise . resolve ( ) ) . finally ( ( ) = > {
if ( isInDOM ( globalVideo ) ) {
return ;
}
globalVideo . removeEventListener ( 'play' , onPlay ) ;
globalVideo . removeEventListener ( 'timeupdate' , onTimeUpdate ) ;
globalVideo . removeEventListener ( 'pause' , onPaused ) ;
} ) ;
} ;
const clear = ( ) = > {
//console.log('clearing video');
const onFrame = ( ) = > {
ctx . drawImage ( globalVideo , 0 , 0 ) ;
const offset = circumference - globalVideo . currentTime / globalVideo . duration * circumference ;
circle . style . strokeDashoffset = '' + offset ;
globalVideo . removeEventListener ( 'timeupdate' , onGlobalTimeUpdate ) ;
globalVideo . removeEventListener ( 'play' , onGlobalPlay ) ;
globalVideo . removeEventListener ( 'pause' , onGlobalPause ) ;
video . removeEventListener ( 'play' , onVideoPlay ) ;
video . removeEventListener ( 'pause' , onVideoPause ) ;
return ! globalVideo . paused ;
} ;
const onGlobalTimeUpdate = ( e : Event ) = > {
//console.log('video global timeupdate event', e, globalVideo.currentTime, globalVideo.duration);
if ( ! isInDOM ( video ) ) {
const onTimeUpdate = ( ) = > {
if ( ! globalVideo . duration ) return ;
if ( ! isInDOM ( globalVideo ) ) {
clear ( ) ;
return ;
}
spanTime . innerText = ( globalVideo . duration - globalVideo . currentTime + '' ) . toHHMMSS ( false ) ;
} ;
const onGlobalPlay = ( e : Event ) = > {
//console.log('video global play event', e);
video . play ( ) ;
const onPlay = ( ) = > {
video . remove ( ) ;
divRound . classList . remove ( 'is-paused' ) ;
animateSingle ( onFrame , canvas ) ;
} ;
const onGlobalPause = ( e : Event ) = > {
//console.trace('video global pause event', e, globalVideo.paused, e.eventPhase);
video . pause ( ) ;
const onPaused = ( ) = > {
if ( ! isInDOM ( globalVideo ) ) {
clear ( ) ;
return ;
}
divRound . classList . add ( 'is-paused' ) ;
} ;
const onVideoPlay = ( e : Event ) = > {
//console.log('video play event', e);
globalVideo . addEventListener ( 'play' , onPlay ) ;
globalVideo . addEventListener ( 'timeupdate' , onTimeUpdate ) ;
globalVideo . addEventListener ( 'pause' , onPaused ) ;
attachClickEvent ( canvas , ( e ) = > {
cancelEvent ( e ) ;
if ( globalVideo . paused ) {
globalVideo . currentTime = video . currentTime ;
globalVideo . play ( ) ;
} else {
globalVideo . pause ( ) ;
}
} ;
} ) ;
// * this will fire when video unmounts
const onVideoPause = ( e : Event ) = > {
//console.trace('video pause event', e);
if ( isInDOM ( video ) ) {
globalVideo . pause ( ) ;
globalVideo . currentTime = video . currentTime ;
if ( globalVideo . paused ) {
if ( globalVideo . duration && globalVideo . currentTime !== globalVideo . duration ) {
onFrame ( ) ;
onTimeUpdate ( ) ;
} 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 {
video . autoplay = true ; // для safari
}
@ -276,7 +305,7 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
@@ -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 ) {
video . pause ( ) ;
} * /
if ( doc . type !== 'round' && group ) {
if ( group ) {
animationIntersector . addAnimation ( video , group ) ;
}
@ -297,24 +326,16 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
@@ -297,24 +326,16 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
deferred . resolve ( ) ;
} ) ;
if ( doc . type !== 'round' ) {
video . muted = true ;
video . loop = true ;
//video.play();
video . autoplay = true ;
}
renderImageFromUrl ( video , doc . url ) ;
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 ) {
let downloadDiv = document . createElement ( 'div' ) ;
downloadDiv . classList . add ( 'download' ) ;