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 10KB

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