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.4KB

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