2018-02-01 16:02:07 +00:00
|
|
|
// @flow
|
|
|
|
|
2018-02-19 22:52:21 +00:00
|
|
|
import { NativeModules } from 'react-native';
|
|
|
|
|
2018-02-01 16:02:07 +00:00
|
|
|
import {
|
2018-02-19 22:52:21 +00:00
|
|
|
ENTER_PICTURE_IN_PICTURE,
|
|
|
|
_SET_EMITTER_SUBSCRIPTIONS
|
2018-02-01 16:02:07 +00:00
|
|
|
} from './actionTypes';
|
|
|
|
|
|
|
|
/**
|
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() {
|
|
|
|
return (dispatch: Dispatch, getState: Function) => {
|
|
|
|
const state = getState();
|
|
|
|
const { app } = state['features/app'];
|
|
|
|
const { conference, joining } = state['features/base/conference'];
|
|
|
|
|
|
|
|
if (app
|
|
|
|
&& app.props.pictureInPictureEnabled
|
|
|
|
&& (conference || joining)) {
|
|
|
|
const { PictureInPicture } = NativeModules;
|
|
|
|
const p
|
|
|
|
= PictureInPicture
|
|
|
|
? PictureInPicture.enterPictureInPicture()
|
|
|
|
: Promise.reject(
|
|
|
|
new Error('Picture-in-Picture not supported'));
|
|
|
|
|
|
|
|
p.then(
|
|
|
|
() => dispatch({ type: ENTER_PICTURE_IN_PICTURE }),
|
|
|
|
e => console.warn(`Error entering PiP mode: ${e}`));
|
|
|
|
}
|
2018-02-01 16:02:07 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-02-19 22:52:21 +00:00
|
|
|
* Sets the {@code EventEmitter} subscriptions utilized by the feature
|
|
|
|
* picture-in-picture.
|
2018-02-01 16:02:07 +00:00
|
|
|
*
|
2018-02-19 22:52:21 +00:00
|
|
|
* @param {Array<Object>} emitterSubscriptions - The {@code EventEmitter}
|
|
|
|
* subscriptions to be set.
|
|
|
|
* @protected
|
2018-02-01 16:02:07 +00:00
|
|
|
* @returns {{
|
2018-02-19 22:52:21 +00:00
|
|
|
* type: _SET_EMITTER_SUBSCRIPTIONS,
|
|
|
|
* emitterSubscriptions: Array<Object>
|
2018-02-01 16:02:07 +00:00
|
|
|
* }}
|
|
|
|
*/
|
2018-02-19 22:52:21 +00:00
|
|
|
export function _setEmitterSubscriptions(emitterSubscriptions: ?Array<Object>) {
|
2018-02-01 16:02:07 +00:00
|
|
|
return {
|
2018-02-19 22:52:21 +00:00
|
|
|
type: _SET_EMITTER_SUBSCRIPTIONS,
|
|
|
|
emitterSubscriptions
|
2018-02-01 16:02:07 +00:00
|
|
|
};
|
|
|
|
}
|