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.

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