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

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