2018-02-01 16:02:07 +00:00
|
|
|
// @flow
|
|
|
|
|
2018-02-19 22:52:21 +00:00
|
|
|
import { NativeModules } from 'react-native';
|
2019-03-19 15:42:25 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
2018-02-19 22:52:21 +00:00
|
|
|
|
2019-05-24 11:06:05 +00:00
|
|
|
import { PIP_ENABLED, getFeatureFlag } from '../../base/flags';
|
2018-03-06 22:02:59 +00:00
|
|
|
import { Platform } from '../../base/react';
|
|
|
|
|
2018-05-01 15:07:14 +00:00
|
|
|
import { ENTER_PICTURE_IN_PICTURE } from './actionTypes';
|
2019-08-21 14:50:00 +00:00
|
|
|
import logger from './logger';
|
2018-07-30 14:38:25 +00:00
|
|
|
|
2018-02-01 16:02:07 +00:00
|
|
|
/**
|
2018-02-19 22:52:21 +00:00
|
|
|
* Enters (or rather initiates entering) picture-in-picture.
|
|
|
|
* Helper function to enter PiP mode. This is triggered by user request
|
|
|
|
* (either pressing the button in the toolbox or the home button on Android)
|
|
|
|
* ans this triggers the PiP mode, iff it's available and we are in a
|
|
|
|
* conference.
|
2018-02-01 16:02:07 +00:00
|
|
|
*
|
2018-02-19 22:52:21 +00:00
|
|
|
* @public
|
|
|
|
* @returns {Function}
|
2018-02-01 16:02:07 +00:00
|
|
|
*/
|
2018-02-19 22:52:21 +00:00
|
|
|
export function enterPictureInPicture() {
|
2019-03-19 15:42:25 +00:00
|
|
|
return (dispatch: Dispatch<any>, getState: Function) => {
|
2018-04-26 14:18:15 +00:00
|
|
|
// XXX At the time of this writing this action can only be dispatched by
|
|
|
|
// the button which is on the conference view, which means that it's
|
|
|
|
// fine to enter PiP mode.
|
2019-05-24 11:06:05 +00:00
|
|
|
if (getFeatureFlag(getState, PIP_ENABLED)) {
|
2018-02-19 22:52:21 +00:00
|
|
|
const { PictureInPicture } = NativeModules;
|
|
|
|
const p
|
2018-03-06 22:02:59 +00:00
|
|
|
= Platform.OS === 'android'
|
|
|
|
? PictureInPicture
|
|
|
|
? PictureInPicture.enterPictureInPicture()
|
|
|
|
: Promise.reject(
|
|
|
|
new Error('Picture-in-Picture not supported'))
|
|
|
|
: Promise.resolve();
|
2018-02-19 22:52:21 +00:00
|
|
|
|
|
|
|
p.then(
|
|
|
|
() => dispatch({ type: ENTER_PICTURE_IN_PICTURE }),
|
2018-07-30 14:38:25 +00:00
|
|
|
e => logger.warn(`Error entering PiP mode: ${e}`));
|
2018-02-19 22:52:21 +00:00
|
|
|
}
|
2018-02-01 16:02:07 +00:00
|
|
|
};
|
|
|
|
}
|