Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

functions.native.js 2.9KB

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