Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

functions.ts 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import { IReduxState } from '../app/types';
  2. import { getRoomName } from '../base/conference/functions';
  3. import { getDialOutStatusUrl, getDialOutUrl } from '../base/config/functions.any';
  4. import { UNSAFE_ROOM_WARNING } from '../base/flags/constants';
  5. import { getFeatureFlag } from '../base/flags/functions';
  6. import { isAudioMuted, isVideoMutedByUser } from '../base/media/functions';
  7. import { getLobbyConfig } from '../lobby/functions';
  8. /**
  9. * Selector for the visibility of the 'join by phone' button.
  10. *
  11. * @param {IReduxState} state - The state of the app.
  12. * @returns {boolean}
  13. */
  14. export function isJoinByPhoneButtonVisible(state: IReduxState): boolean {
  15. return Boolean(getDialOutUrl(state) && getDialOutStatusUrl(state));
  16. }
  17. /**
  18. * Selector for determining if the device status strip is visible or not.
  19. *
  20. * @param {IReduxState} state - The state of the app.
  21. * @returns {boolean}
  22. */
  23. export function isDeviceStatusVisible(state: IReduxState): boolean {
  24. return !(isAudioMuted(state) && isVideoMutedByUser(state))
  25. && !state['features/base/config'].startSilent;
  26. }
  27. /**
  28. * Selector for determining if the display name is mandatory.
  29. *
  30. * @param {IReduxState} state - The state of the app.
  31. * @returns {boolean}
  32. */
  33. export function isDisplayNameRequired(state: IReduxState): boolean {
  34. return Boolean(state['features/lobby']?.isDisplayNameRequiredError
  35. || state['features/base/config']?.requireDisplayName);
  36. }
  37. /**
  38. * Selector for determining if the prejoin display name field is visible.
  39. *
  40. * @param {IReduxState} state - The state of the app.
  41. * @returns {boolean}
  42. */
  43. export function isPrejoinDisplayNameVisible(state: IReduxState): boolean {
  44. return !state['features/base/config'].prejoinConfig?.hideDisplayName;
  45. }
  46. /**
  47. * Returns the text for the prejoin status bar.
  48. *
  49. * @param {IReduxState} state - The state of the app.
  50. * @returns {string}
  51. */
  52. export function getDeviceStatusText(state: IReduxState): string {
  53. return state['features/prejoin']?.deviceStatusText;
  54. }
  55. /**
  56. * Returns the type of the prejoin status bar: 'ok'|'warning'.
  57. *
  58. * @param {IReduxState} state - The state of the app.
  59. * @returns {string}
  60. */
  61. export function getDeviceStatusType(state: IReduxState): string {
  62. return state['features/prejoin']?.deviceStatusType;
  63. }
  64. /**
  65. * Returns the 'conferenceUrl' used for dialing out.
  66. *
  67. * @param {IReduxState} state - The state of the app.
  68. * @returns {string}
  69. */
  70. export function getDialOutConferenceUrl(state: IReduxState): string {
  71. return `${getRoomName(state)}@${state['features/base/config'].hosts?.muc}`;
  72. }
  73. /**
  74. * Selector for getting the dial out country.
  75. *
  76. * @param {IReduxState} state - The state of the app.
  77. * @returns {Object}
  78. */
  79. export function getDialOutCountry(state: IReduxState) {
  80. return state['features/prejoin'].dialOutCountry;
  81. }
  82. /**
  83. * Selector for getting the dial out number (without prefix).
  84. *
  85. * @param {IReduxState} state - The state of the app.
  86. * @returns {string}
  87. */
  88. export function getDialOutNumber(state: IReduxState): string {
  89. return state['features/prejoin'].dialOutNumber;
  90. }
  91. /**
  92. * Selector for getting the dial out status while calling.
  93. *
  94. * @param {IReduxState} state - The state of the app.
  95. * @returns {string}
  96. */
  97. export function getDialOutStatus(state: IReduxState): string {
  98. return state['features/prejoin'].dialOutStatus;
  99. }
  100. /**
  101. * Returns the full dial out number (containing country code and +).
  102. *
  103. * @param {IReduxState} state - The state of the app.
  104. * @returns {string}
  105. */
  106. export function getFullDialOutNumber(state: IReduxState): string {
  107. const dialOutNumber = getDialOutNumber(state);
  108. const country = getDialOutCountry(state);
  109. return `+${country.dialCode}${dialOutNumber}`;
  110. }
  111. /**
  112. * Selector for getting the error if any while creating streams.
  113. *
  114. * @param {IReduxState} state - The state of the app.
  115. * @returns {string}
  116. */
  117. export function getRawError(state: IReduxState): string {
  118. return state['features/prejoin']?.rawError;
  119. }
  120. /**
  121. * Selector for getting the visibility state for the 'JoinByPhoneDialog'.
  122. *
  123. * @param {IReduxState} state - The state of the app.
  124. * @returns {boolean}
  125. */
  126. export function isJoinByPhoneDialogVisible(state: IReduxState): boolean {
  127. return state['features/prejoin']?.showJoinByPhoneDialog;
  128. }
  129. /**
  130. * Returns true if the prejoin page is enabled and no flag
  131. * to bypass showing the page is present.
  132. *
  133. * @param {IReduxState} state - The state of the app.
  134. * @returns {boolean}
  135. */
  136. export function isPrejoinPageVisible(state: IReduxState): boolean {
  137. return Boolean(navigator.product !== 'ReactNative'
  138. && state['features/base/config'].prejoinConfig?.enabled
  139. && state['features/prejoin']?.showPrejoin
  140. && !(state['features/base/config'].enableForcedReload && state['features/prejoin'].skipPrejoinOnReload));
  141. }
  142. /**
  143. * Returns true if we should auto-knock in case lobby is enabled for the room.
  144. *
  145. * @param {IReduxState} state - The state of the app.
  146. * @returns {boolean}
  147. */
  148. export function shouldAutoKnock(state: IReduxState): boolean {
  149. const { iAmRecorder, iAmSipGateway, prejoinConfig } = state['features/base/config'];
  150. const { userSelectedSkipPrejoin } = state['features/base/settings'];
  151. const { autoKnock } = getLobbyConfig(state);
  152. const isPrejoinEnabled = prejoinConfig?.enabled;
  153. return Boolean(((isPrejoinEnabled && !userSelectedSkipPrejoin)
  154. || autoKnock || (iAmRecorder && iAmSipGateway))
  155. && !state['features/lobby'].knocking);
  156. }
  157. /**
  158. * Returns true if the unsafe room warning flag is enabled.
  159. *
  160. * @param {IReduxState} state - The state of the app.
  161. * @returns {boolean}
  162. */
  163. export function isUnsafeRoomWarningEnabled(state: IReduxState): boolean {
  164. const { enableInsecureRoomNameWarning = false } = state['features/base/config'];
  165. return getFeatureFlag(state, UNSAFE_ROOM_WARNING, enableInsecureRoomNameWarning);
  166. }