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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* @flow */
  2. import type { Dispatch } from 'redux';
  3. import {
  4. SET_AUDIO_MUTED,
  5. SET_AUDIO_AVAILABLE,
  6. SET_CAMERA_FACING_MODE,
  7. SET_VIDEO_AVAILABLE,
  8. SET_VIDEO_MUTED,
  9. TOGGLE_CAMERA_FACING_MODE
  10. } from './actionTypes';
  11. import { CAMERA_FACING_MODE, VIDEO_MUTISM_AUTHORITY } from './constants';
  12. /**
  13. * Action to adjust the availability of the local audio.
  14. *
  15. * @param {boolean} available - True if the local audio is to be marked as
  16. * available or false if the local audio is not available.
  17. * @returns {{
  18. * type: SET_AUDIO_AVAILABLE,
  19. * available: boolean
  20. * }}
  21. */
  22. export function setAudioAvailable(available: boolean) {
  23. return {
  24. type: SET_AUDIO_AVAILABLE,
  25. available
  26. };
  27. }
  28. /**
  29. * Action to set the muted state of the local audio.
  30. *
  31. * @param {boolean} muted - True if the local audio is to be muted or false if
  32. * the local audio is to be unmuted.
  33. * @param {boolean} ensureTrack - True if we want to ensure that a new track is
  34. * created if missing.
  35. * @returns {{
  36. * type: SET_AUDIO_MUTED,
  37. * ensureTrack: boolean,
  38. * muted: boolean
  39. * }}
  40. */
  41. export function setAudioMuted(muted: boolean, ensureTrack: boolean = false) {
  42. return {
  43. type: SET_AUDIO_MUTED,
  44. ensureTrack,
  45. muted
  46. };
  47. }
  48. /**
  49. * Action to set the facing mode of the local camera.
  50. *
  51. * @param {CAMERA_FACING_MODE} cameraFacingMode - The camera facing mode to set.
  52. * @returns {{
  53. * type: SET_CAMERA_FACING_MODE,
  54. * cameraFacingMode: CAMERA_FACING_MODE
  55. * }}
  56. */
  57. export function setCameraFacingMode(cameraFacingMode: CAMERA_FACING_MODE) {
  58. return {
  59. type: SET_CAMERA_FACING_MODE,
  60. cameraFacingMode
  61. };
  62. }
  63. /**
  64. * Action to adjust the availability of the local video.
  65. *
  66. * @param {boolean} available - True if the local video is to be marked as
  67. * available or false if the local video is not available.
  68. * @returns {{
  69. * type: SET_VIDEO_AVAILABLE,
  70. * available: boolean
  71. * }}
  72. */
  73. export function setVideoAvailable(available: boolean) {
  74. return {
  75. type: SET_VIDEO_AVAILABLE,
  76. available
  77. };
  78. }
  79. /**
  80. * Action to set the muted state of the local video.
  81. *
  82. * @param {boolean} muted - True if the local video is to be muted or false if
  83. * the local video is to be unmuted.
  84. * @param {number} authority - The {@link VIDEO_MUTISM_AUTHORITY} which is
  85. * muting/unmuting the local video.
  86. * @param {boolean} ensureTrack - True if we want to ensure that a new track is
  87. * created if missing.
  88. * @returns {Function}
  89. */
  90. export function setVideoMuted(
  91. muted: boolean,
  92. authority: number = VIDEO_MUTISM_AUTHORITY.USER,
  93. ensureTrack: boolean = false) {
  94. return (dispatch: Dispatch<*>, getState: Function) => {
  95. const oldValue = getState()['features/base/media'].video.muted;
  96. // eslint-disable-next-line no-bitwise
  97. const newValue = muted ? oldValue | authority : oldValue & ~authority;
  98. return dispatch({
  99. type: SET_VIDEO_MUTED,
  100. ensureTrack,
  101. muted: newValue
  102. });
  103. };
  104. }
  105. /**
  106. * Toggles the mute state of the local audio track(s).
  107. *
  108. * @returns {Function}
  109. */
  110. export function toggleAudioMuted() {
  111. return (dispatch: Dispatch<*>, getState: Function) => {
  112. const muted = getState()['features/base/media'].audio.muted;
  113. return dispatch(setAudioMuted(!muted));
  114. };
  115. }
  116. /**
  117. * Toggles the camera facing mode. Most commonly, for example, mobile devices
  118. * such as phones have a front/user-facing and a back/environment-facing
  119. * cameras. In contrast to setCameraFacingMode, allows the toggling to be
  120. * optimally and/or natively implemented without the overhead of separate reads
  121. * and writes of the current/effective camera facing mode.
  122. *
  123. * @returns {{
  124. * type: TOGGLE_CAMERA_FACING_MODE
  125. * }}
  126. */
  127. export function toggleCameraFacingMode() {
  128. return {
  129. type: TOGGLE_CAMERA_FACING_MODE
  130. };
  131. }
  132. /**
  133. * Toggles the mute state of the local video track(s).
  134. *
  135. * @returns {Function}
  136. */
  137. export function toggleVideoMuted() {
  138. return (dispatch: Dispatch<*>, getState: Function) => {
  139. const muted = getState()['features/base/media'].video.muted;
  140. // XXX The following directly invokes the action creator in order to
  141. // silence Flow.
  142. return setVideoMuted(!muted)(dispatch, getState);
  143. };
  144. }