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

fix(iframe): Use largeVideo video element for screenshot.

Get the existing HTMLVideoElement for large video instead of creating a new video element for capturing the screenshot.
This should prevent the video player from getting displayed on mobile Safari.
master
Jaya Allamsetty пре 5 година
родитељ
комит
09124ad7e9

+ 2
- 2
modules/API/external/external_api.js Прегледај датотеку

@@ -639,8 +639,8 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
639 639
     /**
640 640
      * Captures the screenshot of the large video.
641 641
      *
642
-     * @returns {dataURL} - Base64 encoded image data of the screenshot if large
643
-     * video is detected, an error otherwise.
642
+     * @returns {Promise<string>} - Resolves with a base64 encoded image data of the screenshot
643
+     * if large video is detected, an error otherwise.
644 644
      */
645 645
     captureLargeVideoScreenshot() {
646 646
         return this._transport.sendRequest({

+ 0
- 52
react/features/large-video/actions.any.js Прегледај датотеку

@@ -9,7 +9,6 @@ import {
9 9
 import { _handleParticipantError } from '../base/conference';
10 10
 import { MEDIA_TYPE } from '../base/media';
11 11
 import { getParticipants } from '../base/participants';
12
-import { getTrackByMediaTypeAndParticipant } from '../base/tracks';
13 12
 import { reportError } from '../base/util';
14 13
 import { shouldDisplayTileView } from '../video-layout';
15 14
 
@@ -18,57 +17,6 @@ import {
18 17
     UPDATE_KNOWN_LARGE_VIDEO_RESOLUTION
19 18
 } from './actionTypes';
20 19
 
21
-/**
22
-* Captures a screenshot of the video displayed on the large video.
23
-*
24
-* @returns {Function}
25
-*/
26
-export function captureLargeVideoScreenshot() {
27
-    return (dispatch: Dispatch<any>, getState: Function): Promise<Object> => {
28
-        const state = getState();
29
-        const largeVideo = state['features/large-video'];
30
-
31
-        if (!largeVideo) {
32
-            return Promise.resolve();
33
-        }
34
-        const tracks = state['features/base/tracks'];
35
-        const { jitsiTrack } = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, largeVideo.participantId);
36
-        const videoStream = jitsiTrack.getOriginalStream();
37
-
38
-        // Create a HTML canvas and draw video from the track on to the canvas.
39
-        const [ track ] = videoStream.getVideoTracks();
40
-        const { height, width } = track.getSettings() ?? track.getConstraints();
41
-        const canvasElement = document.createElement('canvas');
42
-        const ctx = canvasElement.getContext('2d');
43
-        const videoElement = document.createElement('video');
44
-
45
-        videoElement.height = parseInt(height, 10);
46
-        videoElement.width = parseInt(width, 10);
47
-        videoElement.autoplay = true;
48
-        videoElement.srcObject = videoStream;
49
-        canvasElement.height = videoElement.height;
50
-        canvasElement.width = videoElement.width;
51
-
52
-        // Wait for the video to load before drawing on to the canvas.
53
-        const promise = new Promise(resolve => {
54
-            videoElement.onloadeddata = () => resolve();
55
-        });
56
-
57
-        return promise.then(() => {
58
-            ctx.drawImage(videoElement, 0, 0, videoElement.width, videoElement.height);
59
-            const dataURL = canvasElement.toDataURL('image/png', 1.0);
60
-
61
-            // Cleanup.
62
-            ctx.clearRect(0, 0, videoElement.width, videoElement.height);
63
-            videoElement.srcObject = null;
64
-            canvasElement.remove();
65
-            videoElement.remove();
66
-
67
-            return Promise.resolve(dataURL);
68
-        });
69
-    };
70
-}
71
-
72 20
 /**
73 21
  * Signals conference to select a participant.
74 22
  *

+ 47
- 0
react/features/large-video/actions.web.js Прегледај датотеку

@@ -3,9 +3,56 @@
3 3
 import type { Dispatch } from 'redux';
4 4
 
5 5
 import VideoLayout from '../../../modules/UI/videolayout/VideoLayout';
6
+import { MEDIA_TYPE } from '../base/media';
7
+import { getTrackByMediaTypeAndParticipant } from '../base/tracks';
6 8
 
7 9
 export * from './actions.any';
8 10
 
11
+/**
12
+* Captures a screenshot of the video displayed on the large video.
13
+*
14
+* @returns {Function}
15
+*/
16
+export function captureLargeVideoScreenshot() {
17
+    return (dispatch: Dispatch<any>, getState: Function): Promise<string> => {
18
+        const state = getState();
19
+        const largeVideo = state['features/large-video'];
20
+
21
+        if (!largeVideo) {
22
+            return Promise.resolve();
23
+        }
24
+        const tracks = state['features/base/tracks'];
25
+        const { jitsiTrack } = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, largeVideo.participantId);
26
+        const videoStream = jitsiTrack.getOriginalStream();
27
+
28
+        // Get the video element for the large video, cast HTMLElement to HTMLVideoElement to make flow happy.
29
+        /* eslint-disable-next-line no-extra-parens*/
30
+        const videoElement = ((document.getElementById('largeVideo'): any): HTMLVideoElement);
31
+
32
+        if (!videoElement) {
33
+            return Promise.resolve();
34
+        }
35
+
36
+        // Create a HTML canvas and draw video on to the canvas.
37
+        const [ track ] = videoStream.getVideoTracks();
38
+        const { height, width } = track.getSettings() ?? track.getConstraints();
39
+        const canvasElement = document.createElement('canvas');
40
+        const ctx = canvasElement.getContext('2d');
41
+
42
+        canvasElement.style.display = 'none';
43
+        canvasElement.height = parseInt(height, 10);
44
+        canvasElement.width = parseInt(width, 10);
45
+        ctx.drawImage(videoElement, 0, 0);
46
+        const dataURL = canvasElement.toDataURL('image/png', 1.0);
47
+
48
+        // Cleanup.
49
+        ctx.clearRect(0, 0, canvasElement.width, canvasElement.height);
50
+        canvasElement.remove();
51
+
52
+        return Promise.resolve(dataURL);
53
+    };
54
+}
55
+
9 56
 /**
10 57
  * Resizes the large video container based on the dimensions provided.
11 58
  *

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