Video: Notify user on unsupported formats (#3706)
This commit is contained in:
parent
aa120959e6
commit
e367d82c6c
@ -48,7 +48,6 @@ import {
|
|||||||
SUPPORTED_AUDIO_CONTENT_TYPES,
|
SUPPORTED_AUDIO_CONTENT_TYPES,
|
||||||
SUPPORTED_IMAGE_CONTENT_TYPES,
|
SUPPORTED_IMAGE_CONTENT_TYPES,
|
||||||
SUPPORTED_VIDEO_CONTENT_TYPES,
|
SUPPORTED_VIDEO_CONTENT_TYPES,
|
||||||
VIDEO_MOV_TYPE,
|
|
||||||
VIDEO_WEBM_TYPE,
|
VIDEO_WEBM_TYPE,
|
||||||
} from '../../../config';
|
} from '../../../config';
|
||||||
import { pick } from '../../../util/iteratees';
|
import { pick } from '../../../util/iteratees';
|
||||||
@ -484,11 +483,6 @@ export function buildVideoFromDocument(document: GramJs.Document, isSpoiler?: bo
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-restricted-globals
|
|
||||||
if (mimeType === VIDEO_MOV_TYPE && !(self as any).isMovSupported) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const videoAttr = attributes
|
const videoAttr = attributes
|
||||||
.find((a: any): a is GramJs.DocumentAttributeVideo => a instanceof GramJs.DocumentAttributeVideo);
|
.find((a: any): a is GramJs.DocumentAttributeVideo => a instanceof GramJs.DocumentAttributeVideo);
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import type {
|
|||||||
} from '../../types';
|
} from '../../types';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DEBUG, DEBUG_GRAMJS, UPLOAD_WORKERS, IS_TEST, SUPPORTED_VIDEO_CONTENT_TYPES, VIDEO_MOV_TYPE,
|
DEBUG, DEBUG_GRAMJS, UPLOAD_WORKERS, IS_TEST,
|
||||||
} from '../../../config';
|
} from '../../../config';
|
||||||
import {
|
import {
|
||||||
onRequestPhoneNumber, onRequestCode, onRequestPassword, onRequestRegistration,
|
onRequestPhoneNumber, onRequestCode, onRequestPassword, onRequestRegistration,
|
||||||
@ -64,16 +64,12 @@ export async function init(_onUpdate: OnApiUpdate, initialArgs: ApiInitialArgs)
|
|||||||
onUpdate = _onUpdate;
|
onUpdate = _onUpdate;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
userAgent, platform, sessionData, isTest, isMovSupported, isWebmSupported, maxBufferSize, webAuthToken, dcId,
|
userAgent, platform, sessionData, isTest, isWebmSupported, maxBufferSize, webAuthToken, dcId,
|
||||||
mockScenario, shouldForceHttpTransport, shouldAllowHttpTransport,
|
mockScenario, shouldForceHttpTransport, shouldAllowHttpTransport,
|
||||||
shouldDebugExportedSenders,
|
shouldDebugExportedSenders,
|
||||||
} = initialArgs;
|
} = initialArgs;
|
||||||
const session = new sessions.CallbackSession(sessionData, onSessionUpdate);
|
const session = new sessions.CallbackSession(sessionData, onSessionUpdate);
|
||||||
|
|
||||||
// eslint-disable-next-line no-restricted-globals
|
|
||||||
(self as any).isMovSupported = isMovSupported;
|
|
||||||
// Hacky way to update this set inside GramJS worker
|
|
||||||
if (isMovSupported) SUPPORTED_VIDEO_CONTENT_TYPES.add(VIDEO_MOV_TYPE);
|
|
||||||
// eslint-disable-next-line no-restricted-globals
|
// eslint-disable-next-line no-restricted-globals
|
||||||
(self as any).isWebmSupported = isWebmSupported;
|
(self as any).isWebmSupported = isWebmSupported;
|
||||||
// eslint-disable-next-line no-restricted-globals
|
// eslint-disable-next-line no-restricted-globals
|
||||||
|
|||||||
@ -7,7 +7,6 @@ export interface ApiInitialArgs {
|
|||||||
platform?: string;
|
platform?: string;
|
||||||
sessionData?: ApiSessionData;
|
sessionData?: ApiSessionData;
|
||||||
isTest?: boolean;
|
isTest?: boolean;
|
||||||
isMovSupported?: boolean;
|
|
||||||
isWebmSupported?: boolean;
|
isWebmSupported?: boolean;
|
||||||
maxBufferSize?: number;
|
maxBufferSize?: number;
|
||||||
webAuthToken?: string;
|
webAuthToken?: string;
|
||||||
@ -112,6 +111,7 @@ export type ApiNotification = {
|
|||||||
actionText?: string;
|
actionText?: string;
|
||||||
action?: CallbackAction;
|
action?: CallbackAction;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
duration?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ApiError = {
|
export type ApiError = {
|
||||||
|
|||||||
@ -24,13 +24,14 @@ const Notifications: FC<StateProps> = ({ notifications }) => {
|
|||||||
return (
|
return (
|
||||||
<div id="Notifications">
|
<div id="Notifications">
|
||||||
{notifications.map(({
|
{notifications.map(({
|
||||||
message, className, localId, action, actionText, title,
|
message, className, localId, action, actionText, title, duration,
|
||||||
}) => (
|
}) => (
|
||||||
<Notification
|
<Notification
|
||||||
title={title ? renderText(title, ['simple_markdown', 'emoji', 'br', 'links']) : undefined}
|
title={title ? renderText(title, ['simple_markdown', 'emoji', 'br', 'links']) : undefined}
|
||||||
action={action}
|
action={action}
|
||||||
actionText={actionText}
|
actionText={actionText}
|
||||||
className={className}
|
className={className}
|
||||||
|
duration={duration}
|
||||||
message={renderText(message, ['simple_markdown', 'emoji', 'br', 'links'])}
|
message={renderText(message, ['simple_markdown', 'emoji', 'br', 'links'])}
|
||||||
// eslint-disable-next-line react/jsx-no-bind
|
// eslint-disable-next-line react/jsx-no-bind
|
||||||
onDismiss={() => dismissNotification({ localId })}
|
onDismiss={() => dismissNotification({ localId })}
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import useAppLayout from '../../hooks/useAppLayout';
|
|||||||
import useCurrentTimeSignal from './hooks/useCurrentTimeSignal';
|
import useCurrentTimeSignal from './hooks/useCurrentTimeSignal';
|
||||||
import useControlsSignal from './hooks/useControlsSignal';
|
import useControlsSignal from './hooks/useControlsSignal';
|
||||||
import useVideoWaitingSignal from './hooks/useVideoWaitingSignal';
|
import useVideoWaitingSignal from './hooks/useVideoWaitingSignal';
|
||||||
|
import useUnsupportedMedia from '../../hooks/media/useUnsupportedMedia';
|
||||||
|
|
||||||
import Button from '../ui/Button';
|
import Button from '../ui/Button';
|
||||||
import ProgressSpinner from '../ui/ProgressSpinner';
|
import ProgressSpinner from '../ui/ProgressSpinner';
|
||||||
@ -120,22 +121,23 @@ const VideoPlayer: FC<OwnProps> = ({
|
|||||||
const {
|
const {
|
||||||
isReady, isBuffered, bufferedRanges, bufferingHandlers, bufferedProgress,
|
isReady, isBuffered, bufferedRanges, bufferingHandlers, bufferedProgress,
|
||||||
} = useBuffering();
|
} = useBuffering();
|
||||||
|
const isUnsupported = useUnsupportedMedia(videoRef, undefined, !url);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
shouldRender: shouldRenderSpinner,
|
shouldRender: shouldRenderSpinner,
|
||||||
transitionClassNames: spinnerClassNames,
|
transitionClassNames: spinnerClassNames,
|
||||||
} = useShowTransition(!isBuffered, undefined, undefined, 'slow');
|
} = useShowTransition(!isBuffered && !isUnsupported, undefined, undefined, 'slow');
|
||||||
const {
|
const {
|
||||||
shouldRender: shouldRenderPlayButton,
|
shouldRender: shouldRenderPlayButton,
|
||||||
transitionClassNames: playButtonClassNames,
|
transitionClassNames: playButtonClassNames,
|
||||||
} = useShowTransition(IS_IOS && !isPlaying && !shouldRenderSpinner, undefined, undefined, 'slow');
|
} = useShowTransition(IS_IOS && !isPlaying && !shouldRenderSpinner && !isUnsupported, undefined, undefined, 'slow');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
lockControls(shouldRenderSpinner);
|
lockControls(shouldRenderSpinner);
|
||||||
}, [lockControls, shouldRenderSpinner]);
|
}, [lockControls, shouldRenderSpinner]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (noPlay || !isMediaViewerOpen) {
|
if (noPlay || !isMediaViewerOpen || isUnsupported) {
|
||||||
videoRef.current!.pause();
|
videoRef.current!.pause();
|
||||||
} else if (url && !IS_TOUCH_ENV) {
|
} else if (url && !IS_TOUCH_ENV) {
|
||||||
// Chrome does not automatically start playing when `url` becomes available (even with `autoPlay`),
|
// Chrome does not automatically start playing when `url` becomes available (even with `autoPlay`),
|
||||||
@ -143,7 +145,7 @@ const VideoPlayer: FC<OwnProps> = ({
|
|||||||
// so we need to use `autoPlay` instead to allow pre-buffering.
|
// so we need to use `autoPlay` instead to allow pre-buffering.
|
||||||
safePlay(videoRef.current!);
|
safePlay(videoRef.current!);
|
||||||
}
|
}
|
||||||
}, [noPlay, isMediaViewerOpen, url, setMediaViewerMuted]);
|
}, [noPlay, isMediaViewerOpen, url, setMediaViewerMuted, isUnsupported]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
videoRef.current!.volume = volume;
|
videoRef.current!.volume = volume;
|
||||||
@ -307,9 +309,8 @@ const VideoPlayer: FC<OwnProps> = ({
|
|||||||
bufferingHandlers.onPause(e);
|
bufferingHandlers.onPause(e);
|
||||||
}}
|
}}
|
||||||
onTimeUpdate={handleTimeUpdate}
|
onTimeUpdate={handleTimeUpdate}
|
||||||
>
|
src={url}
|
||||||
{url && <source src={url} />}
|
/>
|
||||||
</video>
|
|
||||||
</div>
|
</div>
|
||||||
{shouldRenderPlayButton && (
|
{shouldRenderPlayButton && (
|
||||||
<Button round className={`play-button ${playButtonClassNames}`} onClick={togglePlayState}>
|
<Button round className={`play-button ${playButtonClassNames}`} onClick={togglePlayState}>
|
||||||
@ -327,7 +328,7 @@ const VideoPlayer: FC<OwnProps> = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{!isGif && (
|
{!isGif && !isUnsupported && (
|
||||||
<VideoPlayerControls
|
<VideoPlayerControls
|
||||||
url={url}
|
url={url}
|
||||||
isPlaying={isPlaying}
|
isPlaying={isPlaying}
|
||||||
|
|||||||
@ -63,11 +63,14 @@ export default async function buildAttachment(
|
|||||||
previewBlobUrl = blobUrl;
|
previewBlobUrl = blobUrl;
|
||||||
}
|
}
|
||||||
} else if (SUPPORTED_VIDEO_CONTENT_TYPES.has(mimeType)) {
|
} else if (SUPPORTED_VIDEO_CONTENT_TYPES.has(mimeType)) {
|
||||||
const { videoWidth: width, videoHeight: height, duration } = await preloadVideo(blobUrl);
|
try {
|
||||||
shouldSendAsFile = !validateAspectRatio(width, height);
|
const { videoWidth: width, videoHeight: height, duration } = await preloadVideo(blobUrl);
|
||||||
|
shouldSendAsFile = !validateAspectRatio(width, height);
|
||||||
if (!shouldSendAsFile) {
|
if (!shouldSendAsFile) {
|
||||||
quick = { width, height, duration };
|
quick = { width: width!, height: height!, duration: duration! };
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
shouldSendAsFile = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
previewBlobUrl = await createPosterForVideo(blobUrl);
|
previewBlobUrl = await createPosterForVideo(blobUrl);
|
||||||
|
|||||||
@ -31,6 +31,7 @@ import useMediaTransition from '../../../hooks/useMediaTransition';
|
|||||||
import useBlurredMediaThumbRef from './hooks/useBlurredMediaThumbRef';
|
import useBlurredMediaThumbRef from './hooks/useBlurredMediaThumbRef';
|
||||||
import useFlag from '../../../hooks/useFlag';
|
import useFlag from '../../../hooks/useFlag';
|
||||||
import useAppLayout from '../../../hooks/useAppLayout';
|
import useAppLayout from '../../../hooks/useAppLayout';
|
||||||
|
import useUnsupportedMedia from '../../../hooks/media/useUnsupportedMedia';
|
||||||
|
|
||||||
import ProgressSpinner from '../../ui/ProgressSpinner';
|
import ProgressSpinner from '../../ui/ProgressSpinner';
|
||||||
import OptimizedVideo from '../../ui/OptimizedVideo';
|
import OptimizedVideo from '../../ui/OptimizedVideo';
|
||||||
@ -121,6 +122,7 @@ const Video: FC<OwnProps> = ({
|
|||||||
|
|
||||||
const isInline = fullMediaData && wasIntersectedRef.current;
|
const isInline = fullMediaData && wasIntersectedRef.current;
|
||||||
|
|
||||||
|
const isUnsupported = useUnsupportedMedia(videoRef, true, !isInline);
|
||||||
const { loadProgress: downloadProgress } = useMediaWithLoadProgress(
|
const { loadProgress: downloadProgress } = useMediaWithLoadProgress(
|
||||||
getMessageMediaHash(message, 'download'),
|
getMessageMediaHash(message, 'download'),
|
||||||
!isDownloading,
|
!isDownloading,
|
||||||
@ -137,7 +139,7 @@ const Video: FC<OwnProps> = ({
|
|||||||
const {
|
const {
|
||||||
shouldRender: shouldRenderSpinner,
|
shouldRender: shouldRenderSpinner,
|
||||||
transitionClassNames: spinnerClassNames,
|
transitionClassNames: spinnerClassNames,
|
||||||
} = useShowTransition(isTransferring, undefined, wasLoadDisabled);
|
} = useShowTransition(isTransferring && !isUnsupported, undefined, wasLoadDisabled);
|
||||||
const {
|
const {
|
||||||
transitionClassNames: playButtonClassNames,
|
transitionClassNames: playButtonClassNames,
|
||||||
} = useShowTransition(Boolean((isLoadAllowed || fullMediaData) && !isPlayAllowed && !shouldRenderSpinner));
|
} = useShowTransition(Boolean((isLoadAllowed || fullMediaData) && !isPlayAllowed && !shouldRenderSpinner));
|
||||||
@ -147,7 +149,7 @@ const Video: FC<OwnProps> = ({
|
|||||||
setPlayProgress(Math.max(0, e.currentTarget.currentTime - 1));
|
setPlayProgress(Math.max(0, e.currentTarget.currentTime - 1));
|
||||||
});
|
});
|
||||||
|
|
||||||
const duration = videoRef.current?.duration || video.duration || 0;
|
const duration = (Number.isFinite(videoRef.current?.duration) ? videoRef.current?.duration : video.duration) || 0;
|
||||||
|
|
||||||
const isOwn = isOwnMessage(message);
|
const isOwn = isOwnMessage(message);
|
||||||
const isWebPageVideo = Boolean(getMessageWebPageVideo(message));
|
const isWebPageVideo = Boolean(getMessageWebPageVideo(message));
|
||||||
@ -206,7 +208,7 @@ const Video: FC<OwnProps> = ({
|
|||||||
ref={videoRef}
|
ref={videoRef}
|
||||||
src={fullMediaData}
|
src={fullMediaData}
|
||||||
className={buildClassName('full-media', withBlurredBackground && 'with-blurred-bg')}
|
className={buildClassName('full-media', withBlurredBackground && 'with-blurred-bg')}
|
||||||
canPlay={isPlayAllowed && isIntersectingForPlaying}
|
canPlay={isPlayAllowed && isIntersectingForPlaying && !isUnsupported}
|
||||||
muted
|
muted
|
||||||
loop
|
loop
|
||||||
playsInline
|
playsInline
|
||||||
@ -247,13 +249,14 @@ const Video: FC<OwnProps> = ({
|
|||||||
{!isLoadAllowed && !fullMediaData && (
|
{!isLoadAllowed && !fullMediaData && (
|
||||||
<i className="icon icon-download" />
|
<i className="icon icon-download" />
|
||||||
)}
|
)}
|
||||||
{isTransferring ? (
|
{isTransferring && (!isUnsupported || isDownloading) ? (
|
||||||
<span className="message-transfer-progress">
|
<span className="message-transfer-progress">
|
||||||
{(isUploading || isDownloading) ? `${Math.round(transferProgress * 100)}%` : '...'}
|
{(isUploading || isDownloading) ? `${Math.round(transferProgress * 100)}%` : '...'}
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<div className="message-media-duration">
|
<div className="message-media-duration">
|
||||||
{video.isGif ? 'GIF' : formatMediaDuration(Math.max(duration - playProgress, 0))}
|
{video.isGif ? 'GIF' : formatMediaDuration(Math.max(duration - playProgress, 0))}
|
||||||
|
{isUnsupported && <i className="icon icon-message-failed playback-failed" />}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -655,6 +655,8 @@
|
|||||||
border-radius: 0.75rem;
|
border-radius: 0.75rem;
|
||||||
line-height: 1.125rem;
|
line-height: 1.125rem;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.message-media-duration .icon-muted {
|
.message-media-duration .icon-muted {
|
||||||
@ -662,6 +664,11 @@
|
|||||||
margin-left: 0.375rem;
|
margin-left: 0.375rem;
|
||||||
font-size: 1.0625rem;
|
font-size: 1.0625rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.message-media-duration .playback-failed {
|
||||||
|
margin-inline-start: 0.125rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.message-content.custom-shape {
|
.message-content.custom-shape {
|
||||||
|
|||||||
@ -199,7 +199,6 @@ export const BASE_EMOJI_KEYWORD_LANG = 'en';
|
|||||||
export const MENU_TRANSITION_DURATION = 200;
|
export const MENU_TRANSITION_DURATION = 200;
|
||||||
export const SLIDE_TRANSITION_DURATION = 450;
|
export const SLIDE_TRANSITION_DURATION = 450;
|
||||||
|
|
||||||
export const VIDEO_MOV_TYPE = 'video/quicktime';
|
|
||||||
export const VIDEO_WEBM_TYPE = 'video/webm';
|
export const VIDEO_WEBM_TYPE = 'video/webm';
|
||||||
|
|
||||||
export const GIF_MIME_TYPE = 'image/gif';
|
export const GIF_MIME_TYPE = 'image/gif';
|
||||||
@ -209,7 +208,7 @@ export const SUPPORTED_IMAGE_CONTENT_TYPES = new Set([
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
export const SUPPORTED_VIDEO_CONTENT_TYPES = new Set([
|
export const SUPPORTED_VIDEO_CONTENT_TYPES = new Set([
|
||||||
'video/mp4', // video/quicktime added dynamically in environment.ts
|
'video/mp4', 'video/quicktime',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const SUPPORTED_AUDIO_CONTENT_TYPES = new Set([
|
export const SUPPORTED_AUDIO_CONTENT_TYPES = new Set([
|
||||||
|
|||||||
@ -16,7 +16,7 @@ import {
|
|||||||
LOCK_SCREEN_ANIMATION_DURATION_MS,
|
LOCK_SCREEN_ANIMATION_DURATION_MS,
|
||||||
} from '../../../config';
|
} from '../../../config';
|
||||||
import {
|
import {
|
||||||
IS_MOV_SUPPORTED, IS_WEBM_SUPPORTED, MAX_BUFFER_SIZE, PLATFORM_ENV,
|
IS_WEBM_SUPPORTED, MAX_BUFFER_SIZE, PLATFORM_ENV,
|
||||||
} from '../../../util/windowEnvironment';
|
} from '../../../util/windowEnvironment';
|
||||||
import { unsubscribe } from '../../../util/notifications';
|
import { unsubscribe } from '../../../util/notifications';
|
||||||
import * as cacheApi from '../../../util/cacheApi';
|
import * as cacheApi from '../../../util/cacheApi';
|
||||||
@ -50,7 +50,6 @@ addActionHandler('initApi', async (global, actions): Promise<void> => {
|
|||||||
platform: PLATFORM_ENV,
|
platform: PLATFORM_ENV,
|
||||||
sessionData: loadStoredSession(),
|
sessionData: loadStoredSession(),
|
||||||
isTest: window.location.search.includes('test') || initialLocationHash?.tgWebAuthTest === '1',
|
isTest: window.location.search.includes('test') || initialLocationHash?.tgWebAuthTest === '1',
|
||||||
isMovSupported: IS_MOV_SUPPORTED,
|
|
||||||
isWebmSupported: IS_WEBM_SUPPORTED,
|
isWebmSupported: IS_WEBM_SUPPORTED,
|
||||||
maxBufferSize: MAX_BUFFER_SIZE,
|
maxBufferSize: MAX_BUFFER_SIZE,
|
||||||
webAuthToken: initialLocationHash?.tgWebAuthToken,
|
webAuthToken: initialLocationHash?.tgWebAuthToken,
|
||||||
|
|||||||
@ -2296,6 +2296,7 @@ export interface ActionPayloads {
|
|||||||
title?: string;
|
title?: string;
|
||||||
message: string;
|
message: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
duration?: number;
|
||||||
actionText?: string;
|
actionText?: string;
|
||||||
action?: CallbackAction;
|
action?: CallbackAction;
|
||||||
} & WithTabId;
|
} & WithTabId;
|
||||||
|
|||||||
63
src/hooks/media/useUnsupportedMedia.ts
Normal file
63
src/hooks/media/useUnsupportedMedia.ts
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import { useEffect, useState } from '../../lib/teact/teact';
|
||||||
|
import { getActions } from '../../global';
|
||||||
|
import useLastCallback from '../useLastCallback';
|
||||||
|
import useLang from '../useLang';
|
||||||
|
import { IS_MOBILE } from '../../util/windowEnvironment';
|
||||||
|
|
||||||
|
const NOTIFICATION_DURATION = 8000;
|
||||||
|
|
||||||
|
export default function useUnsupportedMedia(
|
||||||
|
ref: React.RefObject<HTMLVideoElement>, shouldDisableNotification?: boolean, isDisabled?: boolean,
|
||||||
|
) {
|
||||||
|
const { showNotification } = getActions();
|
||||||
|
const lang = useLang();
|
||||||
|
const [isUnsupported, setIsUnsupported] = useState(false);
|
||||||
|
|
||||||
|
const handleUnsupported = useLastCallback(() => {
|
||||||
|
setIsUnsupported(true);
|
||||||
|
if (shouldDisableNotification) return;
|
||||||
|
|
||||||
|
showNotification({
|
||||||
|
message: IS_MOBILE ? lang('Video.Unsupported.Mobile') : lang('Video.Unsupported.Desktop'),
|
||||||
|
duration: NOTIFICATION_DURATION,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const onError = useLastCallback((event: Event) => {
|
||||||
|
const target = event.currentTarget as HTMLVideoElement;
|
||||||
|
const { error } = target;
|
||||||
|
if (!error) return;
|
||||||
|
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/MediaError/code
|
||||||
|
if (error.code === 3 || error.code === 4) {
|
||||||
|
handleUnsupported();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const onCanPlay = useLastCallback((event: Event) => {
|
||||||
|
const target = event.currentTarget as HTMLVideoElement;
|
||||||
|
|
||||||
|
if (!target.videoHeight || !target.videoWidth) {
|
||||||
|
handleUnsupported();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isDisabled) return undefined;
|
||||||
|
|
||||||
|
const { current } = ref;
|
||||||
|
if (!current) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
current.addEventListener('error', onError);
|
||||||
|
current.addEventListener('canplay', onCanPlay);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
current.removeEventListener('error', onError);
|
||||||
|
current.removeEventListener('canplay', onCanPlay);
|
||||||
|
};
|
||||||
|
}, [isDisabled, ref]);
|
||||||
|
|
||||||
|
return isUnsupported;
|
||||||
|
}
|
||||||
@ -500,4 +500,6 @@ export default {
|
|||||||
'ChannelVisibility.Forwarding.Disabled': 'Restrict Forwarding',
|
'ChannelVisibility.Forwarding.Disabled': 'Restrict Forwarding',
|
||||||
'Settings.TipsUsername': 'TelegramTips',
|
'Settings.TipsUsername': 'TelegramTips',
|
||||||
FoldersAllChatsDesc: 'All unarchived chats',
|
FoldersAllChatsDesc: 'All unarchived chats',
|
||||||
|
'Video.Unsupported.Desktop': 'Unfortunately, this video can\'t be played on Telegram Web. Try opening it with our **desktop app** instead.',
|
||||||
|
'Video.Unsupported.Mobile': 'Unfortunately, this video can\'t be played on Telegram Web. Try opening it with our **mobile app** instead.',
|
||||||
} as ApiLangPack;
|
} as ApiLangPack;
|
||||||
|
|||||||
@ -80,30 +80,34 @@ export function preloadVideo(url: string): Promise<HTMLVideoElement> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function createPosterForVideo(url: string): Promise<string | undefined> {
|
export async function createPosterForVideo(url: string): Promise<string | undefined> {
|
||||||
const video = await preloadVideo(url);
|
try {
|
||||||
|
const video = await preloadVideo(url);
|
||||||
|
|
||||||
return Promise.race([
|
return await Promise.race([
|
||||||
pause(2000) as Promise<undefined>,
|
pause(2000) as Promise<undefined>,
|
||||||
new Promise<string | undefined>((resolve, reject) => {
|
new Promise<string | undefined>((resolve, reject) => {
|
||||||
video.onseeked = () => {
|
video.onseeked = () => {
|
||||||
if (!video.videoWidth || !video.videoHeight) {
|
if (!video.videoWidth || !video.videoHeight) {
|
||||||
resolve(undefined);
|
resolve(undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
canvas.width = video.videoWidth;
|
canvas.width = video.videoWidth;
|
||||||
canvas.height = video.videoHeight;
|
canvas.height = video.videoHeight;
|
||||||
const ctx = canvas.getContext('2d')!;
|
const ctx = canvas.getContext('2d')!;
|
||||||
ctx.drawImage(video, 0, 0);
|
ctx.drawImage(video, 0, 0);
|
||||||
|
|
||||||
canvas.toBlob((blob) => {
|
canvas.toBlob((blob) => {
|
||||||
resolve(blob ? URL.createObjectURL(blob) : undefined);
|
resolve(blob ? URL.createObjectURL(blob) : undefined);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
video.onerror = reject;
|
video.onerror = reject;
|
||||||
video.currentTime = Math.min(video.duration, 1);
|
video.currentTime = Math.min(video.duration, 1);
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
} catch (e) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchBlob(blobUrl: string) {
|
export async function fetchBlob(blobUrl: string) {
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
IS_TEST,
|
IS_TEST,
|
||||||
IS_ELECTRON,
|
IS_ELECTRON,
|
||||||
SUPPORTED_VIDEO_CONTENT_TYPES,
|
|
||||||
VIDEO_MOV_TYPE,
|
|
||||||
CONTENT_TYPES_WITH_PREVIEW,
|
|
||||||
PRODUCTION_HOSTNAME,
|
PRODUCTION_HOSTNAME,
|
||||||
} from '../config';
|
} from '../config';
|
||||||
|
|
||||||
@ -80,15 +77,6 @@ export const ARE_CALLS_SUPPORTED = !navigator.userAgent.includes('Firefox');
|
|||||||
export const LAYERS_ANIMATION_NAME = IS_ANDROID ? 'slideFade' : IS_IOS ? 'slideLayers' : 'pushSlide';
|
export const LAYERS_ANIMATION_NAME = IS_ANDROID ? 'slideFade' : IS_IOS ? 'slideLayers' : 'pushSlide';
|
||||||
|
|
||||||
const TEST_VIDEO = document.createElement('video');
|
const TEST_VIDEO = document.createElement('video');
|
||||||
// `canPlayType(VIDEO_MOV_TYPE)` returns false negative at least for macOS Chrome and iOS Safari
|
|
||||||
export const IS_MOV_SUPPORTED = Boolean(
|
|
||||||
TEST_VIDEO.canPlayType(VIDEO_MOV_TYPE).replace('no', '') || IS_IOS || IS_MAC_OS,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (IS_MOV_SUPPORTED) {
|
|
||||||
SUPPORTED_VIDEO_CONTENT_TYPES.add(VIDEO_MOV_TYPE);
|
|
||||||
CONTENT_TYPES_WITH_PREVIEW.add(VIDEO_MOV_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const IS_WEBM_SUPPORTED = Boolean(TEST_VIDEO.canPlayType('video/webm; codecs="vp9"').replace('no', ''));
|
export const IS_WEBM_SUPPORTED = Boolean(TEST_VIDEO.canPlayType('video/webm; codecs="vp9"').replace('no', ''));
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user