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.

UI.js 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. /* global APP, config */
  2. const UI = {};
  3. import Logger from '@jitsi/logger';
  4. import EventEmitter from 'events';
  5. import { isMobileBrowser } from '../../react/features/base/environment/utils';
  6. import { setColorAlpha } from '../../react/features/base/util';
  7. import { setDocumentUrl } from '../../react/features/etherpad';
  8. import { setFilmstripVisible } from '../../react/features/filmstrip';
  9. import {
  10. NOTIFICATION_TIMEOUT_TYPE,
  11. joinLeaveNotificationsDisabled,
  12. setNotificationsEnabled,
  13. showNotification
  14. } from '../../react/features/notifications';
  15. import {
  16. dockToolbox,
  17. setToolboxEnabled,
  18. showToolbox
  19. } from '../../react/features/toolbox/actions.web';
  20. import UIEvents from '../../service/UI/UIEvents';
  21. import EtherpadManager from './etherpad/Etherpad';
  22. import messageHandler from './util/MessageHandler';
  23. import UIUtil from './util/UIUtil';
  24. import VideoLayout from './videolayout/VideoLayout';
  25. const logger = Logger.getLogger(__filename);
  26. UI.messageHandler = messageHandler;
  27. const eventEmitter = new EventEmitter();
  28. UI.eventEmitter = eventEmitter;
  29. let etherpadManager;
  30. const UIListeners = new Map([
  31. [
  32. UIEvents.ETHERPAD_CLICKED,
  33. () => etherpadManager && etherpadManager.toggleEtherpad()
  34. ], [
  35. UIEvents.TOGGLE_FILMSTRIP,
  36. () => UI.toggleFilmstrip()
  37. ]
  38. ]);
  39. /**
  40. * Indicates if we're currently in full screen mode.
  41. *
  42. * @return {boolean} {true} to indicate that we're currently in full screen
  43. * mode, {false} otherwise
  44. */
  45. UI.isFullScreen = function() {
  46. return UIUtil.isFullScreen();
  47. };
  48. /**
  49. * Notify user that server has shut down.
  50. */
  51. UI.notifyGracefulShutdown = function() {
  52. messageHandler.showError({
  53. descriptionKey: 'dialog.gracefulShutdown',
  54. titleKey: 'dialog.serviceUnavailable'
  55. });
  56. };
  57. /**
  58. * Notify user that reservation error happened.
  59. */
  60. UI.notifyReservationError = function(code, msg) {
  61. messageHandler.showError({
  62. descriptionArguments: {
  63. code,
  64. msg
  65. },
  66. descriptionKey: 'dialog.reservationErrorMsg',
  67. titleKey: 'dialog.reservationError'
  68. });
  69. };
  70. /**
  71. * Initialize conference UI.
  72. */
  73. UI.initConference = function() {
  74. UI.showToolbar();
  75. };
  76. /**
  77. * Starts the UI module and initializes all related components.
  78. *
  79. * @returns {boolean} true if the UI is ready and the conference should be
  80. * established, false - otherwise (for example in the case of welcome page)
  81. */
  82. UI.start = function() {
  83. VideoLayout.initLargeVideo();
  84. // Do not animate the video area on UI start (second argument passed into
  85. // resizeVideoArea) because the animation is not visible anyway. Plus with
  86. // the current dom layout, the quality label is part of the video layout and
  87. // will be seen animating in.
  88. VideoLayout.resizeVideoArea();
  89. if (isMobileBrowser()) {
  90. document.body.classList.add('mobile-browser');
  91. } else {
  92. document.body.classList.add('desktop-browser');
  93. }
  94. if (config.backgroundAlpha !== undefined) {
  95. const backgroundColor = getComputedStyle(document.body).getPropertyValue('background-color');
  96. const alphaColor = setColorAlpha(backgroundColor, config.backgroundAlpha);
  97. document.body.style.backgroundColor = alphaColor;
  98. }
  99. if (config.iAmRecorder) {
  100. // in case of iAmSipGateway keep local video visible
  101. if (!config.iAmSipGateway) {
  102. APP.store.dispatch(setNotificationsEnabled(false));
  103. }
  104. APP.store.dispatch(setToolboxEnabled(false));
  105. }
  106. };
  107. /**
  108. * Setup some UI event listeners.
  109. */
  110. UI.registerListeners
  111. = () => UIListeners.forEach((value, key) => UI.addListener(key, value));
  112. /**
  113. *
  114. */
  115. function onResize() {
  116. VideoLayout.onResize();
  117. }
  118. /**
  119. * Setup some DOM event listeners.
  120. */
  121. UI.bindEvents = () => {
  122. // Resize and reposition videos in full screen mode.
  123. document.addEventListener('webkitfullscreenchange', onResize);
  124. document.addEventListener('mozfullscreenchange', onResize);
  125. document.addEventListener('fullscreenchange', onResize);
  126. window.addEventListener('resize', onResize);
  127. };
  128. /**
  129. * Unbind some DOM event listeners.
  130. */
  131. UI.unbindEvents = () => {
  132. document.removeEventListener('webkitfullscreenchange', onResize);
  133. document.removeEventListener('mozfullscreenchange', onResize);
  134. document.removeEventListener('fullscreenchange', onResize);
  135. window.removeEventListener('resize', onResize);
  136. };
  137. /**
  138. * Setup and show Etherpad.
  139. * @param {string} name etherpad id
  140. */
  141. UI.initEtherpad = name => {
  142. if (etherpadManager || !config.etherpad_base || !name) {
  143. return;
  144. }
  145. logger.log('Etherpad is enabled');
  146. etherpadManager = new EtherpadManager(eventEmitter);
  147. const url = new URL(name, config.etherpad_base);
  148. APP.store.dispatch(setDocumentUrl(url.toString()));
  149. if (config.openSharedDocumentOnJoin) {
  150. etherpadManager.toggleEtherpad();
  151. }
  152. };
  153. /**
  154. * Returns the shared document manager object.
  155. * @return {EtherpadManager} the shared document manager object
  156. */
  157. UI.getSharedDocumentManager = () => etherpadManager;
  158. /**
  159. * Show user on UI.
  160. * @param {JitsiParticipant} user
  161. */
  162. UI.addUser = function(user) {
  163. const status = user.getStatus();
  164. if (status) {
  165. // FIXME: move updateUserStatus in participantPresenceChanged action
  166. UI.updateUserStatus(user, status);
  167. }
  168. };
  169. /**
  170. * Updates the user status.
  171. *
  172. * @param {JitsiParticipant} user - The user which status we need to update.
  173. * @param {string} status - The new status.
  174. */
  175. UI.updateUserStatus = (user, status) => {
  176. const reduxState = APP.store.getState() || {};
  177. const { calleeInfoVisible } = reduxState['features/invite'] || {};
  178. // We hide status updates when join/leave notifications are disabled,
  179. // as jigasi is the component with statuses and they are seen as join/leave notifications.
  180. if (!status || calleeInfoVisible || joinLeaveNotificationsDisabled()) {
  181. return;
  182. }
  183. const displayName = user.getDisplayName();
  184. APP.store.dispatch(showNotification({
  185. titleKey: `${displayName} connected`,
  186. descriptionKey: 'dialOut.statusMessage'
  187. }, NOTIFICATION_TIMEOUT_TYPE.SHORT));
  188. };
  189. /**
  190. * Toggles filmstrip.
  191. */
  192. UI.toggleFilmstrip = function() {
  193. const { visible } = APP.store.getState()['features/filmstrip'];
  194. APP.store.dispatch(setFilmstripVisible(!visible));
  195. };
  196. /**
  197. * Sets muted audio state for participant
  198. */
  199. UI.setAudioMuted = function(id) {
  200. // FIXME: Maybe this can be removed!
  201. if (APP.conference.isLocalId(id)) {
  202. APP.conference.updateAudioIconEnabled();
  203. }
  204. };
  205. /**
  206. * Sets muted video state for participant
  207. */
  208. UI.setVideoMuted = function(id) {
  209. VideoLayout._updateLargeVideoIfDisplayed(id, true);
  210. if (APP.conference.isLocalId(id)) {
  211. APP.conference.updateVideoIconEnabled();
  212. }
  213. };
  214. UI.updateLargeVideo = (id, forceUpdate) => VideoLayout.updateLargeVideo(id, forceUpdate);
  215. /**
  216. * Adds a listener that would be notified on the given type of event.
  217. *
  218. * @param type the type of the event we're listening for
  219. * @param listener a function that would be called when notified
  220. */
  221. UI.addListener = function(type, listener) {
  222. eventEmitter.on(type, listener);
  223. };
  224. /**
  225. * Removes the all listeners for all events.
  226. *
  227. * @returns {void}
  228. */
  229. UI.removeAllListeners = function() {
  230. eventEmitter.removeAllListeners();
  231. };
  232. /**
  233. * Emits the event of given type by specifying the parameters in options.
  234. *
  235. * @param type the type of the event we're emitting
  236. * @param options the parameters for the event
  237. */
  238. UI.emitEvent = (type, ...options) => eventEmitter.emit(type, ...options);
  239. // Used by torture.
  240. UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  241. // Used by torture.
  242. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  243. /**
  244. * Notify user that connection failed.
  245. * @param {string} stropheErrorMsg raw Strophe error message
  246. */
  247. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  248. let descriptionKey;
  249. let descriptionArguments;
  250. if (stropheErrorMsg) {
  251. descriptionKey = 'dialog.connectErrorWithMsg';
  252. descriptionArguments = { msg: stropheErrorMsg };
  253. } else {
  254. descriptionKey = 'dialog.connectError';
  255. }
  256. messageHandler.showError({
  257. descriptionArguments,
  258. descriptionKey,
  259. titleKey: 'connection.CONNFAIL'
  260. });
  261. };
  262. /**
  263. * Notify user that maximum users limit has been reached.
  264. */
  265. UI.notifyMaxUsersLimitReached = function() {
  266. messageHandler.showError({
  267. hideErrorSupportLink: true,
  268. descriptionKey: 'dialog.maxUsersLimitReached',
  269. titleKey: 'dialog.maxUsersLimitReachedTitle'
  270. });
  271. };
  272. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  273. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  274. };
  275. /**
  276. * Update audio level visualization for specified user.
  277. * @param {string} id user id
  278. * @param {number} lvl audio level
  279. */
  280. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  281. UI.notifyTokenAuthFailed = function() {
  282. messageHandler.showError({
  283. descriptionKey: 'dialog.tokenAuthFailed',
  284. titleKey: 'dialog.tokenAuthFailedTitle'
  285. });
  286. };
  287. /**
  288. * Update list of available physical devices.
  289. */
  290. UI.onAvailableDevicesChanged = function() {
  291. APP.conference.updateAudioIconEnabled();
  292. APP.conference.updateVideoIconEnabled();
  293. };
  294. /**
  295. * Returns the id of the current video shown on large.
  296. * Currently used by tests (torture).
  297. */
  298. UI.getLargeVideoID = function() {
  299. return VideoLayout.getLargeVideoID();
  300. };
  301. /**
  302. * Returns the current video shown on large.
  303. * Currently used by tests (torture).
  304. */
  305. UI.getLargeVideo = function() {
  306. return VideoLayout.getLargeVideo();
  307. };
  308. // TODO: Export every function separately. For now there is no point of doing
  309. // this because we are importing everything.
  310. export default UI;