Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

actions.ts 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. import { createRemoteVideoMenuButtonEvent } from '../analytics/AnalyticsEvents';
  2. import { sendAnalytics } from '../analytics/functions';
  3. import { IStore } from '../app/types';
  4. import { getCurrentConference } from '../base/conference/functions';
  5. import { connect, disconnect, setPreferVisitor } from '../base/connection/actions';
  6. import { getLocalParticipant } from '../base/participants/functions';
  7. import {
  8. CLEAR_VISITOR_PROMOTION_REQUEST,
  9. I_AM_VISITOR_MODE,
  10. SET_IN_VISITORS_QUEUE,
  11. SET_VISITORS_SUPPORTED,
  12. SET_VISITOR_DEMOTE_ACTOR,
  13. UPDATE_VISITORS_COUNT,
  14. UPDATE_VISITORS_IN_QUEUE_COUNT,
  15. VISITOR_PROMOTION_REQUEST
  16. } from './actionTypes';
  17. import logger from './logger';
  18. import { IPromotionRequest } from './types';
  19. /**
  20. * Action used to admit multiple participants in the conference.
  21. *
  22. * @param {Array<Object>} requests - A list of visitors requests.
  23. * @returns {Function}
  24. */
  25. export function admitMultiple(requests: Array<IPromotionRequest>): Function {
  26. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  27. const conference = getCurrentConference(getState);
  28. conference?.sendMessage({
  29. type: 'visitors',
  30. action: 'promotion-response',
  31. approved: true,
  32. ids: requests.map(r => r.from)
  33. });
  34. };
  35. }
  36. /**
  37. * Approves the request of a visitor to join the main meeting.
  38. *
  39. * @param {IPromotionRequest} request - The request from the visitor.
  40. * @returns {Function}
  41. */
  42. export function approveRequest(request: IPromotionRequest) {
  43. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  44. const conference = getCurrentConference(getState);
  45. conference?.sendMessage({
  46. type: 'visitors',
  47. action: 'promotion-response',
  48. approved: true,
  49. id: request.from
  50. });
  51. dispatch(clearPromotionRequest(request));
  52. };
  53. }
  54. /**
  55. * Denies the request of a visitor to join the main meeting.
  56. *
  57. * @param {IPromotionRequest} request - The request from the visitor.
  58. * @returns {Function}
  59. */
  60. export function denyRequest(request: IPromotionRequest) {
  61. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  62. const conference = getCurrentConference(getState);
  63. conference?.sendMessage({
  64. type: 'visitors',
  65. action: 'promotion-response',
  66. approved: false,
  67. id: request.from
  68. });
  69. dispatch(clearPromotionRequest(request));
  70. };
  71. }
  72. /**
  73. * Sends a demote request to a main participant to join the meeting as a visitor.
  74. *
  75. * @param {string} id - The ID for the participant.
  76. * @returns {Function}
  77. */
  78. export function demoteRequest(id: string) {
  79. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  80. const conference = getCurrentConference(getState);
  81. const localParticipant = getLocalParticipant(getState());
  82. sendAnalytics(createRemoteVideoMenuButtonEvent('demote.button', { 'participant_id': id }));
  83. if (id === localParticipant?.id) {
  84. dispatch(disconnect(true))
  85. .then(() => {
  86. dispatch(setPreferVisitor(true));
  87. logger.info('Dispatching connect to demote the local participant.');
  88. return dispatch(connect());
  89. });
  90. } else {
  91. conference?.sendMessage({
  92. type: 'visitors',
  93. action: 'demote-request',
  94. id,
  95. actor: localParticipant?.id
  96. });
  97. }
  98. };
  99. }
  100. /**
  101. * Removes a promotion request from the state.
  102. *
  103. * @param {IPromotionRequest} request - The request.
  104. * @returns {{
  105. * type: CLEAR_VISITOR_PROMOTION_REQUEST,
  106. * request: IPromotionRequest
  107. * }}
  108. */
  109. export function clearPromotionRequest(request: IPromotionRequest) {
  110. return {
  111. type: CLEAR_VISITOR_PROMOTION_REQUEST,
  112. request
  113. };
  114. }
  115. /**
  116. * Visitor has sent us a promotion request.
  117. *
  118. * @param {IPromotionRequest} request - The request.
  119. * @returns {{
  120. * type: VISITOR_PROMOTION_REQUEST,
  121. * }}
  122. */
  123. export function promotionRequestReceived(request: IPromotionRequest) {
  124. return {
  125. type: VISITOR_PROMOTION_REQUEST,
  126. request
  127. };
  128. }
  129. /**
  130. * Sets Visitors mode on or off.
  131. *
  132. * @param {boolean} enabled - The new visitors mode state.
  133. * @returns {{
  134. * type: I_AM_VISITOR_MODE,
  135. * }}
  136. */
  137. export function setIAmVisitor(enabled: boolean) {
  138. return {
  139. type: I_AM_VISITOR_MODE,
  140. enabled
  141. };
  142. }
  143. /**
  144. * Sets in visitor's queue.
  145. *
  146. * @param {boolean} value - The new value.
  147. * @returns {{
  148. * type: SET_IN_VISITORS_QUEUE,
  149. * }}
  150. */
  151. export function setInVisitorsQueue(value: boolean) {
  152. return {
  153. type: SET_IN_VISITORS_QUEUE,
  154. value
  155. };
  156. }
  157. /**
  158. * Sets visitor demote actor.
  159. *
  160. * @param {string|undefined} displayName - The display name of the participant.
  161. * @returns {{
  162. * type: SET_VISITOR_DEMOTE_ACTOR,
  163. * }}
  164. */
  165. export function setVisitorDemoteActor(displayName: string | undefined) {
  166. return {
  167. type: SET_VISITOR_DEMOTE_ACTOR,
  168. displayName
  169. };
  170. }
  171. /**
  172. * Visitors count has been updated.
  173. *
  174. * @param {boolean} value - The new value whether visitors are supported.
  175. * @returns {{
  176. * type: SET_VISITORS_SUPPORTED,
  177. * }}
  178. */
  179. export function setVisitorsSupported(value: boolean) {
  180. return {
  181. type: SET_VISITORS_SUPPORTED,
  182. value
  183. };
  184. }
  185. /**
  186. * Visitors count has been updated.
  187. *
  188. * @param {number} count - The new visitors count.
  189. * @returns {{
  190. * type: UPDATE_VISITORS_COUNT,
  191. * }}
  192. */
  193. export function updateVisitorsCount(count: number) {
  194. return {
  195. type: UPDATE_VISITORS_COUNT,
  196. count
  197. };
  198. }
  199. /**
  200. * Visitors in queue count has been updated.
  201. *
  202. * @param {number} count - The new visitors in queue count.
  203. * @returns {{
  204. * type: UPDATE_VISITORS_IN_QUEUE_COUNT,
  205. * }}
  206. */
  207. export function updateVisitorsInQueueCount(count: number) {
  208. return {
  209. type: UPDATE_VISITORS_IN_QUEUE_COUNT,
  210. count
  211. };
  212. }
  213. /**
  214. * Closes the overflow menu if opened.
  215. *
  216. * @private
  217. * @returns {void}
  218. */
  219. export function goLive() {
  220. return (_: IStore['dispatch'], getState: IStore['getState']) => {
  221. const { conference } = getState()['features/base/conference'];
  222. conference?.getMetadataHandler().setMetadata('visitors', {
  223. live: true
  224. });
  225. };
  226. }