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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // @flow
  2. /**
  3. * Mutes or unmutes a track.
  4. *
  5. * @param {Object} track - The track to be configured.
  6. * @param {boolean} shouldMute - If it should mute or not.
  7. * @returns {Promise<void>}
  8. */
  9. function applyMuteOptionsToTrack(track, shouldMute) {
  10. if (track.isMuted() === shouldMute) {
  11. return;
  12. }
  13. if (shouldMute) {
  14. return track.mute();
  15. }
  16. return track.unmute();
  17. }
  18. /**
  19. * Selector for the visibility of the 'join by phone' buttons.
  20. *
  21. * @param {Object} state - The state of the app.
  22. * @returns {boolean}
  23. */
  24. export function areJoinByPhoneButtonsVisible(state: Object): boolean {
  25. return state['features/prejoin'].buttonsVisible;
  26. }
  27. /**
  28. * Selector for determining if the device status strip is visible or not.
  29. *
  30. * @param {Object} state - The state of the app.
  31. * @returns {boolean}
  32. */
  33. export function isDeviceStatusVisible(state: Object): boolean {
  34. return !((isAudioDisabled(state) && isPrejoinVideoDisabled(state))
  35. || (isPrejoinAudioMuted(state) && isPrejoinVideoMuted(state)));
  36. }
  37. /**
  38. * Selector for getting the active video/content sharing track.
  39. *
  40. * @param {Object} state - The state of the app.
  41. * @returns {boolean}
  42. */
  43. export function getActiveVideoTrack(state: Object): Object {
  44. const track = getVideoTrack(state) || getContentSharingTrack(state);
  45. if (track && track.isActive()) {
  46. return track;
  47. }
  48. return null;
  49. }
  50. /**
  51. * Returns a list with all the prejoin tracks configured according to
  52. * user's preferences.
  53. *
  54. * @param {Object} state - The state of the app.
  55. * @returns {Promise<Object[]>}
  56. */
  57. export async function getAllPrejoinConfiguredTracks(state: Object): Promise<Object[]> {
  58. const tracks = [];
  59. const audioTrack = getAudioTrack(state);
  60. const videoTrack = getVideoTrack(state);
  61. const csTrack = getContentSharingTrack(state);
  62. if (csTrack) {
  63. tracks.push(csTrack);
  64. } else if (videoTrack) {
  65. await applyMuteOptionsToTrack(videoTrack, isPrejoinVideoMuted(state));
  66. tracks.push(videoTrack);
  67. }
  68. if (audioTrack) {
  69. await applyMuteOptionsToTrack(audioTrack, isPrejoinAudioMuted(state));
  70. isPrejoinAudioMuted(state) && audioTrack.mute();
  71. tracks.push(audioTrack);
  72. }
  73. return tracks;
  74. }
  75. /**
  76. * Selector for getting the prejoin audio track.
  77. *
  78. * @param {Object} state - The state of the app.
  79. * @returns {Object}
  80. */
  81. export function getAudioTrack(state: Object): Object {
  82. return state['features/prejoin'].audioTrack;
  83. }
  84. /**
  85. * Selector for getting the prejoin content sharing track.
  86. *
  87. * @param {Object} state - The state of the app.
  88. * @returns {Object}
  89. */
  90. export function getContentSharingTrack(state: Object): Object {
  91. return state['features/prejoin'].contentSharingTrack;
  92. }
  93. /**
  94. * Returns the text for the prejoin status bar.
  95. *
  96. * @param {Object} state - The state of the app.
  97. * @returns {string}
  98. */
  99. export function getDeviceStatusText(state: Object): string {
  100. return state['features/prejoin'].deviceStatusText;
  101. }
  102. /**
  103. * Returns the type of the prejoin status bar: 'ok'|'warning'.
  104. *
  105. * @param {Object} state - The state of the app.
  106. * @returns {string}
  107. */
  108. export function getDeviceStatusType(state: Object): string {
  109. return state['features/prejoin'].deviceStatusType;
  110. }
  111. /**
  112. * Selector for getting the prejoin video track.
  113. *
  114. * @param {Object} state - The state of the app.
  115. * @returns {Object}
  116. */
  117. export function getVideoTrack(state: Object): Object {
  118. return state['features/prejoin'].videoTrack;
  119. }
  120. /**
  121. * Selector for getting the mute status of the prejoin audio.
  122. *
  123. * @param {Object} state - The state of the app.
  124. * @returns {boolean}
  125. */
  126. export function isPrejoinAudioMuted(state: Object): boolean {
  127. return state['features/prejoin'].audioMuted;
  128. }
  129. /**
  130. * Selector for getting the name that the user filled while configuring.
  131. *
  132. * @param {Object} state - The state of the app.
  133. * @returns {boolean}
  134. */
  135. export function getPrejoinName(state: Object): string {
  136. return state['features/prejoin'].name;
  137. }
  138. /**
  139. * Selector for getting the mute status of the prejoin video.
  140. *
  141. * @param {Object} state - The state of the app.
  142. * @returns {boolean}
  143. */
  144. export function isPrejoinVideoMuted(state: Object): boolean {
  145. return state['features/prejoin'].videoMuted;
  146. }
  147. /**
  148. * Selector for getting the error if any while creating streams.
  149. *
  150. * @param {Object} state - The state of the app.
  151. * @returns {string}
  152. */
  153. export function getRawError(state: Object): string {
  154. return state['features/prejoin'].rawError;
  155. }
  156. /**
  157. * Selector for getting state of the prejoin audio.
  158. *
  159. * @param {Object} state - The state of the app.
  160. * @returns {boolean}
  161. */
  162. export function isAudioDisabled(state: Object): Object {
  163. return state['features/prejoin'].audioDisabled;
  164. }
  165. /**
  166. * Selector for getting state of the prejoin video.
  167. *
  168. * @param {Object} state - The state of the app.
  169. * @returns {boolean}
  170. */
  171. export function isPrejoinVideoDisabled(state: Object): Object {
  172. return state['features/prejoin'].videoDisabled;
  173. }
  174. /**
  175. * Selector for getting the visiblity state for the 'JoinByPhoneDialog'.
  176. *
  177. * @param {Object} state - The state of the app.
  178. * @returns {boolean}
  179. */
  180. export function isJoinByPhoneDialogVisible(state: Object): boolean {
  181. return state['features/prejoin'].showJoinByPhoneDialog;
  182. }
  183. /**
  184. * Returns true if the prejoin page is enabled and no flag
  185. * to bypass showing the page is present.
  186. *
  187. * @param {Object} state - The state of the app.
  188. * @returns {boolean}
  189. */
  190. export function isPrejoinPageEnabled(state: Object): boolean {
  191. return state['features/base/config'].prejoinPageEnabled;
  192. }
  193. /**
  194. * Returns true if the prejoin page is visible & active.
  195. *
  196. * @param {Object} state - The state of the app.
  197. * @returns {boolean}
  198. */
  199. export function isPrejoinPageVisible(state: Object): boolean {
  200. return isPrejoinPageEnabled(state) && state['features/prejoin'].showPrejoin;
  201. }