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 6.3KB

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