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.

functions.ts 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { IReduxState, IStore } from '../app/types';
  2. import { isDisplayNameVisible } from '../base/config/functions.any';
  3. import {
  4. getLocalParticipant,
  5. getParticipantDisplayName,
  6. isScreenShareParticipant,
  7. isWhiteboardParticipant
  8. } from '../base/participants/functions';
  9. import { updateSettings } from '../base/settings/actions';
  10. import { getLargeVideoParticipant } from '../large-video/functions';
  11. import { isToolboxVisible } from '../toolbox/functions.web';
  12. import { isLayoutTileView } from '../video-layout/functions.any';
  13. /**
  14. * Appends a suffix to the display name.
  15. *
  16. * @param {string} displayName - The display name.
  17. * @param {string} suffix - Suffix that will be appended.
  18. * @returns {string} The formatted display name.
  19. */
  20. export function appendSuffix(displayName: string, suffix = ''): string {
  21. return `${displayName || suffix}${
  22. displayName && suffix && displayName !== suffix ? ` (${suffix})` : ''}`;
  23. }
  24. /**
  25. * Dispatches an action to update the local participant's display name. A
  26. * name must be entered for the action to dispatch.
  27. *
  28. * It returns a boolean to comply the Dialog behaviour:
  29. * {@code true} - the dialog should be closed.
  30. * {@code false} - the dialog should be left open.
  31. *
  32. * @param {Function} dispatch - Redux dispatch function.
  33. * @param {Function} onPostSubmit - Function to be invoked after a successful display name change.
  34. * @param {string} displayName - The display name to save.
  35. * @returns {boolean}
  36. */
  37. export function onSetDisplayName(dispatch: IStore['dispatch'], onPostSubmit?: Function) {
  38. return function(displayName: string) {
  39. if (!displayName?.trim()) {
  40. return false;
  41. }
  42. // Store display name in settings
  43. dispatch(updateSettings({
  44. displayName
  45. }));
  46. onPostSubmit?.();
  47. return true;
  48. };
  49. }
  50. /**
  51. * Returns true if the stage participant badge should be displayed and false otherwise.
  52. *
  53. * @param {IReduxState} state - The redux state.
  54. * @returns {boolean} - True if the stage participant badge should be displayed and false otherwise.
  55. */
  56. export function shouldDisplayStageParticipantBadge(state: IReduxState) {
  57. const largeVideoParticipant = getLargeVideoParticipant(state);
  58. const selectedId = largeVideoParticipant?.id;
  59. const nameToDisplay = getParticipantDisplayName(state, selectedId ?? '');
  60. const localId = getLocalParticipant(state)?.id;
  61. const isTileView = isLayoutTileView(state);
  62. const toolboxVisible: boolean = isToolboxVisible(state);
  63. const showDisplayName = isDisplayNameVisible(state);
  64. return Boolean(showDisplayName
  65. && nameToDisplay
  66. && selectedId !== localId
  67. && !isTileView
  68. && !isWhiteboardParticipant(largeVideoParticipant)
  69. && (!isScreenShareParticipant(largeVideoParticipant) || toolboxVisible)
  70. );
  71. }