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.web.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { getLocalParticipant, getRemoteParticipants, pinParticipant } from '../base/participants';
  4. import {
  5. SET_HORIZONTAL_VIEW_DIMENSIONS,
  6. SET_TILE_VIEW_DIMENSIONS,
  7. SET_VERTICAL_VIEW_DIMENSIONS,
  8. SET_VISIBLE_REMOTE_PARTICIPANTS,
  9. SET_VOLUME
  10. } from './actionTypes';
  11. import {
  12. HORIZONTAL_FILMSTRIP_MARGIN,
  13. SCROLL_SIZE,
  14. STAGE_VIEW_THUMBNAIL_HORIZONTAL_BORDER,
  15. STAGE_VIEW_THUMBNAIL_VERTICAL_BORDER,
  16. TILE_HORIZONTAL_MARGIN,
  17. TILE_VERTICAL_MARGIN,
  18. VERTICAL_FILMSTRIP_VERTICAL_MARGIN
  19. } from './constants';
  20. import {
  21. calculateThumbnailSizeForHorizontalView,
  22. calculateThumbnailSizeForTileView,
  23. calculateThumbnailSizeForVerticalView
  24. } from './functions';
  25. export * from './actions.any';
  26. /**
  27. * Sets the dimensions of the tile view grid.
  28. *
  29. * @param {Object} dimensions - Whether the filmstrip is visible.
  30. * @param {Object | Function} stateful - An object or function that can be
  31. * resolved to Redux state using the {@code toState} function.
  32. * @returns {Function}
  33. */
  34. export function setTileViewDimensions(dimensions: Object) {
  35. return (dispatch: Dispatch<any>, getState: Function) => {
  36. const state = getState();
  37. const { clientHeight, clientWidth } = state['features/base/responsive-ui'];
  38. const { disableResponsiveTiles } = state['features/base/config'];
  39. const {
  40. height,
  41. width
  42. } = calculateThumbnailSizeForTileView({
  43. ...dimensions,
  44. clientWidth,
  45. clientHeight,
  46. disableResponsiveTiles
  47. });
  48. const { columns, rows } = dimensions;
  49. const thumbnailsTotalHeight = rows * (TILE_VERTICAL_MARGIN + height);
  50. const hasScroll = clientHeight < thumbnailsTotalHeight;
  51. const filmstripWidth = (columns * (TILE_HORIZONTAL_MARGIN + width)) + (hasScroll ? SCROLL_SIZE : 0);
  52. const filmstripHeight = Math.min(clientHeight, thumbnailsTotalHeight);
  53. dispatch({
  54. type: SET_TILE_VIEW_DIMENSIONS,
  55. dimensions: {
  56. gridDimensions: dimensions,
  57. thumbnailSize: {
  58. height,
  59. width
  60. },
  61. filmstripHeight,
  62. filmstripWidth
  63. }
  64. });
  65. };
  66. }
  67. /**
  68. * Sets the dimensions of the thumbnails in vertical view.
  69. *
  70. * @returns {Function}
  71. */
  72. export function setVerticalViewDimensions() {
  73. return (dispatch: Dispatch<any>, getState: Function) => {
  74. const state = getState();
  75. const { clientHeight = 0, clientWidth = 0 } = state['features/base/responsive-ui'];
  76. const thumbnails = calculateThumbnailSizeForVerticalView(clientWidth);
  77. dispatch({
  78. type: SET_VERTICAL_VIEW_DIMENSIONS,
  79. dimensions: {
  80. ...thumbnails,
  81. remoteVideosContainer: {
  82. width: thumbnails?.local?.width
  83. + TILE_HORIZONTAL_MARGIN + STAGE_VIEW_THUMBNAIL_HORIZONTAL_BORDER + SCROLL_SIZE,
  84. height: clientHeight - thumbnails?.local?.height - VERTICAL_FILMSTRIP_VERTICAL_MARGIN
  85. }
  86. }
  87. });
  88. };
  89. }
  90. /**
  91. * Sets the dimensions of the thumbnails in horizontal view.
  92. *
  93. * @returns {Function}
  94. */
  95. export function setHorizontalViewDimensions() {
  96. return (dispatch: Dispatch<any>, getState: Function) => {
  97. const state = getState();
  98. const { clientHeight = 0, clientWidth = 0 } = state['features/base/responsive-ui'];
  99. const thumbnails = calculateThumbnailSizeForHorizontalView(clientHeight);
  100. dispatch({
  101. type: SET_HORIZONTAL_VIEW_DIMENSIONS,
  102. dimensions: {
  103. ...thumbnails,
  104. remoteVideosContainer: {
  105. width: clientWidth - thumbnails?.local?.width - HORIZONTAL_FILMSTRIP_MARGIN,
  106. height: thumbnails?.local?.height
  107. + TILE_VERTICAL_MARGIN + STAGE_VIEW_THUMBNAIL_VERTICAL_BORDER + SCROLL_SIZE
  108. }
  109. }
  110. });
  111. };
  112. }
  113. /**
  114. * Emulates a click on the n-th video.
  115. *
  116. * @param {number} n - Number that identifies the video.
  117. * @returns {Function}
  118. */
  119. export function clickOnVideo(n: number) {
  120. return (dispatch: Function, getState: Function) => {
  121. const state = getState();
  122. const participants = [ getLocalParticipant(state), ...getRemoteParticipants(state).values() ];
  123. const nThParticipant = participants[n];
  124. const { id, pinned } = nThParticipant;
  125. dispatch(pinParticipant(pinned ? null : id));
  126. };
  127. }
  128. /**
  129. * Sets the volume for a thumbnail's audio.
  130. *
  131. * @param {string} participantId - The participant ID asociated with the audio.
  132. * @param {string} volume - The volume level.
  133. * @returns {{
  134. * type: SET_VOLUME,
  135. * participantId: string,
  136. * volume: number
  137. * }}
  138. */
  139. export function setVolume(participantId: string, volume: number) {
  140. return {
  141. type: SET_VOLUME,
  142. participantId,
  143. volume
  144. };
  145. }
  146. /**
  147. * Sets the list of the visible participants in the filmstrip by storing the start and end index from the remote
  148. * participants array.
  149. *
  150. * @param {number} startIndex - The start index from the remote participants array.
  151. * @param {number} endIndex - The end index from the remote participants array.
  152. * @returns {{
  153. * type: SET_VISIBLE_REMOTE_PARTICIPANTS,
  154. * startIndex: number,
  155. * endIndex: number
  156. * }}
  157. */
  158. export function setVisibleRemoteParticipants(startIndex: number, endIndex: number) {
  159. return {
  160. type: SET_VISIBLE_REMOTE_PARTICIPANTS,
  161. startIndex,
  162. endIndex
  163. };
  164. }