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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* @flow */
  2. import type { Dispatch } from 'redux';
  3. import { appNavigate } from '../app';
  4. import { toggleAudioMuted, toggleVideoMuted } from '../base/media';
  5. import { getLocalAudioTrack, getLocalVideoTrack } 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. /**
  20. * Dispatches action to leave the current conference.
  21. *
  22. * @private
  23. * @returns {void}
  24. * @type {Function}
  25. */
  26. _onHangup() {
  27. // XXX We don't know here which value is effectively/internally
  28. // used when there's no valid room name to join. It isn't our
  29. // business to know that anyway. The undefined value is our
  30. // expression of (1) the lack of knowledge & (2) the desire to no
  31. // longer have a valid room name to join.
  32. dispatch(appNavigate(undefined));
  33. },
  34. /**
  35. * Dispatches an action to toggle the mute state of the
  36. * audio/microphone.
  37. *
  38. * @private
  39. * @returns {Object} - Dispatched action.
  40. * @type {Function}
  41. */
  42. _onToggleAudio() {
  43. dispatch(toggleAudioMuted());
  44. },
  45. /**
  46. * Dispatches an action to toggle the mute state of the video/camera.
  47. *
  48. * @private
  49. * @returns {Object} - Dispatched action.
  50. * @type {Function}
  51. */
  52. _onToggleVideo() {
  53. dispatch(toggleVideoMuted());
  54. }
  55. };
  56. }
  57. /**
  58. * Maps parts of the redux state to {@link Toolbox} (React {@code Component})
  59. * props.
  60. *
  61. * @param {Object} state - The redux state of which parts are to be mapped to
  62. * {@code Toolbox} props.
  63. * @protected
  64. * @returns {{
  65. * _audioMuted: boolean,
  66. * _videoMuted: boolean,
  67. * _visible: boolean
  68. * }}
  69. */
  70. export function abstractMapStateToProps(state: Object): Object {
  71. const tracks = state['features/base/tracks'];
  72. const { visible } = state['features/toolbox'];
  73. const audioTrack = getLocalAudioTrack(tracks);
  74. const videoTrack = getLocalVideoTrack(tracks);
  75. return {
  76. /**
  77. * Flag showing whether audio is muted.
  78. *
  79. * @protected
  80. * @type {boolean}
  81. */
  82. _audioMuted: !audioTrack || audioTrack.muted,
  83. /**
  84. * Flag showing whether video is muted.
  85. *
  86. * @protected
  87. * @type {boolean}
  88. */
  89. _videoMuted: !videoTrack || videoTrack.muted,
  90. /**
  91. * Flag showing whether toolbox is visible.
  92. *
  93. * @protected
  94. * @type {boolean}
  95. */
  96. _visible: visible
  97. };
  98. }
  99. /**
  100. * Returns the button object corresponding to a specific {@code buttonName}.
  101. *
  102. * @param {string} buttonName - The name of the button.
  103. * @param {Object} state - The current state.
  104. * @returns {Object} - The button object.
  105. */
  106. export function getButton(buttonName: string, state: Object) {
  107. const { primaryToolbarButtons, secondaryToolbarButtons }
  108. = state['features/toolbox'];
  109. return primaryToolbarButtons.get(buttonName)
  110. || secondaryToolbarButtons.get(buttonName);
  111. }