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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // @flow
  2. import { NativeModules } from 'react-native';
  3. import {
  4. ENTER_PICTURE_IN_PICTURE,
  5. _SET_EMITTER_SUBSCRIPTIONS
  6. } from './actionTypes';
  7. /**
  8. * Enters (or rather initiates entering) picture-in-picture.
  9. * Helper function to enter PiP mode. This is triggered by user request
  10. * (either pressing the button in the toolbox or the home button on Android)
  11. * ans this triggers the PiP mode, iff it's available and we are in a
  12. * conference.
  13. *
  14. * @public
  15. * @returns {Function}
  16. */
  17. export function enterPictureInPicture() {
  18. return (dispatch: Dispatch, getState: Function) => {
  19. const state = getState();
  20. const { app } = state['features/app'];
  21. const { conference, joining } = state['features/base/conference'];
  22. if (app
  23. && app.props.pictureInPictureEnabled
  24. && (conference || joining)) {
  25. const { PictureInPicture } = NativeModules;
  26. const p
  27. = PictureInPicture
  28. ? PictureInPicture.enterPictureInPicture()
  29. : Promise.reject(
  30. new Error('Picture-in-Picture not supported'));
  31. p.then(
  32. () => dispatch({ type: ENTER_PICTURE_IN_PICTURE }),
  33. e => console.warn(`Error entering PiP mode: ${e}`));
  34. }
  35. };
  36. }
  37. /**
  38. * Sets the {@code EventEmitter} subscriptions utilized by the feature
  39. * picture-in-picture.
  40. *
  41. * @param {Array<Object>} emitterSubscriptions - The {@code EventEmitter}
  42. * subscriptions to be set.
  43. * @protected
  44. * @returns {{
  45. * type: _SET_EMITTER_SUBSCRIPTIONS,
  46. * emitterSubscriptions: Array<Object>
  47. * }}
  48. */
  49. export function _setEmitterSubscriptions(emitterSubscriptions: ?Array<Object>) {
  50. return {
  51. type: _SET_EMITTER_SUBSCRIPTIONS,
  52. emitterSubscriptions
  53. };
  54. }