您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

functions.any.ts 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. // This handles the case where disableInitialGUM=true and we haven't yet tried to create any tracks. In this
  30. // case we shouldn't display the the device status indicator. But once we create some tracks we can show it
  31. // because we would know if we created the tracks successfully or not.
  32. && (!state['features/base/config'].disableInitialGUM || state['features/base/tracks']?.length > 0);
  33. }
  34. /**
  35. * Selector for determining if the display name is mandatory.
  36. *
  37. * @param {IReduxState} state - The state of the app.
  38. * @returns {boolean}
  39. */
  40. export function isDisplayNameRequired(state: IReduxState): boolean {
  41. return Boolean(state['features/lobby']?.isDisplayNameRequiredError
  42. || state['features/base/config']?.requireDisplayName);
  43. }
  44. /**
  45. * Selector for determining if the prejoin page is enabled in config. Defaults to `true`.
  46. *
  47. * @param {IReduxState} state - The state of the app.
  48. * @returns {boolean}
  49. */
  50. export function isPrejoinEnabledInConfig(state: IReduxState): boolean {
  51. return state['features/base/config'].prejoinConfig?.enabled ?? true;
  52. }
  53. /**
  54. * Selector for determining if the prejoin display name field is visible.
  55. *
  56. * @param {IReduxState} state - The state of the app.
  57. * @returns {boolean}
  58. */
  59. export function isPrejoinDisplayNameVisible(state: IReduxState): boolean {
  60. return !state['features/base/config'].prejoinConfig?.hideDisplayName;
  61. }
  62. /**
  63. * Returns the text for the prejoin status bar.
  64. *
  65. * @param {IReduxState} state - The state of the app.
  66. * @returns {string}
  67. */
  68. export function getDeviceStatusText(state: IReduxState): string {
  69. return state['features/prejoin']?.deviceStatusText;
  70. }
  71. /**
  72. * Returns the type of the prejoin status bar: 'ok'|'warning'.
  73. *
  74. * @param {IReduxState} state - The state of the app.
  75. * @returns {string}
  76. */
  77. export function getDeviceStatusType(state: IReduxState): string {
  78. return state['features/prejoin']?.deviceStatusType;
  79. }
  80. /**
  81. * Returns the 'conferenceUrl' used for dialing out.
  82. *
  83. * @param {IReduxState} state - The state of the app.
  84. * @returns {string}
  85. */
  86. export function getDialOutConferenceUrl(state: IReduxState): string {
  87. return `${getRoomName(state)}@${state['features/base/config'].hosts?.muc}`;
  88. }
  89. /**
  90. * Selector for getting the dial out country.
  91. *
  92. * @param {IReduxState} state - The state of the app.
  93. * @returns {Object}
  94. */
  95. export function getDialOutCountry(state: IReduxState) {
  96. return state['features/prejoin'].dialOutCountry;
  97. }
  98. /**
  99. * Selector for getting the dial out number (without prefix).
  100. *
  101. * @param {IReduxState} state - The state of the app.
  102. * @returns {string}
  103. */
  104. export function getDialOutNumber(state: IReduxState): string {
  105. return state['features/prejoin'].dialOutNumber;
  106. }
  107. /**
  108. * Selector for getting the dial out status while calling.
  109. *
  110. * @param {IReduxState} state - The state of the app.
  111. * @returns {string}
  112. */
  113. export function getDialOutStatus(state: IReduxState): string {
  114. return state['features/prejoin'].dialOutStatus;
  115. }
  116. /**
  117. * Returns the full dial out number (containing country code and +).
  118. *
  119. * @param {IReduxState} state - The state of the app.
  120. * @returns {string}
  121. */
  122. export function getFullDialOutNumber(state: IReduxState): string {
  123. const dialOutNumber = getDialOutNumber(state);
  124. const country = getDialOutCountry(state);
  125. return `+${country.dialCode}${dialOutNumber}`;
  126. }
  127. /**
  128. * Selector for getting the error if any while creating streams.
  129. *
  130. * @param {IReduxState} state - The state of the app.
  131. * @returns {string}
  132. */
  133. export function getRawError(state: IReduxState): string {
  134. return state['features/prejoin']?.rawError;
  135. }
  136. /**
  137. * Selector for getting the visibility state for the 'JoinByPhoneDialog'.
  138. *
  139. * @param {IReduxState} state - The state of the app.
  140. * @returns {boolean}
  141. */
  142. export function isJoinByPhoneDialogVisible(state: IReduxState): boolean {
  143. return state['features/prejoin']?.showJoinByPhoneDialog;
  144. }
  145. /**
  146. * Returns true if the prejoin page is enabled and no flag
  147. * to bypass showing the page is present.
  148. *
  149. * @param {IReduxState} state - The state of the app.
  150. * @returns {boolean}
  151. */
  152. export function isPrejoinPageVisible(state: IReduxState): boolean {
  153. return Boolean(navigator.product !== 'ReactNative'
  154. && isPrejoinEnabledInConfig(state)
  155. && state['features/prejoin']?.showPrejoin
  156. && !(state['features/base/config'].enableForcedReload && state['features/prejoin'].skipPrejoinOnReload));
  157. }
  158. /**
  159. * Returns true if we should auto-knock in case lobby is enabled for the room.
  160. *
  161. * @param {IReduxState} state - The state of the app.
  162. * @returns {boolean}
  163. */
  164. export function shouldAutoKnock(state: IReduxState): boolean {
  165. const { iAmRecorder, iAmSipGateway } = state['features/base/config'];
  166. const { userSelectedSkipPrejoin } = state['features/base/settings'];
  167. const { autoKnock } = getLobbyConfig(state);
  168. return Boolean(((isPrejoinEnabledInConfig(state) && !userSelectedSkipPrejoin)
  169. || autoKnock || (iAmRecorder && iAmSipGateway))
  170. && !state['features/lobby'].knocking);
  171. }
  172. /**
  173. * Returns true if the unsafe room warning flag is enabled.
  174. *
  175. * @param {IReduxState} state - The state of the app.
  176. * @returns {boolean}
  177. */
  178. export function isUnsafeRoomWarningEnabled(state: IReduxState): boolean {
  179. const { enableInsecureRoomNameWarning = false } = state['features/base/config'];
  180. return getFeatureFlag(state, UNSAFE_ROOM_WARNING, enableInsecureRoomNameWarning);
  181. }
  182. /**
  183. * Returns true if the room name is enabled.
  184. *
  185. * @param {IReduxState} state - The state of the app.
  186. * @returns {boolean}
  187. */
  188. export function isRoomNameEnabled(state: IReduxState): boolean {
  189. const { hideConferenceSubject = false } = state['features/base/config'];
  190. return getFeatureFlag(state, MEETING_NAME_ENABLED, true)
  191. && !hideConferenceSubject;
  192. }