From 79b7e1641d87d3fa92837b1478985ab57cb89d48 Mon Sep 17 00:00:00 2001 From: Zoltan Bettenbuk Date: Sat, 7 Apr 2018 02:52:38 -0500 Subject: [PATCH] Add pinch zoom functionality --- react/features/base/media/actionTypes.js | 12 + react/features/base/media/actions.js | 27 +- .../media/components/AbstractVideoTrack.js | 21 +- .../base/media/components/native/Video.js | 32 +- .../media/components/native/VideoTransform.js | 714 ++++++++++++++++++ .../base/media/components/native/styles.js | 17 + react/features/base/media/reducer.js | 83 +- .../components/ParticipantView.native.js | 11 +- .../components/LargeVideo.native.js | 3 +- 9 files changed, 895 insertions(+), 25 deletions(-) create mode 100644 react/features/base/media/components/native/VideoTransform.js diff --git a/react/features/base/media/actionTypes.js b/react/features/base/media/actionTypes.js index 592644e7e..8b9866c50 100644 --- a/react/features/base/media/actionTypes.js +++ b/react/features/base/media/actionTypes.js @@ -49,6 +49,18 @@ export const SET_VIDEO_AVAILABLE = Symbol('SET_VIDEO_AVAILABLE'); */ export const SET_VIDEO_MUTED = Symbol('SET_VIDEO_MUTED'); +/** + * The type of (redux) action to store the last video {@link Transform} applied + * to a stream. + * + * { + * type: STORE_VIDEO_TRANSFORM, + * streamId: string, + * transform: Transform + * } + */ +export const STORE_VIDEO_TRANSFORM = Symbol('STORE_VIDEO_TRANSFORM'); + /** * The type of (redux) action to toggle the local video camera facing mode. In * contrast to SET_CAMERA_FACING_MODE, allows the toggling to be optimally diff --git a/react/features/base/media/actions.js b/react/features/base/media/actions.js index 79a203b19..7eab0977f 100644 --- a/react/features/base/media/actions.js +++ b/react/features/base/media/actions.js @@ -8,6 +8,7 @@ import { SET_CAMERA_FACING_MODE, SET_VIDEO_AVAILABLE, SET_VIDEO_MUTED, + STORE_VIDEO_TRANSFORM, TOGGLE_CAMERA_FACING_MODE } from './actionTypes'; import { CAMERA_FACING_MODE, VIDEO_MUTISM_AUTHORITY } from './constants'; @@ -18,9 +19,9 @@ import { CAMERA_FACING_MODE, VIDEO_MUTISM_AUTHORITY } from './constants'; * @param {boolean} available - True if the local audio is to be marked as * available or false if the local audio is not available. * @returns {{ - * type: SET_AUDIO_AVAILABLE, - * available: boolean - * }} + * type: SET_AUDIO_AVAILABLE, + * available: boolean + * }} */ export function setAudioAvailable(available: boolean) { return { @@ -112,6 +113,26 @@ export function setVideoMuted( }; } +/** + * Creates an action to store the last video {@link Transform} applied to a + * stream. + * + * @param {string} streamId - The ID of the stream. + * @param {Object} transform - The {@code Transform} to store. + * @returns {{ + * type: STORE_VIDEO_TRANSFORM, + * streamId: string, + * transform: Object + * }} + */ +export function storeVideoTransform(streamId: string, transform: Object) { + return { + type: STORE_VIDEO_TRANSFORM, + streamId, + transform + }; +} + /** * Toggles the camera facing mode. Most commonly, for example, mobile devices * such as phones have a front/user-facing and a back/environment-facing diff --git a/react/features/base/media/components/AbstractVideoTrack.js b/react/features/base/media/components/AbstractVideoTrack.js index 721a531f6..5a2321965 100644 --- a/react/features/base/media/components/AbstractVideoTrack.js +++ b/react/features/base/media/components/AbstractVideoTrack.js @@ -36,7 +36,12 @@ export default class AbstractVideoTrack extends Component { * of all Videos. For more details, refer to the zOrder property of the * Video class for React Native. */ - zOrder: PropTypes.number + zOrder: PropTypes.number, + + /** + * Indicates whether zooming (pinch to zoom and/or drag) is enabled. + */ + zoomEnabled: PropTypes.bool }; /** @@ -80,7 +85,7 @@ export default class AbstractVideoTrack extends Component { * @returns {ReactElement} */ render() { - const videoTrack = this.state.videoTrack; + const { videoTrack } = this.state; let render; if (this.props.waitForVideoStarted) { @@ -108,13 +113,21 @@ export default class AbstractVideoTrack extends Component { const stream = render ? videoTrack.jitsiTrack.getOriginalStream() : null; + // Actual zoom is currently only enabled if the stream is a desktop + // stream. + const zoomEnabled + = this.props.zoomEnabled + && stream + && videoTrack.videoType === 'desktop'; + return (