fix(iframeAPI): startShareVideo command.

This commit is contained in:
Hristo Terezov 2022-01-14 17:35:31 -06:00 committed by Дамян Минков
parent 43f554295e
commit 2c2b2c0bec
3 changed files with 45 additions and 25 deletions

View File

@ -71,6 +71,7 @@ import { isScreenAudioSupported, isScreenVideoShared } from '../../react/feature
import { startScreenShareFlow, startAudioScreenShareFlow } from '../../react/features/screen-share/actions';
import { toggleScreenshotCaptureSummary } from '../../react/features/screenshot-capture';
import { playSharedVideo, stopSharedVideo } from '../../react/features/shared-video/actions.any';
import { extractYoutubeIdOrURL } from '../../react/features/shared-video/functions';
import { toggleTileView, setTileView } from '../../react/features/video-layout';
import { muteAllParticipants } from '../../react/features/video-menu/actions';
import { setVideoQuality } from '../../react/features/video-quality';
@ -382,7 +383,11 @@ function initCommands() {
'start-share-video': url => {
logger.debug('Share video command received');
sendAnalytics(createApiEvent('share.video.start'));
APP.store.dispatch(playSharedVideo(url));
const id = extractYoutubeIdOrURL(url);
if (id) {
APP.store.dispatch(playSharedVideo(id));
}
},
'stop-share-video': () => {

View File

@ -3,7 +3,7 @@
import { Component } from 'react';
import type { Dispatch } from 'redux';
import { getYoutubeId } from '../functions';
import { extractYoutubeIdOrURL } from '../functions';
/**
* The type of the React {@code Component} props of
@ -56,34 +56,15 @@ export default class AbstractSharedVideoDialog<S: *> extends Component < Props,
* @returns {boolean}
*/
_onSetVideoLink(link: string) {
if (!link) {
return false;
}
const trimmedLink = link.trim();
if (!trimmedLink) {
return false;
}
const { onPostSubmit } = this.props;
const youtubeId = getYoutubeId(trimmedLink);
if (youtubeId) {
onPostSubmit(youtubeId);
const id = extractYoutubeIdOrURL(link);
return true;
}
// Check if the URL is valid, native may crash otherwise.
try {
// eslint-disable-next-line no-new
new URL(trimmedLink);
} catch (_) {
if (!id) {
return false;
}
onPostSubmit(trimmedLink);
onPostSubmit(id);
return true;
}

View File

@ -12,7 +12,7 @@ import { VIDEO_PLAYER_PARTICIPANT_NAME, YOUTUBE_PLAYER_PARTICIPANT_NAME } from '
* @param {string} url - The entered video link.
* @returns {string} The youtube video id if matched.
*/
export function getYoutubeId(url: string) {
function getYoutubeId(url: string) {
if (!url) {
return null;
}
@ -54,3 +54,37 @@ export function isVideoPlaying(stateful: Object | Function): boolean {
return videoPlaying;
}
/**
* Extracts a Youtube id or URL from the user input.
*
* @param {string} input - The user input.
* @returns {string|undefined}
*/
export function extractYoutubeIdOrURL(input: string) {
if (!input) {
return;
}
const trimmedLink = input.trim();
if (!trimmedLink) {
return;
}
const youtubeId = getYoutubeId(trimmedLink);
if (youtubeId) {
return youtubeId;
}
// Check if the URL is valid, native may crash otherwise.
try {
// eslint-disable-next-line no-new
new URL(trimmedLink);
} catch (_) {
return;
}
return trimmedLink;
}