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

functions.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // @flow
  2. import { getRoomName } from '../base/conference';
  3. import { getDialOutStatusUrl, getDialOutUrl } from '../base/config/functions';
  4. import { isAudioMuted, isVideoMutedByUser } from '../base/media';
  5. import { PREJOIN_SCREEN_STATES } from './constants';
  6. /**
  7. * Selector for the visibility of the 'join by phone' button.
  8. *
  9. * @param {Object} state - The state of the app.
  10. * @returns {boolean}
  11. */
  12. export function isJoinByPhoneButtonVisible(state: Object): 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 {Object} state - The state of the app.
  19. * @returns {boolean}
  20. */
  21. export function isDeviceStatusVisible(state: Object): 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 {Object} state - The state of the app.
  29. * @returns {boolean}
  30. */
  31. export function isDisplayNameRequired(state: Object): boolean {
  32. return state['features/prejoin'].isDisplayNameRequired
  33. || state['features/base/config'].requireDisplayName;
  34. }
  35. /**
  36. * Selector for determining if the user has chosen to skip prejoin page.
  37. *
  38. * @param {Object} state - The state of the app.
  39. * @returns {boolean}
  40. */
  41. export function isPrejoinSkipped(state: Object) {
  42. return state['features/prejoin'].userSelectedSkipPrejoin;
  43. }
  44. /**
  45. * Returns the text for the prejoin status bar.
  46. *
  47. * @param {Object} state - The state of the app.
  48. * @returns {string}
  49. */
  50. export function getDeviceStatusText(state: Object): string {
  51. return state['features/prejoin']?.deviceStatusText;
  52. }
  53. /**
  54. * Returns the type of the prejoin status bar: 'ok'|'warning'.
  55. *
  56. * @param {Object} state - The state of the app.
  57. * @returns {string}
  58. */
  59. export function getDeviceStatusType(state: Object): string {
  60. return state['features/prejoin']?.deviceStatusType;
  61. }
  62. /**
  63. * Returns the 'conferenceUrl' used for dialing out.
  64. *
  65. * @param {Object} state - The state of the app.
  66. * @returns {string}
  67. */
  68. export function getDialOutConferenceUrl(state: Object): string {
  69. return `${getRoomName(state)}@${state['features/base/config'].hosts.muc}`;
  70. }
  71. /**
  72. * Selector for getting the dial out country.
  73. *
  74. * @param {Object} state - The state of the app.
  75. * @returns {Object}
  76. */
  77. export function getDialOutCountry(state: Object): Object {
  78. return state['features/prejoin'].dialOutCountry;
  79. }
  80. /**
  81. * Selector for getting the dial out number (without prefix).
  82. *
  83. * @param {Object} state - The state of the app.
  84. * @returns {string}
  85. */
  86. export function getDialOutNumber(state: Object): string {
  87. return state['features/prejoin'].dialOutNumber;
  88. }
  89. /**
  90. * Selector for getting the dial out status while calling.
  91. *
  92. * @param {Object} state - The state of the app.
  93. * @returns {string}
  94. */
  95. export function getDialOutStatus(state: Object): string {
  96. return state['features/prejoin'].dialOutStatus;
  97. }
  98. /**
  99. * Returns the full dial out number (containing country code and +).
  100. *
  101. * @param {Object} state - The state of the app.
  102. * @returns {string}
  103. */
  104. export function getFullDialOutNumber(state: Object): 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 {Object} state - The state of the app.
  113. * @returns {string}
  114. */
  115. export function getRawError(state: Object): string {
  116. return state['features/prejoin']?.rawError;
  117. }
  118. /**
  119. * Selector for getting the visibility state for the 'JoinByPhoneDialog'.
  120. *
  121. * @param {Object} state - The state of the app.
  122. * @returns {boolean}
  123. */
  124. export function isJoinByPhoneDialogVisible(state: Object): 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 {Object} state - The state of the app.
  132. * @returns {boolean}
  133. */
  134. export function isPrejoinPageEnabled(state: Object): boolean {
  135. return navigator.product !== 'ReactNative'
  136. && state['features/base/config'].prejoinPageEnabled
  137. && !state['features/base/settings'].userSelectedSkipPrejoin
  138. && !(state['features/base/config'].enableForcedReload && state['features/prejoin'].skipPrejoinOnReload);
  139. }
  140. /**
  141. * Returns true if the prejoin page is visible & active.
  142. *
  143. * @param {Object} state - The state of the app.
  144. * @returns {boolean}
  145. */
  146. export function isPrejoinPageVisible(state: Object): boolean {
  147. return isPrejoinPageEnabled(state) && state['features/prejoin']?.showPrejoin === PREJOIN_SCREEN_STATES.VISIBLE;
  148. }
  149. /**
  150. * Returns true if the prejoin page is loading.
  151. *
  152. * @param {Object} state - The state of the app.
  153. * @returns {boolean}
  154. */
  155. export function isPrejoinPageLoading(state: Object): boolean {
  156. return isPrejoinPageEnabled(state) && state['features/prejoin']?.showPrejoin === PREJOIN_SCREEN_STATES.LOADING;
  157. }
  158. /**
  159. * Returns true if we should auto-knock in case lobby is enabled for the room.
  160. *
  161. * @param {Object} state - The state of the app.
  162. * @returns {boolean}
  163. */
  164. export function shouldAutoKnock(state: Object): boolean {
  165. const { iAmRecorder, iAmSipGateway } = state['features/base/config'];
  166. return (isPrejoinPageEnabled(state) || (iAmRecorder && iAmSipGateway))
  167. && !state['features/lobby'].knocking;
  168. }