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.

actions.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. * @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. * @param {number} authority - The {@link VIDEO_MUTISM_AUTHORITY} which is
  81. * muting/unmuting the local video.
  82. * @returns {Function}
  83. */
  84. export function setVideoMuted(
  85. muted: boolean,
  86. authority: number = VIDEO_MUTISM_AUTHORITY.USER) {
  87. return (dispatch: Dispatch<*>, getState: Function) => {
  88. const oldValue = getState()['features/base/media'].video.muted;
  89. // eslint-disable-next-line no-bitwise
  90. const newValue = muted ? oldValue | authority : oldValue & ~authority;
  91. return dispatch({
  92. type: SET_VIDEO_MUTED,
  93. muted: newValue
  94. });
  95. };
  96. }
  97. /**
  98. * Toggles the mute state of the local audio track(s).
  99. *
  100. * @returns {Function}
  101. */
  102. export function toggleAudioMuted() {
  103. return (dispatch: Dispatch<*>, getState: Function) => {
  104. const muted = getState()['features/base/media'].audio.muted;
  105. return dispatch(setAudioMuted(!muted));
  106. };
  107. }
  108. /**
  109. * Toggles the camera facing mode. Most commonly, for example, mobile devices
  110. * such as phones have a front/user-facing and a back/environment-facing
  111. * cameras. In contrast to setCameraFacingMode, allows the toggling to be
  112. * optimally and/or natively implemented without the overhead of separate reads
  113. * and writes of the current/effective camera facing mode.
  114. *
  115. * @returns {{
  116. * type: TOGGLE_CAMERA_FACING_MODE
  117. * }}
  118. */
  119. export function toggleCameraFacingMode() {
  120. return {
  121. type: TOGGLE_CAMERA_FACING_MODE
  122. };
  123. }
  124. /**
  125. * Toggles the mute state of the local video track(s).
  126. *
  127. * @returns {Function}
  128. */
  129. export function toggleVideoMuted() {
  130. return (dispatch: Dispatch<*>, getState: Function) => {
  131. const muted = getState()['features/base/media'].video.muted;
  132. // XXX The following directly invokes the action creator in order to
  133. // silence Flow.
  134. return setVideoMuted(!muted)(dispatch, getState);
  135. };
  136. }