您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.web.js 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { getLocalParticipant, getParticipantById, pinParticipant } from '../base/participants';
  4. import {
  5. SET_HORIZONTAL_VIEW_DIMENSIONS,
  6. SET_TILE_VIEW_DIMENSIONS,
  7. SET_VERTICAL_VIEW_DIMENSIONS,
  8. SET_VOLUME
  9. } from './actionTypes';
  10. import {
  11. HORIZONTAL_FILMSTRIP_MARGIN,
  12. SCROLL_SIZE,
  13. STAGE_VIEW_THUMBNAIL_HORIZONTAL_BORDER,
  14. STAGE_VIEW_THUMBNAIL_VERTICAL_BORDER,
  15. TILE_HORIZONTAL_MARGIN,
  16. TILE_VERTICAL_MARGIN,
  17. VERTICAL_FILMSTRIP_VERTICAL_MARGIN
  18. } from './constants';
  19. import {
  20. calculateThumbnailSizeForHorizontalView,
  21. calculateThumbnailSizeForTileView,
  22. calculateThumbnailSizeForVerticalView
  23. } from './functions';
  24. export * from './actions.any';
  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 { id: localId } = getLocalParticipant(state);
  122. // Use the list that correctly represents the current order of the participants as visible in the UI.
  123. const { remoteParticipants } = state['features/filmstrip'];
  124. const participants = [ localId, ...remoteParticipants ];
  125. const { id, pinned } = getParticipantById(state, participants[n]);
  126. dispatch(pinParticipant(pinned ? null : id));
  127. };
  128. }
  129. /**
  130. * Sets the volume for a thumbnail's audio.
  131. *
  132. * @param {string} participantId - The participant ID asociated with the audio.
  133. * @param {string} volume - The volume level.
  134. * @returns {{
  135. * type: SET_VOLUME,
  136. * participantId: string,
  137. * volume: number
  138. * }}
  139. */
  140. export function setVolume(participantId: string, volume: number) {
  141. return {
  142. type: SET_VOLUME,
  143. participantId,
  144. volume
  145. };
  146. }