You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

actions.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // @flow
  2. import { NativeModules } from 'react-native';
  3. import type { Dispatch } from 'redux';
  4. import { PIP_ENABLED, getFeatureFlag } from '../../base/flags';
  5. import { Platform } from '../../base/react';
  6. import { ENTER_PICTURE_IN_PICTURE } from './actionTypes';
  7. import logger from './logger';
  8. /**
  9. * Enters (or rather initiates entering) picture-in-picture.
  10. * Helper function to enter PiP mode. This is triggered by user request
  11. * (either pressing the button in the toolbox or the home button on Android)
  12. * ans this triggers the PiP mode, iff it's available and we are in a
  13. * conference.
  14. *
  15. * @public
  16. * @returns {Function}
  17. */
  18. export function enterPictureInPicture() {
  19. return (dispatch: Dispatch<any>, getState: Function) => {
  20. // XXX At the time of this writing this action can only be dispatched by
  21. // the button which is on the conference view, which means that it's
  22. // fine to enter PiP mode.
  23. if (getFeatureFlag(getState, PIP_ENABLED)) {
  24. const { PictureInPicture } = NativeModules;
  25. const p
  26. = Platform.OS === 'android'
  27. ? PictureInPicture
  28. ? PictureInPicture.enterPictureInPicture()
  29. : Promise.reject(
  30. new Error('Picture-in-Picture not supported'))
  31. : Promise.resolve();
  32. p.then(
  33. () => dispatch({ type: ENTER_PICTURE_IN_PICTURE }),
  34. e => logger.warn(`Error entering PiP mode: ${e}`));
  35. }
  36. };
  37. }