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.

functions.native.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* @flow */
  2. import type { Dispatch } from 'redux';
  3. import { appNavigate } from '../app';
  4. import { MEDIA_TYPE } from '../base/media';
  5. import { isLocalTrackMuted } from '../base/tracks';
  6. /**
  7. * Maps redux actions to {@link Toolbox} (React {@code Component}) props.
  8. *
  9. * @param {Function} dispatch - The redux {@code dispatch} function.
  10. * @returns {{
  11. * _onHangup: Function,
  12. * _onToggleAudio: Function,
  13. * _onToggleVideo: Function
  14. * }}
  15. * @private
  16. */
  17. export function abstractMapDispatchToProps(dispatch: Dispatch<*>): Object {
  18. return {
  19. // Inject {@code dispatch} into the React Component's props in case it
  20. // needs to dispatch an action in the redux store without
  21. // {@code mapDispatchToProps}.
  22. dispatch,
  23. /**
  24. * Dispatches action to leave the current conference.
  25. *
  26. * @private
  27. * @returns {void}
  28. * @type {Function}
  29. */
  30. _onHangup() {
  31. // XXX We don't know here which value is effectively/internally
  32. // used when there's no valid room name to join. It isn't our
  33. // business to know that anyway. The undefined value is our
  34. // expression of (1) the lack of knowledge & (2) the desire to no
  35. // longer have a valid room name to join.
  36. dispatch(appNavigate(undefined));
  37. }
  38. };
  39. }
  40. /**
  41. * Maps parts of the redux state to {@link Toolbox} (React {@code Component})
  42. * props.
  43. *
  44. * @param {Object} state - The redux state of which parts are to be mapped to
  45. * {@code Toolbox} props.
  46. * @protected
  47. * @returns {{
  48. * _audioMuted: boolean,
  49. * _videoMuted: boolean,
  50. * _visible: boolean
  51. * }}
  52. */
  53. export function abstractMapStateToProps(state: Object): Object {
  54. const tracks = state['features/base/tracks'];
  55. const { visible } = state['features/toolbox'];
  56. return {
  57. /**
  58. * Flag showing whether audio is muted.
  59. *
  60. * @protected
  61. * @type {boolean}
  62. */
  63. _audioMuted: isLocalTrackMuted(tracks, MEDIA_TYPE.AUDIO),
  64. /**
  65. * Flag showing whether video is muted.
  66. *
  67. * @protected
  68. * @type {boolean}
  69. */
  70. _videoMuted: isLocalTrackMuted(tracks, MEDIA_TYPE.VIDEO),
  71. /**
  72. * Flag showing whether toolbox is visible.
  73. *
  74. * @protected
  75. * @type {boolean}
  76. */
  77. _visible: visible
  78. };
  79. }
  80. /**
  81. * Returns the button object corresponding to a specific {@code buttonName}.
  82. *
  83. * @param {string} buttonName - The name of the button.
  84. * @param {Object} state - The current state.
  85. * @returns {Object} - The button object.
  86. */
  87. export function getButton(buttonName: string, state: Object) {
  88. const { primaryToolbarButtons, secondaryToolbarButtons }
  89. = state['features/toolbox'];
  90. return primaryToolbarButtons.get(buttonName)
  91. || secondaryToolbarButtons.get(buttonName);
  92. }