Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(iframeAPI): startShareVideo command.

Hristo Terezov2c2b2c0bec2c
diff --git a/modules/API/API.js b/modules/API/API.js
index a3ffb8d1f4..1a076867e7 100644
--- a/modules/API/API.js
+++ b/modules/API/API.js
@@ -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': () => {
diff --git a/react/features/shared-video/components/AbstractSharedVideoDialog.js b/react/features/shared-video/components/AbstractSharedVideoDialog.js
index 4a70f07c61..ccaed69809 100644
--- a/react/features/shared-video/components/AbstractSharedVideoDialog.js
+++ b/react/features/shared-video/components/AbstractSharedVideoDialog.js
@@ -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);
-
- return true;
- }
+ const id = extractYoutubeIdOrURL(link);
- // 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;
}
diff --git a/react/features/shared-video/functions.js b/react/features/shared-video/functions.js
index ab762dfbbe..efbc7c97d4 100644
--- a/react/features/shared-video/functions.js
+++ b/react/features/shared-video/functions.js
@@ -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;
+}
+