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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 } 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. * @returns {{
  34. * type: SET_AUDIO_MUTED,
  35. * muted: boolean
  36. * }}
  37. */
  38. export function setAudioMuted(muted: boolean) {
  39. return {
  40. type: SET_AUDIO_MUTED,
  41. muted
  42. };
  43. }
  44. /**
  45. * Action to set the facing mode of the local camera.
  46. *
  47. * @param {CAMERA_FACING_MODE} cameraFacingMode - The camera facing mode to set.
  48. * @returns {{
  49. * type: SET_CAMERA_FACING_MODE,
  50. * cameraFacingMode: CAMERA_FACING_MODE
  51. * }}
  52. */
  53. export function setCameraFacingMode(cameraFacingMode: CAMERA_FACING_MODE) {
  54. return {
  55. type: SET_CAMERA_FACING_MODE,
  56. cameraFacingMode
  57. };
  58. }
  59. /**
  60. * Action to adjust the availability of the local video.
  61. *
  62. * @param {boolean} available - True if the local video is to be marked as
  63. * available or false if the local video is not available.
  64. * @returns {{
  65. * type: SET_VIDEO_AVAILABLE,
  66. * available: boolean
  67. * }}
  68. */
  69. export function setVideoAvailable(available: boolean) {
  70. return {
  71. type: SET_VIDEO_AVAILABLE,
  72. available
  73. };
  74. }
  75. /**
  76. * Action to set the muted state of the local video.
  77. *
  78. * @param {boolean} muted - True if the local video is to be muted or false if
  79. * the local video is to be unmuted.
  80. * @returns {{
  81. * type: SET_VIDEO_MUTED,
  82. * muted: boolean
  83. * }}
  84. */
  85. export function setVideoMuted(muted: boolean) {
  86. return {
  87. type: SET_VIDEO_MUTED,
  88. muted
  89. };
  90. }
  91. /**
  92. * Toggles the mute state of the local audio track(s).
  93. *
  94. * @returns {Function}
  95. */
  96. export function toggleAudioMuted() {
  97. return (dispatch: Dispatch<*>, getState: Function) => {
  98. const muted = getState()['features/base/media'].audio.muted;
  99. return dispatch(setAudioMuted(!muted));
  100. };
  101. }
  102. /**
  103. * Toggles the camera facing mode. Most commonly, for example, mobile devices
  104. * such as phones have a front/user-facing and a back/environment-facing
  105. * cameras. In contrast to setCameraFacingMode, allows the toggling to be
  106. * optimally and/or natively implemented without the overhead of separate reads
  107. * and writes of the current/effective camera facing mode.
  108. *
  109. * @returns {{
  110. * type: TOGGLE_CAMERA_FACING_MODE
  111. * }}
  112. */
  113. export function toggleCameraFacingMode() {
  114. return {
  115. type: TOGGLE_CAMERA_FACING_MODE
  116. };
  117. }
  118. /**
  119. * Toggles the mute state of the local video track(s).
  120. *
  121. * @returns {Function}
  122. */
  123. export function toggleVideoMuted() {
  124. return (dispatch: Dispatch<*>, getState: Function) => {
  125. const muted = getState()['features/base/media'].video.muted;
  126. return dispatch(setVideoMuted(!muted));
  127. };
  128. }