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

functions.js 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. // @flow
  2. import { getRoomName } from '../base/conference';
  3. import { getDialOutStatusUrl, getDialOutUrl } from '../base/config/functions';
  4. /**
  5. * Mutes or unmutes a track.
  6. *
  7. * @param {Object} track - The track to be configured.
  8. * @param {boolean} shouldMute - If it should mute or not.
  9. * @returns {Promise<void>}
  10. */
  11. function applyMuteOptionsToTrack(track, shouldMute) {
  12. if (track.isMuted() === shouldMute) {
  13. return;
  14. }
  15. if (shouldMute) {
  16. return track.mute();
  17. }
  18. return track.unmute();
  19. }
  20. /**
  21. * Selector for the visibility of the 'join by phone' button.
  22. *
  23. * @param {Object} state - The state of the app.
  24. * @returns {boolean}
  25. */
  26. export function isJoinByPhoneButtonVisible(state: Object): boolean {
  27. return Boolean(getDialOutUrl(state) && getDialOutStatusUrl(state));
  28. }
  29. /**
  30. * Selector for determining if the device status strip is visible or not.
  31. *
  32. * @param {Object} state - The state of the app.
  33. * @returns {boolean}
  34. */
  35. export function isDeviceStatusVisible(state: Object): boolean {
  36. return !((isAudioDisabled(state) && isPrejoinVideoDisabled(state))
  37. || (isPrejoinAudioMuted(state) && isPrejoinVideoMuted(state)));
  38. }
  39. /**
  40. * Selector for getting the active video/content sharing track.
  41. *
  42. * @param {Object} state - The state of the app.
  43. * @returns {boolean}
  44. */
  45. export function getActiveVideoTrack(state: Object): Object {
  46. const track = getVideoTrack(state) || getContentSharingTrack(state);
  47. if (track && track.isActive()) {
  48. return track;
  49. }
  50. return null;
  51. }
  52. /**
  53. * Returns a list with all the prejoin tracks configured according to
  54. * user's preferences.
  55. *
  56. * @param {Object} state - The state of the app.
  57. * @returns {Promise<Object[]>}
  58. */
  59. export async function getAllPrejoinConfiguredTracks(state: Object): Promise<Object[]> {
  60. const tracks = [];
  61. const audioTrack = getAudioTrack(state);
  62. const videoTrack = getVideoTrack(state);
  63. const csTrack = getContentSharingTrack(state);
  64. if (csTrack) {
  65. tracks.push(csTrack);
  66. } else if (videoTrack) {
  67. await applyMuteOptionsToTrack(videoTrack, isPrejoinVideoMuted(state));
  68. tracks.push(videoTrack);
  69. }
  70. if (audioTrack) {
  71. await applyMuteOptionsToTrack(audioTrack, isPrejoinAudioMuted(state));
  72. isPrejoinAudioMuted(state) && audioTrack.mute();
  73. tracks.push(audioTrack);
  74. }
  75. return tracks;
  76. }
  77. /**
  78. * Selector for getting the prejoin audio track.
  79. *
  80. * @param {Object} state - The state of the app.
  81. * @returns {Object}
  82. */
  83. export function getAudioTrack(state: Object): Object {
  84. return state['features/prejoin']?.audioTrack;
  85. }
  86. /**
  87. * Selector for getting the prejoin content sharing track.
  88. *
  89. * @param {Object} state - The state of the app.
  90. * @returns {Object}
  91. */
  92. export function getContentSharingTrack(state: Object): Object {
  93. return state['features/prejoin']?.contentSharingTrack;
  94. }
  95. /**
  96. * Returns the text for the prejoin status bar.
  97. *
  98. * @param {Object} state - The state of the app.
  99. * @returns {string}
  100. */
  101. export function getDeviceStatusText(state: Object): string {
  102. return state['features/prejoin']?.deviceStatusText;
  103. }
  104. /**
  105. * Returns the type of the prejoin status bar: 'ok'|'warning'.
  106. *
  107. * @param {Object} state - The state of the app.
  108. * @returns {string}
  109. */
  110. export function getDeviceStatusType(state: Object): string {
  111. return state['features/prejoin']?.deviceStatusType;
  112. }
  113. /**
  114. * Returns the 'conferenceUrl' used for dialing out.
  115. *
  116. * @param {Object} state - The state of the app.
  117. * @returns {string}
  118. */
  119. export function getDialOutConferenceUrl(state: Object): string {
  120. return `${getRoomName(state)}@${state['features/base/config'].hosts.muc}`;
  121. }
  122. /**
  123. * Selector for getting the dial out country.
  124. *
  125. * @param {Object} state - The state of the app.
  126. * @returns {Object}
  127. */
  128. export function getDialOutCountry(state: Object): Object {
  129. return state['features/prejoin'].dialOutCountry;
  130. }
  131. /**
  132. * Selector for getting the dial out number (without prefix).
  133. *
  134. * @param {Object} state - The state of the app.
  135. * @returns {string}
  136. */
  137. export function getDialOutNumber(state: Object): string {
  138. return state['features/prejoin'].dialOutNumber;
  139. }
  140. /**
  141. * Selector for getting the dial out status while calling.
  142. *
  143. * @param {Object} state - The state of the app.
  144. * @returns {string}
  145. */
  146. export function getDialOutStatus(state: Object): string {
  147. return state['features/prejoin'].dialOutStatus;
  148. }
  149. /**
  150. * Returns the full dial out number (containing country code and +).
  151. *
  152. * @param {Object} state - The state of the app.
  153. * @returns {string}
  154. */
  155. export function getFullDialOutNumber(state: Object): string {
  156. const dialOutNumber = getDialOutNumber(state);
  157. const country = getDialOutCountry(state);
  158. return `+${country.dialCode}${dialOutNumber}`;
  159. }
  160. /**
  161. * Selector for getting the prejoin video track.
  162. *
  163. * @param {Object} state - The state of the app.
  164. * @returns {Object}
  165. */
  166. export function getVideoTrack(state: Object): Object {
  167. return state['features/prejoin']?.videoTrack;
  168. }
  169. /**
  170. * Selector for getting the mute status of the prejoin audio.
  171. *
  172. * @param {Object} state - The state of the app.
  173. * @returns {boolean}
  174. */
  175. export function isPrejoinAudioMuted(state: Object): boolean {
  176. return state['features/prejoin']?.audioMuted;
  177. }
  178. /**
  179. * Selector for getting the mute status of the prejoin video.
  180. *
  181. * @param {Object} state - The state of the app.
  182. * @returns {boolean}
  183. */
  184. export function isPrejoinVideoMuted(state: Object): boolean {
  185. return state['features/prejoin']?.videoMuted;
  186. }
  187. /**
  188. * Selector for getting the error if any while creating streams.
  189. *
  190. * @param {Object} state - The state of the app.
  191. * @returns {string}
  192. */
  193. export function getRawError(state: Object): string {
  194. return state['features/prejoin']?.rawError;
  195. }
  196. /**
  197. * Selector for getting state of the prejoin audio.
  198. *
  199. * @param {Object} state - The state of the app.
  200. * @returns {boolean}
  201. */
  202. export function isAudioDisabled(state: Object): Object {
  203. return state['features/prejoin']?.audioDisabled;
  204. }
  205. /**
  206. * Selector for getting state of the prejoin video.
  207. *
  208. * @param {Object} state - The state of the app.
  209. * @returns {boolean}
  210. */
  211. export function isPrejoinVideoDisabled(state: Object): Object {
  212. return state['features/prejoin']?.videoDisabled;
  213. }
  214. /**
  215. * Selector for getting the visiblity state for the 'JoinByPhoneDialog'.
  216. *
  217. * @param {Object} state - The state of the app.
  218. * @returns {boolean}
  219. */
  220. export function isJoinByPhoneDialogVisible(state: Object): boolean {
  221. return state['features/prejoin']?.showJoinByPhoneDialog;
  222. }
  223. /**
  224. * Returns true if the prejoin page is enabled and no flag
  225. * to bypass showing the page is present.
  226. *
  227. * @param {Object} state - The state of the app.
  228. * @returns {boolean}
  229. */
  230. export function isPrejoinPageEnabled(state: Object): boolean {
  231. return state['features/base/config'].prejoinPageEnabled
  232. && !state['features/base/settings'].userSelectedSkipPrejoin;
  233. }
  234. /**
  235. * Returns true if the prejoin page is visible & active.
  236. *
  237. * @param {Object} state - The state of the app.
  238. * @returns {boolean}
  239. */
  240. export function isPrejoinPageVisible(state: Object): boolean {
  241. return isPrejoinPageEnabled(state) && state['features/prejoin']?.showPrejoin;
  242. }