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 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // @flow
  2. import { NativeModules } from 'react-native';
  3. import { Platform } from '../../base/react';
  4. import {
  5. ENTER_PICTURE_IN_PICTURE,
  6. _SET_EMITTER_SUBSCRIPTIONS
  7. } from './actionTypes';
  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, getState: Function) => {
  20. const state = getState();
  21. const { app } = state['features/app'];
  22. // FIXME We want to be able to enter Picture-in-Picture as soon as we
  23. // are on the Conference page i.e. even before `joining` was set in the
  24. // reducer.
  25. const { conference, joining } = state['features/base/conference'];
  26. if (app
  27. && app.props.pictureInPictureEnabled
  28. && (conference || joining)) {
  29. const { PictureInPicture } = NativeModules;
  30. const p
  31. = Platform.OS === 'android'
  32. ? PictureInPicture
  33. ? PictureInPicture.enterPictureInPicture()
  34. : Promise.reject(
  35. new Error('Picture-in-Picture not supported'))
  36. : Promise.resolve();
  37. p.then(
  38. () => dispatch({ type: ENTER_PICTURE_IN_PICTURE }),
  39. e => console.warn(`Error entering PiP mode: ${e}`));
  40. }
  41. };
  42. }
  43. /**
  44. * Sets the {@code EventEmitter} subscriptions utilized by the feature
  45. * picture-in-picture.
  46. *
  47. * @param {Array<Object>} emitterSubscriptions - The {@code EventEmitter}
  48. * subscriptions to be set.
  49. * @protected
  50. * @returns {{
  51. * type: _SET_EMITTER_SUBSCRIPTIONS,
  52. * emitterSubscriptions: Array<Object>
  53. * }}
  54. */
  55. export function _setEmitterSubscriptions(emitterSubscriptions: ?Array<Object>) {
  56. return {
  57. type: _SET_EMITTER_SUBSCRIPTIONS,
  58. emitterSubscriptions
  59. };
  60. }