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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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. }
  124. };
  125. /**
  126. * Setup some UI event listeners.
  127. */
  128. UI.registerListeners
  129. = () => UIListeners.forEach((value, key) => UI.addListener(key, value));
  130. /**
  131. * Setup some DOM event listeners.
  132. */
  133. UI.bindEvents = () => {
  134. /**
  135. *
  136. */
  137. function onResize() {
  138. VideoLayout.onResize();
  139. }
  140. // Resize and reposition videos in full screen mode.
  141. $(document).on(
  142. 'webkitfullscreenchange mozfullscreenchange fullscreenchange',
  143. onResize);
  144. $(window).resize(onResize);
  145. };
  146. /**
  147. * Unbind some DOM event listeners.
  148. */
  149. UI.unbindEvents = () => {
  150. $(document).off(
  151. 'webkitfullscreenchange mozfullscreenchange fullscreenchange');
  152. $(window).off('resize');
  153. };
  154. /**
  155. * Setup and show Etherpad.
  156. * @param {string} name etherpad id
  157. */
  158. UI.initEtherpad = name => {
  159. if (etherpadManager || !config.etherpad_base || !name) {
  160. return;
  161. }
  162. logger.log('Etherpad is enabled');
  163. etherpadManager = new EtherpadManager(eventEmitter);
  164. const url = new URL(name, config.etherpad_base);
  165. APP.store.dispatch(setDocumentUrl(url.toString()));
  166. if (config.openSharedDocumentOnJoin) {
  167. etherpadManager.toggleEtherpad();
  168. }
  169. };
  170. /**
  171. * Returns the shared document manager object.
  172. * @return {EtherpadManager} the shared document manager object
  173. */
  174. UI.getSharedDocumentManager = () => etherpadManager;
  175. /**
  176. * Show user on UI.
  177. * @param {JitsiParticipant} user
  178. */
  179. UI.addUser = function(user) {
  180. const status = user.getStatus();
  181. if (status) {
  182. // FIXME: move updateUserStatus in participantPresenceChanged action
  183. UI.updateUserStatus(user, status);
  184. }
  185. };
  186. /**
  187. * Updates the user status.
  188. *
  189. * @param {JitsiParticipant} user - The user which status we need to update.
  190. * @param {string} status - The new status.
  191. */
  192. UI.updateUserStatus = (user, status) => {
  193. const reduxState = APP.store.getState() || {};
  194. const { calleeInfoVisible } = reduxState['features/invite'] || {};
  195. // We hide status updates when join/leave notifications are disabled,
  196. // as jigasi is the component with statuses and they are seen as join/leave notifications.
  197. if (!status || calleeInfoVisible || joinLeaveNotificationsDisabled()) {
  198. return;
  199. }
  200. const displayName = user.getDisplayName();
  201. messageHandler.participantNotification(
  202. displayName,
  203. '',
  204. 'connected',
  205. 'dialOut.statusMessage',
  206. { status: UIUtil.escapeHtml(status) });
  207. };
  208. /**
  209. * Toggles filmstrip.
  210. */
  211. UI.toggleFilmstrip = function() {
  212. const { visible } = APP.store.getState()['features/filmstrip'];
  213. APP.store.dispatch(setFilmstripVisible(!visible));
  214. };
  215. /**
  216. * Toggles the visibility of the chat panel.
  217. */
  218. UI.toggleChat = () => APP.store.dispatch(toggleChat());
  219. /**
  220. * Sets muted audio state for participant
  221. */
  222. UI.setAudioMuted = function(id) {
  223. // FIXME: Maybe this can be removed!
  224. if (APP.conference.isLocalId(id)) {
  225. APP.conference.updateAudioIconEnabled();
  226. }
  227. };
  228. /**
  229. * Sets muted video state for participant
  230. */
  231. UI.setVideoMuted = function(id) {
  232. VideoLayout._updateLargeVideoIfDisplayed(id, true);
  233. if (APP.conference.isLocalId(id)) {
  234. APP.conference.updateVideoIconEnabled();
  235. }
  236. };
  237. UI.updateLargeVideo = (id, forceUpdate) => VideoLayout.updateLargeVideo(id, forceUpdate);
  238. /**
  239. * Adds a listener that would be notified on the given type of event.
  240. *
  241. * @param type the type of the event we're listening for
  242. * @param listener a function that would be called when notified
  243. */
  244. UI.addListener = function(type, listener) {
  245. eventEmitter.on(type, listener);
  246. };
  247. /**
  248. * Removes the all listeners for all events.
  249. *
  250. * @returns {void}
  251. */
  252. UI.removeAllListeners = function() {
  253. eventEmitter.removeAllListeners();
  254. };
  255. /**
  256. * Removes the given listener for the given type of event.
  257. *
  258. * @param type the type of the event we're listening for
  259. * @param listener the listener we want to remove
  260. */
  261. UI.removeListener = function(type, listener) {
  262. eventEmitter.removeListener(type, listener);
  263. };
  264. /**
  265. * Emits the event of given type by specifying the parameters in options.
  266. *
  267. * @param type the type of the event we're emitting
  268. * @param options the parameters for the event
  269. */
  270. UI.emitEvent = (type, ...options) => eventEmitter.emit(type, ...options);
  271. // Used by torture.
  272. UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  273. // Used by torture.
  274. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  275. /**
  276. * Updates the displayed avatar for participant.
  277. *
  278. * @param {string} id - User id whose avatar should be updated.
  279. * @param {string} avatarURL - The URL to avatar image to display.
  280. * @returns {void}
  281. */
  282. UI.refreshAvatarDisplay = function(id) {
  283. VideoLayout.changeUserAvatar(id);
  284. };
  285. /**
  286. * Notify user that connection failed.
  287. * @param {string} stropheErrorMsg raw Strophe error message
  288. */
  289. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  290. let descriptionKey;
  291. let descriptionArguments;
  292. if (stropheErrorMsg) {
  293. descriptionKey = 'dialog.connectErrorWithMsg';
  294. descriptionArguments = { msg: stropheErrorMsg };
  295. } else {
  296. descriptionKey = 'dialog.connectError';
  297. }
  298. messageHandler.showError({
  299. descriptionArguments,
  300. descriptionKey,
  301. titleKey: 'connection.CONNFAIL'
  302. });
  303. };
  304. /**
  305. * Notify user that maximum users limit has been reached.
  306. */
  307. UI.notifyMaxUsersLimitReached = function() {
  308. messageHandler.showError({
  309. hideErrorSupportLink: true,
  310. descriptionKey: 'dialog.maxUsersLimitReached',
  311. titleKey: 'dialog.maxUsersLimitReachedTitle'
  312. });
  313. };
  314. /**
  315. * Notify user that he was automatically muted when joned the conference.
  316. */
  317. UI.notifyInitiallyMuted = function() {
  318. messageHandler.participantNotification(
  319. null,
  320. 'notify.mutedTitle',
  321. 'connected',
  322. 'notify.muted',
  323. null);
  324. };
  325. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  326. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  327. };
  328. /**
  329. * Update audio level visualization for specified user.
  330. * @param {string} id user id
  331. * @param {number} lvl audio level
  332. */
  333. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  334. UI.notifyTokenAuthFailed = function() {
  335. messageHandler.showError({
  336. descriptionKey: 'dialog.tokenAuthFailed',
  337. titleKey: 'dialog.tokenAuthFailedTitle'
  338. });
  339. };
  340. UI.notifyFocusDisconnected = function(focus, retrySec) {
  341. messageHandler.participantNotification(
  342. null, 'notify.focus',
  343. 'disconnected', 'notify.focusFail',
  344. { component: focus,
  345. ms: retrySec }
  346. );
  347. };
  348. /**
  349. * Update list of available physical devices.
  350. */
  351. UI.onAvailableDevicesChanged = function() {
  352. APP.conference.updateAudioIconEnabled();
  353. APP.conference.updateVideoIconEnabled();
  354. };
  355. /**
  356. * Returns the id of the current video shown on large.
  357. * Currently used by tests (torture).
  358. */
  359. UI.getLargeVideoID = function() {
  360. return VideoLayout.getLargeVideoID();
  361. };
  362. /**
  363. * Returns the current video shown on large.
  364. * Currently used by tests (torture).
  365. */
  366. UI.getLargeVideo = function() {
  367. return VideoLayout.getLargeVideo();
  368. };
  369. /**
  370. * Show shared video.
  371. * @param {string} id the id of the sender of the command
  372. * @param {string} url video url
  373. * @param {string} attributes
  374. */
  375. UI.onSharedVideoStart = function(id, url, attributes) {
  376. if (sharedVideoManager) {
  377. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  378. }
  379. };
  380. /**
  381. * Update shared video.
  382. * @param {string} id the id of the sender of the command
  383. * @param {string} url video url
  384. * @param {string} attributes
  385. */
  386. UI.onSharedVideoUpdate = function(id, url, attributes) {
  387. if (sharedVideoManager) {
  388. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  389. }
  390. };
  391. /**
  392. * Stop showing shared video.
  393. * @param {string} id the id of the sender of the command
  394. * @param {string} attributes
  395. */
  396. UI.onSharedVideoStop = function(id, attributes) {
  397. if (sharedVideoManager) {
  398. sharedVideoManager.onSharedVideoStop(id, attributes);
  399. }
  400. };
  401. /**
  402. * Show shared video.
  403. * @param {string} url video url
  404. */
  405. UI.startSharedVideoEmitter = function(url) {
  406. if (sharedVideoManager) {
  407. sharedVideoManager.startSharedVideoEmitter(url);
  408. }
  409. };
  410. /**
  411. * Stop shared video.
  412. */
  413. UI.stopSharedVideoEmitter = function() {
  414. if (sharedVideoManager) {
  415. sharedVideoManager.stopSharedVideoEmitter();
  416. }
  417. };
  418. // TODO: Export every function separately. For now there is no point of doing
  419. // this because we are importing everything.
  420. export default UI;