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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* @flow */
  2. import type { Dispatch } from 'redux';
  3. import {
  4. SET_AUDIO_MUTED,
  5. SET_CAMERA_FACING_MODE,
  6. SET_VIDEO_MUTED,
  7. TOGGLE_CAMERA_FACING_MODE
  8. } from './actionTypes';
  9. import { CAMERA_FACING_MODE } from './constants';
  10. /**
  11. * Action to set the muted state of the local audio.
  12. *
  13. * @param {boolean} muted - True if the local audio is to be muted or false if
  14. * the local audio is to be unmuted.
  15. * @returns {{
  16. * type: SET_AUDIO_MUTED,
  17. * muted: boolean
  18. * }}
  19. */
  20. export function setAudioMuted(muted: boolean) {
  21. return {
  22. type: SET_AUDIO_MUTED,
  23. muted
  24. };
  25. }
  26. /**
  27. * Action to set the facing mode of the local camera.
  28. *
  29. * @param {CAMERA_FACING_MODE} cameraFacingMode - The camera facing mode to set.
  30. * @returns {{
  31. * type: SET_CAMERA_FACING_MODE,
  32. * cameraFacingMode: CAMERA_FACING_MODE
  33. * }}
  34. */
  35. export function setCameraFacingMode(cameraFacingMode: CAMERA_FACING_MODE) {
  36. return {
  37. type: SET_CAMERA_FACING_MODE,
  38. cameraFacingMode
  39. };
  40. }
  41. /**
  42. * Action to set the muted state of the local video.
  43. *
  44. * @param {boolean} muted - True if the local video is to be muted or false if
  45. * the local video is to be unmuted.
  46. * @returns {{
  47. * type: SET_VIDEO_MUTED,
  48. * muted: boolean
  49. * }}
  50. */
  51. export function setVideoMuted(muted: boolean) {
  52. return {
  53. type: SET_VIDEO_MUTED,
  54. muted
  55. };
  56. }
  57. /**
  58. * Toggles the mute state of the local audio track(s).
  59. *
  60. * @returns {Function}
  61. */
  62. export function toggleAudioMuted() {
  63. return (dispatch: Dispatch<*>, getState: Function) => {
  64. const muted = getState()['features/base/media'].audio.muted;
  65. return dispatch(setAudioMuted(!muted));
  66. };
  67. }
  68. /**
  69. * Toggles the camera facing mode. Most commonly, for example, mobile devices
  70. * such as phones have a front/user-facing and a back/environment-facing
  71. * cameras. In contrast to setCameraFacingMode, allows the toggling to be
  72. * optimally and/or natively implemented without the overhead of separate reads
  73. * and writes of the current/effective camera facing mode.
  74. *
  75. * @returns {{
  76. * type: TOGGLE_CAMERA_FACING_MODE
  77. * }}
  78. */
  79. export function toggleCameraFacingMode() {
  80. return {
  81. type: TOGGLE_CAMERA_FACING_MODE
  82. };
  83. }
  84. /**
  85. * Toggles the mute state of the local video track(s).
  86. *
  87. * @returns {Function}
  88. */
  89. export function toggleVideoMuted() {
  90. return (dispatch: Dispatch<*>, getState: Function) => {
  91. const muted = getState()['features/base/media'].video.muted;
  92. return dispatch(setVideoMuted(!muted));
  93. };
  94. }