Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

actions.web.js 5.6KB

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