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

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