Преглед изворни кода

fix(iframeAPI): startShareVideo command.

master
Hristo Terezov пре 3 година
родитељ
комит
2c2b2c0bec

+ 6
- 1
modules/API/API.js Прегледај датотеку

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

+ 4
- 23
react/features/shared-video/components/AbstractSharedVideoDialog.js Прегледај датотеку

@@ -3,7 +3,7 @@
3 3
 import { Component } from 'react';
4 4
 import type { Dispatch } from 'redux';
5 5
 
6
-import { getYoutubeId } from '../functions';
6
+import { extractYoutubeIdOrURL } from '../functions';
7 7
 
8 8
 /**
9 9
  * The type of the React {@code Component} props of
@@ -56,34 +56,15 @@ export default class AbstractSharedVideoDialog<S: *> extends Component < Props,
56 56
      * @returns {boolean}
57 57
      */
58 58
     _onSetVideoLink(link: string) {
59
-        if (!link) {
60
-            return false;
61
-        }
62
-
63
-        const trimmedLink = link.trim();
64
-
65
-        if (!trimmedLink) {
66
-            return false;
67
-        }
68
-
69 59
         const { onPostSubmit } = this.props;
70
-        const youtubeId = getYoutubeId(trimmedLink);
71 60
 
72
-        if (youtubeId) {
73
-            onPostSubmit(youtubeId);
74
-
75
-            return true;
76
-        }
61
+        const id = extractYoutubeIdOrURL(link);
77 62
 
78
-        // Check if the URL is valid, native may crash otherwise.
79
-        try {
80
-            // eslint-disable-next-line no-new
81
-            new URL(trimmedLink);
82
-        } catch (_) {
63
+        if (!id) {
83 64
             return false;
84 65
         }
85 66
 
86
-        onPostSubmit(trimmedLink);
67
+        onPostSubmit(id);
87 68
 
88 69
         return true;
89 70
     }

+ 35
- 1
react/features/shared-video/functions.js Прегледај датотеку

@@ -12,7 +12,7 @@ import { VIDEO_PLAYER_PARTICIPANT_NAME, YOUTUBE_PLAYER_PARTICIPANT_NAME } from '
12 12
  * @param {string} url - The entered video link.
13 13
  * @returns {string} The youtube video id if matched.
14 14
  */
15
-export function getYoutubeId(url: string) {
15
+function getYoutubeId(url: string) {
16 16
     if (!url) {
17 17
         return null;
18 18
     }
@@ -54,3 +54,37 @@ export function isVideoPlaying(stateful: Object | Function): boolean {
54 54
     return videoPlaying;
55 55
 }
56 56
 
57
+/**
58
+ * Extracts a Youtube id or URL from the user input.
59
+ *
60
+ * @param {string} input - The user input.
61
+ * @returns {string|undefined}
62
+ */
63
+export function extractYoutubeIdOrURL(input: string) {
64
+    if (!input) {
65
+        return;
66
+    }
67
+
68
+    const trimmedLink = input.trim();
69
+
70
+    if (!trimmedLink) {
71
+        return;
72
+    }
73
+
74
+    const youtubeId = getYoutubeId(trimmedLink);
75
+
76
+    if (youtubeId) {
77
+        return youtubeId;
78
+    }
79
+
80
+    // Check if the URL is valid, native may crash otherwise.
81
+    try {
82
+        // eslint-disable-next-line no-new
83
+        new URL(trimmedLink);
84
+    } catch (_) {
85
+        return;
86
+    }
87
+
88
+    return trimmedLink;
89
+}
90
+

Loading…
Откажи
Сачувај