@ -1,3 +1,4 @@
import type Chat from './chat/chat' ;
import { getEmojiToneIndex } from '../emoji' ;
import { getEmojiToneIndex } from '../emoji' ;
import { readBlobAsText } from '../helpers/blob' ;
import { readBlobAsText } from '../helpers/blob' ;
import { deferredPromise } from '../helpers/cancellablePromise' ;
import { deferredPromise } from '../helpers/cancellablePromise' ;
@ -7,7 +8,6 @@ import { formatBytes } from '../helpers/number';
import { isAppleMobile , isSafari } from '../helpers/userAgent' ;
import { isAppleMobile , isSafari } from '../helpers/userAgent' ;
import { PhotoSize } from '../layer' ;
import { PhotoSize } from '../layer' ;
import appDocsManager , { MyDocument } from "../lib/appManagers/appDocsManager" ;
import appDocsManager , { MyDocument } from "../lib/appManagers/appDocsManager" ;
import { DownloadBlob } from '../lib/appManagers/appDownloadManager' ;
import appMessagesManager from '../lib/appManagers/appMessagesManager' ;
import appMessagesManager from '../lib/appManagers/appMessagesManager' ;
import appPhotosManager , { MyPhoto } from '../lib/appManagers/appPhotosManager' ;
import appPhotosManager , { MyPhoto } from '../lib/appManagers/appPhotosManager' ;
import LottieLoader from '../lib/lottieLoader' ;
import LottieLoader from '../lib/lottieLoader' ;
@ -27,9 +27,9 @@ import './middleEllipsis';
import { nextRandomInt } from '../helpers/random' ;
import { nextRandomInt } from '../helpers/random' ;
import RichTextProcessor from '../lib/richtextprocessor' ;
import RichTextProcessor from '../lib/richtextprocessor' ;
import appImManager from '../lib/appManagers/appImManager' ;
import appImManager from '../lib/appManagers/appImManager' ;
import Chat from './chat/chat' ;
import { SearchSuperContext } from './appSearchSuper.' ;
import { SearchSuperContext } from './appSearchSuper.' ;
import rootScope from '../lib/rootScope' ;
import rootScope from '../lib/rootScope' ;
import { onVideoLoad } from '../helpers/files' ;
const MAX_VIDEO_AUTOPLAY_SIZE = 50 * 1024 * 1024 ; // 50 MB
const MAX_VIDEO_AUTOPLAY_SIZE = 50 * 1024 * 1024 ; // 50 MB
@ -108,28 +108,28 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
video . remove ( ) ;
video . remove ( ) ;
} * /
} * /
const video = document . createElement ( 'video' ) ;
const video = /* doc.type === 'round' ? appMediaPlaybackController.addMedia(message.peerId, doc, message.mid) as HTMLVideoElement : */ document . createElement ( 'video' ) ;
video . classList . add ( 'media-video' ) ;
video . classList . add ( 'media-video' ) ;
video . muted = true ;
video . muted = true ;
video . setAttribute ( 'playsinline' , 'true' ) ;
video . setAttribute ( 'playsinline' , 'true' ) ;
if ( doc . type === 'round' ) {
if ( doc . type === 'round' ) {
//video.muted = true ;
//video.classList.add('z-depth-1') ;
const globalVideo = appMediaPlaybackController . addMedia ( message . peerId , doc , message . mid ) ;
const globalVideo = appMediaPlaybackController . addMedia ( message . peerId , doc , message . mid ) ;
video . classList . add ( 'z-depth-1' ) ;
video . classList . add ( 'z-depth-1' ) ;
video . addEventListener ( 'canplay' , ( ) = > {
onVideoLoad ( video ) . then ( ( ) = > {
if ( globalVideo . currentTime > 0 ) {
if ( globalVideo . currentTime !== globalVideo . duration ) {
video . currentTime = globalVideo . currentTime ;
video . currentTime = globalVideo . currentTime ;
}
}
if ( ! globalVideo . paused ) {
if ( ! globalVideo . paused ) {
// с закоментированными настройками - хром выключал видео при скролле, для этого нужно было включить видео - выйти из диалога, зайти заново и проскроллить вверх
// с закоментированными настройками - хром выключал видео при скролле, для этого нужно было включить видео - выйти из диалога, зайти заново и проскроллить вверх
/ * v i d e o . a u t o p l a y = t r u e ;
//video.autoplay = true;
video . loop = false ; * /
//video.loop = false;
video . play ( ) ;
video . play ( ) ;
}
}
} , { once : true } ) ;
} ) ;
const clear = ( ) = > {
const clear = ( ) = > {
//console.log('clearing video');
//console.log('clearing video');
@ -160,14 +160,18 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
const onVideoPlay = ( e : Event ) = > {
const onVideoPlay = ( e : Event ) = > {
//console.log('video play event', e);
//console.log('video play event', e);
globalVideo . currentTime = video . currentTime ;
if ( globalVideo . paused ) {
globalVideo . play ( ) ;
globalVideo . currentTime = video . currentTime ;
globalVideo . play ( ) ;
}
} ;
} ;
// * this will fire when video unmounts
const onVideoPause = ( e : Event ) = > {
const onVideoPause = ( e : Event ) = > {
//console.trace('video pause event', e);
//console.trace('video pause event', e);
if ( isInDOM ( video ) ) {
if ( isInDOM ( video ) ) {
globalVideo . pause ( ) ;
globalVideo . pause ( ) ;
globalVideo . currentTime = video . currentTime ;
} else {
} else {
clear ( ) ;
clear ( ) ;
}
}
@ -229,22 +233,25 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
return ;
return ;
}
}
let loadPromise : Promise < any > = Promise . resolve ( ) ;
let preloader : ProgressivePreloader ;
let preloader : ProgressivePreloader ;
if ( message ? . media ? . preloader ) { // means upload
if ( message ? . media ? . preloader ) { // means upload
preloader = message . media . preloader as ProgressivePreloader ;
preloader = message . media . preloader as ProgressivePreloader ;
preloader . attach ( container , false ) ;
preloader . attach ( container , false ) ;
} else if ( ! doc . downloaded && ! doc . supportsStreaming ) {
} else if ( ! doc . downloaded && ! doc . supportsStreaming ) {
const promise = appDocsManager . downloadDoc ( doc , lazyLoadQueue ? . queueId ) ;
const promise = loadPromise = appDocsManager . downloadDoc ( doc , lazyLoadQueue ? . queueId ) ;
preloader = new ProgressivePreloader ( {
preloader = new ProgressivePreloader ( {
attachMethod : 'prepend'
attachMethod : 'prepend'
} ) ;
} ) ;
preloader . attach ( container , true , promise ) ;
preloader . attach ( container , true , promise ) ;
await promise ;
//if(doc.type !== 'round') {
await promise ;
if ( middleware && ! middleware ( ) ) {
if ( middleware && ! middleware ( ) ) {
return ;
return ;
}
}
//}
} else if ( doc . supportsStreaming ) {
} else if ( doc . supportsStreaming ) {
preloader = new ProgressivePreloader ( {
preloader = new ProgressivePreloader ( {
cancelable : false ,
cancelable : false ,
@ -256,12 +263,16 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
} , { once : true } ) ;
} , { once : true } ) ;
}
}
/ * i f ( d o c . t y p e = = = ' r o u n d ' ) {
return ;
} * /
//console.log('loaded doc:', doc, doc.url, container);
//console.log('loaded doc:', doc, doc.url, container);
const deferred = deferredPromise < void > ( ) ;
const deferred = deferredPromise < void > ( ) ;
//if(doc.type == 'gif'/* || true */) {
//if(doc.type == 'gif'/* || true */) {
video . addEventListener ( isAppleMobile ? 'loadeddata' : 'canplay' , ( ) = > {
onVideoLoad ( video ) . then ( ( ) = > {
/ * 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 ( ) ;
} * /
} * /
@ -273,7 +284,7 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
//setTimeout(() => {
//setTimeout(() => {
deferred . resolve ( ) ;
deferred . resolve ( ) ;
//}, 5000);
//}, 5000);
} , { once : true } ) ;
} ) ;
//}
//}
if ( doc . type === 'video' ) {
if ( doc . type === 'video' ) {
@ -286,22 +297,24 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
deferred . resolve ( ) ;
deferred . resolve ( ) ;
} ) ;
} ) ;
renderImageFromUrl ( video , doc . url ) ;
if ( doc . type !== 'round' ) {
if ( doc . type === 'round' ) {
video . dataset . ckin = 'circle' ;
video . dataset . overlay = '1' ;
new VideoPlayer ( video ) ;
} else {
video . muted = true ;
video . muted = true ;
video . loop = true ;
video . loop = true ;
//video.play();
//video.play();
video . autoplay = true ;
video . autoplay = true ;
}
}
return deferred ;
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 ) {
/ * 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' ) ;