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.js 5.0KB

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