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