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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. /* global APP, $, config, interfaceConfig */
  2. const logger = require('jitsi-meet-logger').getLogger(__filename);
  3. const UI = {};
  4. import Chat from './side_pannels/chat/Chat';
  5. import SidePanels from './side_pannels/SidePanels';
  6. import SideContainerToggler from './side_pannels/SideContainerToggler';
  7. import messageHandler from './util/MessageHandler';
  8. import UIUtil from './util/UIUtil';
  9. import UIEvents from '../../service/UI/UIEvents';
  10. import EtherpadManager from './etherpad/Etherpad';
  11. import SharedVideoManager from './shared_video/SharedVideo';
  12. import Recording from './recording/Recording';
  13. import VideoLayout from './videolayout/VideoLayout';
  14. import Filmstrip from './videolayout/Filmstrip';
  15. import Profile from './side_pannels/profile/Profile';
  16. import {
  17. openDeviceSelectionDialog
  18. } from '../../react/features/device-selection';
  19. import { updateDeviceList } from '../../react/features/base/devices';
  20. import { JitsiTrackErrors } from '../../react/features/base/lib-jitsi-meet';
  21. import {
  22. getLocalParticipant,
  23. participantPresenceChanged,
  24. showParticipantJoinedNotification
  25. } from '../../react/features/base/participants';
  26. import { destroyLocalTracks } from '../../react/features/base/tracks';
  27. import { openDisplayNamePrompt } from '../../react/features/display-name';
  28. import { setEtherpadHasInitialzied } from '../../react/features/etherpad';
  29. import {
  30. setNotificationsEnabled,
  31. showWarningNotification
  32. } from '../../react/features/notifications';
  33. import {
  34. dockToolbox,
  35. showToolbox
  36. } from '../../react/features/toolbox';
  37. const EventEmitter = require('events');
  38. UI.messageHandler = messageHandler;
  39. import FollowMe from '../FollowMe';
  40. const eventEmitter = new EventEmitter();
  41. UI.eventEmitter = eventEmitter;
  42. let etherpadManager;
  43. let sharedVideoManager;
  44. let followMeHandler;
  45. const JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP = {
  46. microphone: {},
  47. camera: {}
  48. };
  49. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  50. .camera[JitsiTrackErrors.UNSUPPORTED_RESOLUTION]
  51. = 'dialog.cameraUnsupportedResolutionError';
  52. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[JitsiTrackErrors.GENERAL]
  53. = 'dialog.cameraUnknownError';
  54. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[JitsiTrackErrors.PERMISSION_DENIED]
  55. = 'dialog.cameraPermissionDeniedError';
  56. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[JitsiTrackErrors.NOT_FOUND]
  57. = 'dialog.cameraNotFoundError';
  58. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[JitsiTrackErrors.CONSTRAINT_FAILED]
  59. = 'dialog.cameraConstraintFailedError';
  60. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  61. .camera[JitsiTrackErrors.NO_DATA_FROM_SOURCE]
  62. = 'dialog.cameraNotSendingData';
  63. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[JitsiTrackErrors.GENERAL]
  64. = 'dialog.micUnknownError';
  65. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  66. .microphone[JitsiTrackErrors.PERMISSION_DENIED]
  67. = 'dialog.micPermissionDeniedError';
  68. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[JitsiTrackErrors.NOT_FOUND]
  69. = 'dialog.micNotFoundError';
  70. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  71. .microphone[JitsiTrackErrors.CONSTRAINT_FAILED]
  72. = 'dialog.micConstraintFailedError';
  73. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  74. .microphone[JitsiTrackErrors.NO_DATA_FROM_SOURCE]
  75. = 'dialog.micNotSendingData';
  76. const UIListeners = new Map([
  77. [
  78. UIEvents.ETHERPAD_CLICKED,
  79. () => etherpadManager && etherpadManager.toggleEtherpad()
  80. ], [
  81. UIEvents.SHARED_VIDEO_CLICKED,
  82. () => sharedVideoManager && sharedVideoManager.toggleSharedVideo()
  83. ], [
  84. UIEvents.TOGGLE_CHAT,
  85. () => UI.toggleChat()
  86. ], [
  87. UIEvents.TOGGLE_SETTINGS,
  88. () => {
  89. // Opening of device selection is special-cased as it is a dialog
  90. // opened through a button in settings and not directly displayed in
  91. // settings itself. As it is not useful to only have a settings menu
  92. // with a button to open a dialog, open the dialog directly instead.
  93. if (interfaceConfig.SETTINGS_SECTIONS.length === 1
  94. && UIUtil.isSettingEnabled('devices')) {
  95. APP.store.dispatch(openDeviceSelectionDialog());
  96. } else {
  97. UI.toggleSidePanel('settings_container');
  98. }
  99. }
  100. ], [
  101. UIEvents.TOGGLE_PROFILE,
  102. () => UI.toggleSidePanel('profile_container')
  103. ], [
  104. UIEvents.TOGGLE_FILMSTRIP,
  105. () => UI.handleToggleFilmstrip()
  106. ], [
  107. UIEvents.FOLLOW_ME_ENABLED,
  108. enabled => followMeHandler && followMeHandler.enableFollowMe(enabled)
  109. ]
  110. ]);
  111. /**
  112. * Indicates if we're currently in full screen mode.
  113. *
  114. * @return {boolean} {true} to indicate that we're currently in full screen
  115. * mode, {false} otherwise
  116. */
  117. UI.isFullScreen = function() {
  118. return UIUtil.isFullScreen();
  119. };
  120. /**
  121. * Returns true if the etherpad window is currently visible.
  122. * @returns {Boolean} - true if the etherpad window is currently visible.
  123. */
  124. UI.isEtherpadVisible = function() {
  125. return Boolean(etherpadManager && etherpadManager.isVisible());
  126. };
  127. /**
  128. * Returns true if there is a shared video which is being shown (?).
  129. * @returns {boolean} - true if there is a shared video which is being shown.
  130. */
  131. UI.isSharedVideoShown = function() {
  132. return Boolean(sharedVideoManager && sharedVideoManager.isSharedVideoShown);
  133. };
  134. /**
  135. * Notify user that server has shut down.
  136. */
  137. UI.notifyGracefulShutdown = function() {
  138. messageHandler.showError({
  139. descriptionKey: 'dialog.gracefulShutdown',
  140. titleKey: 'dialog.serviceUnavailable'
  141. });
  142. };
  143. /**
  144. * Notify user that reservation error happened.
  145. */
  146. UI.notifyReservationError = function(code, msg) {
  147. messageHandler.showError({
  148. descriptionArguments: {
  149. code,
  150. msg
  151. },
  152. descriptionKey: 'dialog.reservationErrorMsg',
  153. titleKey: 'dialog.reservationError'
  154. });
  155. };
  156. /**
  157. * Notify user that he has been kicked from the server.
  158. */
  159. UI.notifyKicked = function() {
  160. messageHandler.showError({
  161. hideErrorSupportLink: true,
  162. descriptionKey: 'dialog.kickMessage',
  163. titleKey: 'dialog.sessTerminated'
  164. });
  165. };
  166. /**
  167. * Notify user that conference was destroyed.
  168. * @param reason {string} the reason text
  169. */
  170. UI.notifyConferenceDestroyed = function(reason) {
  171. // FIXME: use Session Terminated from translation, but
  172. // 'reason' text comes from XMPP packet and is not translated
  173. messageHandler.showError({
  174. description: reason,
  175. titleKey: 'dialog.sessTerminated'
  176. });
  177. };
  178. /**
  179. * Show chat error.
  180. * @param err the Error
  181. * @param msg
  182. */
  183. UI.showChatError = function(err, msg) {
  184. if (!interfaceConfig.filmStripOnly) {
  185. Chat.chatAddError(err, msg);
  186. }
  187. };
  188. /**
  189. * Change nickname for the user.
  190. * @param {string} id user id
  191. * @param {string} displayName new nickname
  192. */
  193. UI.changeDisplayName = function(id, displayName) {
  194. VideoLayout.onDisplayNameChanged(id, displayName);
  195. if (APP.conference.isLocalId(id) || id === 'localVideoContainer') {
  196. Profile.changeDisplayName(displayName);
  197. Chat.setChatConversationMode(Boolean(displayName));
  198. }
  199. };
  200. /**
  201. * Shows/hides the indication about local connection being interrupted.
  202. *
  203. * @param {boolean} isInterrupted <tt>true</tt> if local connection is
  204. * currently in the interrupted state or <tt>false</tt> if the connection
  205. * is fine.
  206. */
  207. UI.showLocalConnectionInterrupted = function(isInterrupted) {
  208. VideoLayout.showLocalConnectionInterrupted(isInterrupted);
  209. };
  210. /**
  211. * Sets the "raised hand" status for a participant.
  212. *
  213. * @param {string} id - The id of the participant whose raised hand UI should
  214. * be updated.
  215. * @param {string} name - The name of the participant with the raised hand
  216. * update.
  217. * @param {boolean} raisedHandStatus - Whether the participant's hand is raised
  218. * or not.
  219. * @returns {void}
  220. */
  221. UI.setRaisedHandStatus = (id, name, raisedHandStatus) => {
  222. VideoLayout.setRaisedHandStatus(id, raisedHandStatus);
  223. if (raisedHandStatus) {
  224. messageHandler.participantNotification(
  225. name,
  226. 'notify.somebody',
  227. 'connected',
  228. 'notify.raisedHand');
  229. }
  230. };
  231. /**
  232. * Sets the local "raised hand" status.
  233. */
  234. UI.setLocalRaisedHandStatus
  235. = raisedHandStatus =>
  236. VideoLayout.setRaisedHandStatus(
  237. APP.conference.getMyUserId(),
  238. raisedHandStatus);
  239. /**
  240. * Initialize conference UI.
  241. */
  242. UI.initConference = function() {
  243. const { getState } = APP.store;
  244. const { email, id, name } = getLocalParticipant(getState);
  245. // Update default button states before showing the toolbar
  246. // if local role changes buttons state will be again updated.
  247. UI.updateLocalRole(APP.conference.isModerator);
  248. UI.showToolbar();
  249. const displayName = config.displayJids ? id : name;
  250. if (displayName) {
  251. UI.changeDisplayName('localVideoContainer', displayName);
  252. }
  253. // Make sure we configure our avatar id, before creating avatar for us
  254. if (email) {
  255. UI.setUserEmail(id, email);
  256. }
  257. // FollowMe attempts to copy certain aspects of the moderator's UI into the
  258. // other participants' UI. Consequently, it needs (1) read and write access
  259. // to the UI (depending on the moderator role of the local participant) and
  260. // (2) APP.conference as means of communication between the participants.
  261. followMeHandler = new FollowMe(APP.conference, UI);
  262. };
  263. UI.mucJoined = function() {
  264. VideoLayout.mucJoined();
  265. // Update local video now that a conference is joined a user ID should be
  266. // set.
  267. UI.changeDisplayName(
  268. 'localVideoContainer',
  269. APP.conference.getLocalDisplayName());
  270. };
  271. /** *
  272. * Handler for toggling filmstrip
  273. */
  274. UI.handleToggleFilmstrip = () => UI.toggleFilmstrip();
  275. /**
  276. * Returns the shared document manager object.
  277. * @return {EtherpadManager} the shared document manager object
  278. */
  279. UI.getSharedVideoManager = function() {
  280. return sharedVideoManager;
  281. };
  282. /**
  283. * Starts the UI module and initializes all related components.
  284. *
  285. * @returns {boolean} true if the UI is ready and the conference should be
  286. * established, false - otherwise (for example in the case of welcome page)
  287. */
  288. UI.start = function() {
  289. document.title = interfaceConfig.APP_NAME;
  290. // Set the defaults for prompt dialogs.
  291. $.prompt.setDefaults({ persistent: false });
  292. SideContainerToggler.init(eventEmitter);
  293. Filmstrip.init(eventEmitter);
  294. VideoLayout.init(eventEmitter);
  295. if (!interfaceConfig.filmStripOnly) {
  296. VideoLayout.initLargeVideo();
  297. }
  298. VideoLayout.resizeVideoArea(true, true);
  299. sharedVideoManager = new SharedVideoManager(eventEmitter);
  300. // eslint-disable-next-line no-negated-condition
  301. if (!interfaceConfig.filmStripOnly) {
  302. // Initialise the recording module.
  303. if (config.enableRecording) {
  304. Recording.init(eventEmitter, config.recordingType);
  305. }
  306. // Initialize side panels
  307. SidePanels.init(eventEmitter);
  308. } else {
  309. $('body').addClass('filmstrip-only');
  310. UI.showToolbar();
  311. Filmstrip.setFilmstripOnly();
  312. APP.store.dispatch(setNotificationsEnabled(false));
  313. }
  314. if (interfaceConfig.VERTICAL_FILMSTRIP) {
  315. $('body').addClass('vertical-filmstrip');
  316. }
  317. // TODO: remove this class once the old toolbar has been removed. This class
  318. // is set so that any CSS changes needed to adjust elements outside of the
  319. // new toolbar can be scoped to just the app with the new toolbar enabled.
  320. if (!interfaceConfig.filmStripOnly) {
  321. $('body').addClass('use-new-toolbox');
  322. }
  323. document.title = interfaceConfig.APP_NAME;
  324. };
  325. /**
  326. * Setup some UI event listeners.
  327. */
  328. UI.registerListeners
  329. = () => UIListeners.forEach((value, key) => UI.addListener(key, value));
  330. /**
  331. * Unregister some UI event listeners.
  332. */
  333. UI.unregisterListeners
  334. = () => UIListeners.forEach((value, key) => UI.removeListener(key, value));
  335. /**
  336. * Setup some DOM event listeners.
  337. */
  338. UI.bindEvents = () => {
  339. /**
  340. *
  341. */
  342. function onResize() {
  343. SideContainerToggler.resize();
  344. VideoLayout.resizeVideoArea();
  345. }
  346. // Resize and reposition videos in full screen mode.
  347. $(document).on(
  348. 'webkitfullscreenchange mozfullscreenchange fullscreenchange',
  349. onResize);
  350. $(window).resize(onResize);
  351. };
  352. /**
  353. * Unbind some DOM event listeners.
  354. */
  355. UI.unbindEvents = () => {
  356. $(document).off(
  357. 'webkitfullscreenchange mozfullscreenchange fullscreenchange');
  358. $(window).off('resize');
  359. };
  360. /**
  361. * Show local stream on UI.
  362. * @param {JitsiTrack} track stream to show
  363. */
  364. UI.addLocalStream = track => {
  365. switch (track.getType()) {
  366. case 'audio':
  367. // Local audio is not rendered so no further action is needed at this
  368. // point.
  369. break;
  370. case 'video':
  371. VideoLayout.changeLocalVideo(track);
  372. break;
  373. default:
  374. logger.error(`Unknown stream type: ${track.getType()}`);
  375. break;
  376. }
  377. };
  378. /**
  379. * Show remote stream on UI.
  380. * @param {JitsiTrack} track stream to show
  381. */
  382. UI.addRemoteStream = track => VideoLayout.onRemoteStreamAdded(track);
  383. /**
  384. * Removed remote stream from UI.
  385. * @param {JitsiTrack} track stream to remove
  386. */
  387. UI.removeRemoteStream = track => VideoLayout.onRemoteStreamRemoved(track);
  388. /**
  389. * Update chat subject.
  390. * @param {string} subject new chat subject
  391. */
  392. UI.setSubject = subject => Chat.setSubject(subject);
  393. /**
  394. * Setup and show Etherpad.
  395. * @param {string} name etherpad id
  396. */
  397. UI.initEtherpad = name => {
  398. if (etherpadManager || !config.etherpad_base || !name) {
  399. return;
  400. }
  401. logger.log('Etherpad is enabled');
  402. etherpadManager
  403. = new EtherpadManager(config.etherpad_base, name, eventEmitter);
  404. APP.store.dispatch(setEtherpadHasInitialzied());
  405. };
  406. /**
  407. * Returns the shared document manager object.
  408. * @return {EtherpadManager} the shared document manager object
  409. */
  410. UI.getSharedDocumentManager = () => etherpadManager;
  411. /**
  412. * Show user on UI.
  413. * @param {JitsiParticipant} user
  414. */
  415. UI.addUser = function(user) {
  416. const id = user.getId();
  417. const displayName = user.getDisplayName();
  418. const status = user.getStatus();
  419. if (status) {
  420. // if user has initial status dispatch it
  421. // and skip 'connected' notifications
  422. APP.store.dispatch(participantPresenceChanged(id, status));
  423. // FIXME: move updateUserStatus in participantPresenceChanged action
  424. UI.updateUserStatus(user, status);
  425. } else {
  426. APP.store.dispatch(showParticipantJoinedNotification(displayName));
  427. }
  428. // Add Peer's container
  429. VideoLayout.addParticipantContainer(user);
  430. // Configure avatar
  431. UI.setUserEmail(id);
  432. // set initial display name
  433. if (displayName) {
  434. UI.changeDisplayName(id, displayName);
  435. }
  436. };
  437. /**
  438. * Remove user from UI.
  439. * @param {string} id user id
  440. * @param {string} displayName user nickname
  441. */
  442. UI.removeUser = function(id, displayName) {
  443. messageHandler.participantNotification(
  444. displayName, 'notify.somebody', 'disconnected', 'notify.disconnected');
  445. VideoLayout.removeParticipantContainer(id);
  446. };
  447. /**
  448. * Update videotype for specified user.
  449. * @param {string} id user id
  450. * @param {string} newVideoType new videotype
  451. */
  452. UI.onPeerVideoTypeChanged
  453. = (id, newVideoType) => VideoLayout.onVideoTypeChanged(id, newVideoType);
  454. /**
  455. * Update local user role and show notification if user is moderator.
  456. * @param {boolean} isModerator if local user is moderator or not
  457. */
  458. UI.updateLocalRole = isModerator => {
  459. VideoLayout.showModeratorIndicator();
  460. Recording.showRecordingButton(isModerator);
  461. if (isModerator) {
  462. if (!interfaceConfig.DISABLE_FOCUS_INDICATOR) {
  463. messageHandler.participantNotification(
  464. null, 'notify.me', 'connected', 'notify.moderator');
  465. }
  466. Recording.checkAutoRecord();
  467. }
  468. };
  469. /**
  470. * Check the role for the user and reflect it in the UI, moderator ui indication
  471. * and notifies user who is the moderator
  472. * @param user to check for moderator
  473. */
  474. UI.updateUserRole = user => {
  475. VideoLayout.showModeratorIndicator();
  476. // We don't need to show moderator notifications when the focus (moderator)
  477. // indicator is disabled.
  478. if (!user.isModerator() || interfaceConfig.DISABLE_FOCUS_INDICATOR) {
  479. return;
  480. }
  481. const displayName = user.getDisplayName();
  482. if (displayName) {
  483. messageHandler.participantNotification(
  484. displayName,
  485. 'notify.somebody',
  486. 'connected',
  487. 'notify.grantedTo',
  488. { to: UIUtil.escapeHtml(displayName) });
  489. } else {
  490. messageHandler.participantNotification(
  491. '',
  492. 'notify.somebody',
  493. 'connected',
  494. 'notify.grantedToUnknown');
  495. }
  496. };
  497. /**
  498. * Updates the user status.
  499. *
  500. * @param {JitsiParticipant} user - The user which status we need to update.
  501. * @param {string} status - The new status.
  502. */
  503. UI.updateUserStatus = (user, status) => {
  504. if (!status) {
  505. return;
  506. }
  507. const displayName = user.getDisplayName();
  508. messageHandler.participantNotification(
  509. displayName,
  510. '',
  511. 'connected',
  512. 'dialOut.statusMessage',
  513. { status: UIUtil.escapeHtml(status) });
  514. };
  515. /**
  516. * Toggles smileys in the chat.
  517. */
  518. UI.toggleSmileys = () => Chat.toggleSmileys();
  519. /**
  520. * Toggles filmstrip.
  521. */
  522. UI.toggleFilmstrip = function() {
  523. // eslint-disable-next-line prefer-rest-params
  524. Filmstrip.toggleFilmstrip(...arguments);
  525. VideoLayout.resizeVideoArea(true, false);
  526. };
  527. /**
  528. * Checks if the filmstrip is currently visible or not.
  529. * @returns {true} if the filmstrip is currently visible, and false otherwise.
  530. */
  531. UI.isFilmstripVisible = () => Filmstrip.isFilmstripVisible();
  532. /**
  533. * @returns {true} if the chat panel is currently visible, and false otherwise.
  534. */
  535. UI.isChatVisible = () => Chat.isVisible();
  536. /**
  537. * Toggles chat panel.
  538. */
  539. UI.toggleChat = () => UI.toggleSidePanel('chat_container');
  540. /**
  541. * Toggles the given side panel.
  542. *
  543. * @param {String} sidePanelId the identifier of the side panel to toggle
  544. */
  545. UI.toggleSidePanel = sidePanelId => SideContainerToggler.toggle(sidePanelId);
  546. /**
  547. * Handle new user display name.
  548. */
  549. UI.inputDisplayNameHandler = function(newDisplayName) {
  550. eventEmitter.emit(UIEvents.NICKNAME_CHANGED, newDisplayName);
  551. };
  552. /**
  553. * Show custom popup/tooltip for a specified button.
  554. *
  555. * @param {string} buttonName - The name of the button as specified in the
  556. * button configurations for the toolbar.
  557. * @param {string} popupSelectorID - The id of the popup to show as specified in
  558. * the button configurations for the toolbar.
  559. * @param {boolean} show - True or false/show or hide the popup
  560. * @param {number} timeout - The time to show the popup
  561. * @returns {void}
  562. */
  563. // eslint-disable-next-line max-params, no-unused-vars
  564. UI.showCustomToolbarPopup = function(buttonName, popupID, show, timeout) {
  565. // TODO: this is no longer implemented as of Toolbox v2. Remove?
  566. };
  567. /**
  568. * Return the type of the remote video.
  569. * @param jid the jid for the remote video
  570. * @returns the video type video or screen.
  571. */
  572. UI.getRemoteVideoType = function(jid) {
  573. return VideoLayout.getRemoteVideoType(jid);
  574. };
  575. // FIXME check if someone user this
  576. UI.showLoginPopup = function(callback) {
  577. logger.log('password is required');
  578. const message
  579. = `<input name="username" type="text"
  580. placeholder="user@domain.net"
  581. class="input-control" autofocus>
  582. <input name="password" type="password"
  583. data-i18n="[placeholder]dialog.userPassword"
  584. class="input-control"
  585. placeholder="user password">`
  586. ;
  587. // eslint-disable-next-line max-params
  588. const submitFunction = (e, v, m, f) => {
  589. if (v && f.username && f.password) {
  590. callback(f.username, f.password);
  591. }
  592. };
  593. messageHandler.openTwoButtonDialog({
  594. titleKey: 'dialog.passwordRequired',
  595. msgString: message,
  596. leftButtonKey: 'dialog.Ok',
  597. submitFunction,
  598. focus: ':input:first'
  599. });
  600. };
  601. UI.askForNickname = function() {
  602. // eslint-disable-next-line no-alert
  603. return window.prompt('Your nickname (optional)');
  604. };
  605. /**
  606. * Sets muted audio state for participant
  607. */
  608. UI.setAudioMuted = function(id, muted) {
  609. VideoLayout.onAudioMute(id, muted);
  610. if (APP.conference.isLocalId(id)) {
  611. APP.conference.updateAudioIconEnabled();
  612. }
  613. };
  614. /**
  615. * Sets muted video state for participant
  616. */
  617. UI.setVideoMuted = function(id, muted) {
  618. VideoLayout.onVideoMute(id, muted);
  619. if (APP.conference.isLocalId(id)) {
  620. APP.conference.updateVideoIconEnabled();
  621. }
  622. };
  623. /**
  624. * Triggers an update of remote video and large video displays so they may pick
  625. * up any state changes that have occurred elsewhere.
  626. *
  627. * @returns {void}
  628. */
  629. UI.updateAllVideos = () => VideoLayout.updateAllVideos();
  630. /**
  631. * Adds a listener that would be notified on the given type of event.
  632. *
  633. * @param type the type of the event we're listening for
  634. * @param listener a function that would be called when notified
  635. */
  636. UI.addListener = function(type, listener) {
  637. eventEmitter.on(type, listener);
  638. };
  639. /**
  640. * Removes the given listener for the given type of event.
  641. *
  642. * @param type the type of the event we're listening for
  643. * @param listener the listener we want to remove
  644. */
  645. UI.removeListener = function(type, listener) {
  646. eventEmitter.removeListener(type, listener);
  647. };
  648. /**
  649. * Emits the event of given type by specifying the parameters in options.
  650. *
  651. * @param type the type of the event we're emitting
  652. * @param options the parameters for the event
  653. */
  654. UI.emitEvent = (type, ...options) => eventEmitter.emit(type, ...options);
  655. UI.clickOnVideo = function(videoNumber) {
  656. const videos = $('#remoteVideos .videocontainer:not(#mixedstream)');
  657. const videosLength = videos.length;
  658. if (videosLength <= videoNumber) {
  659. return;
  660. }
  661. const videoIndex = videoNumber === 0 ? 0 : videosLength - videoNumber;
  662. videos[videoIndex].click();
  663. };
  664. // Used by torture.
  665. UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  666. // Used by torture.
  667. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  668. /**
  669. * Update user email.
  670. * @param {string} id user id
  671. * @param {string} email user email
  672. */
  673. UI.setUserEmail = function(id, email) {
  674. if (APP.conference.isLocalId(id)) {
  675. Profile.changeEmail(email);
  676. }
  677. };
  678. /**
  679. * Updates the displayed avatar for participant.
  680. *
  681. * @param {string} id - User id whose avatar should be updated.
  682. * @param {string} avatarURL - The URL to avatar image to display.
  683. * @returns {void}
  684. */
  685. UI.refreshAvatarDisplay = function(id, avatarURL) {
  686. VideoLayout.changeUserAvatar(id, avatarURL);
  687. };
  688. /**
  689. * Notify user that connection failed.
  690. * @param {string} stropheErrorMsg raw Strophe error message
  691. */
  692. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  693. let descriptionKey;
  694. let descriptionArguments;
  695. if (stropheErrorMsg) {
  696. descriptionKey = 'dialog.connectErrorWithMsg';
  697. descriptionArguments = { msg: stropheErrorMsg };
  698. } else {
  699. descriptionKey = 'dialog.connectError';
  700. }
  701. messageHandler.showError({
  702. descriptionArguments,
  703. descriptionKey,
  704. titleKey: 'connection.CONNFAIL'
  705. });
  706. };
  707. /**
  708. * Notify user that maximum users limit has been reached.
  709. */
  710. UI.notifyMaxUsersLimitReached = function() {
  711. messageHandler.showError({
  712. hideErrorSupportLink: true,
  713. descriptionKey: 'dialog.maxUsersLimitReached',
  714. titleKey: 'dialog.maxUsersLimitReachedTitle'
  715. });
  716. };
  717. /**
  718. * Notify user that he was automatically muted when joned the conference.
  719. */
  720. UI.notifyInitiallyMuted = function() {
  721. messageHandler.participantNotification(
  722. null,
  723. 'notify.mutedTitle',
  724. 'connected',
  725. 'notify.muted',
  726. null);
  727. };
  728. /**
  729. * Mark user as dominant speaker.
  730. * @param {string} id user id
  731. */
  732. UI.markDominantSpeaker = function(id) {
  733. VideoLayout.onDominantSpeakerChanged(id);
  734. };
  735. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  736. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  737. };
  738. /**
  739. * Will handle notification about participant's connectivity status change.
  740. *
  741. * @param {string} id the id of remote participant(MUC jid)
  742. */
  743. UI.participantConnectionStatusChanged = function(id) {
  744. VideoLayout.onParticipantConnectionStatusChanged(id);
  745. };
  746. /**
  747. * Prompt user for nickname.
  748. */
  749. UI.promptDisplayName = () => {
  750. APP.store.dispatch(openDisplayNamePrompt());
  751. };
  752. /**
  753. * Update audio level visualization for specified user.
  754. * @param {string} id user id
  755. * @param {number} lvl audio level
  756. */
  757. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  758. /**
  759. * Hide connection quality statistics from UI.
  760. */
  761. UI.hideStats = function() {
  762. VideoLayout.hideStats();
  763. };
  764. /**
  765. * Mark video as interrupted or not.
  766. * @param {boolean} interrupted if video is interrupted
  767. */
  768. UI.markVideoInterrupted = function(interrupted) {
  769. if (interrupted) {
  770. VideoLayout.onVideoInterrupted();
  771. } else {
  772. VideoLayout.onVideoRestored();
  773. }
  774. };
  775. /**
  776. * Add chat message.
  777. * @param {string} from user id
  778. * @param {string} displayName user nickname
  779. * @param {string} message message text
  780. * @param {number} stamp timestamp when message was created
  781. */
  782. // eslint-disable-next-line max-params
  783. UI.addMessage = function(from, displayName, message, stamp) {
  784. Chat.updateChatConversation(from, displayName, message, stamp);
  785. };
  786. // TODO: With Toolbox v2 this got scrapped. Remove?
  787. // eslint-disable-next-line no-empty-function
  788. UI.updateDTMFSupport = () => { };
  789. UI.updateRecordingState = function(state) {
  790. Recording.updateRecordingState(state);
  791. };
  792. UI.notifyTokenAuthFailed = function() {
  793. messageHandler.showError({
  794. descriptionKey: 'dialog.tokenAuthFailed',
  795. titleKey: 'dialog.tokenAuthFailedTitle'
  796. });
  797. };
  798. UI.notifyInternalError = function(error) {
  799. messageHandler.showError({
  800. descriptionArguments: { error },
  801. descriptionKey: 'dialog.internalError',
  802. titleKey: 'dialog.internalErrorTitle'
  803. });
  804. };
  805. UI.notifyFocusDisconnected = function(focus, retrySec) {
  806. messageHandler.participantNotification(
  807. null, 'notify.focus',
  808. 'disconnected', 'notify.focusFail',
  809. { component: focus,
  810. ms: retrySec }
  811. );
  812. };
  813. /**
  814. * Updates auth info on the UI.
  815. * @param {boolean} isAuthEnabled if authentication is enabled
  816. * @param {string} [login] current login
  817. */
  818. UI.updateAuthInfo = function(isAuthEnabled, login) {
  819. const showAuth = isAuthEnabled && UIUtil.isAuthenticationEnabled();
  820. const loggedIn = Boolean(login);
  821. Profile.showAuthenticationButtons(showAuth);
  822. if (showAuth) {
  823. Profile.setAuthenticatedIdentity(login);
  824. Profile.showLoginButton(!loggedIn);
  825. Profile.showLogoutButton(loggedIn);
  826. }
  827. };
  828. /**
  829. * Notifies interested listeners that the raise hand property has changed.
  830. *
  831. * @param {boolean} isRaisedHand indicates the current state of the
  832. * "raised hand"
  833. */
  834. UI.onLocalRaiseHandChanged = function(isRaisedHand) {
  835. eventEmitter.emit(UIEvents.LOCAL_RAISE_HAND_CHANGED, isRaisedHand);
  836. };
  837. /**
  838. * Update list of available physical devices.
  839. * @param {object[]} devices new list of available devices
  840. */
  841. UI.onAvailableDevicesChanged = function(devices) {
  842. APP.store.dispatch(updateDeviceList(devices));
  843. APP.conference.updateAudioIconEnabled();
  844. APP.conference.updateVideoIconEnabled();
  845. };
  846. /**
  847. * Returns the id of the current video shown on large.
  848. * Currently used by tests (torture).
  849. */
  850. UI.getLargeVideoID = function() {
  851. return VideoLayout.getLargeVideoID();
  852. };
  853. /**
  854. * Returns the current video shown on large.
  855. * Currently used by tests (torture).
  856. */
  857. UI.getLargeVideo = function() {
  858. return VideoLayout.getLargeVideo();
  859. };
  860. /**
  861. * Returns whether or not the passed in user id is currently pinned to the large
  862. * video.
  863. *
  864. * @param {string} userId - The id of the user to check is pinned or not.
  865. * @returns {boolean} True if the user is currently pinned to the large video.
  866. */
  867. UI.isPinned = userId => VideoLayout.getPinnedId() === userId;
  868. /**
  869. * Shows "Please go to chrome webstore to install the desktop sharing extension"
  870. * 2 button dialog with buttons - cancel and go to web store.
  871. * @param url {string} the url of the extension.
  872. */
  873. UI.showExtensionExternalInstallationDialog = function(url) {
  874. let openedWindow = null;
  875. const submitFunction = function(e, v) {
  876. if (v) {
  877. e.preventDefault();
  878. if (openedWindow === null || openedWindow.closed) {
  879. openedWindow
  880. = window.open(
  881. url,
  882. 'extension_store_window',
  883. 'resizable,scrollbars=yes,status=1');
  884. } else {
  885. openedWindow.focus();
  886. }
  887. }
  888. };
  889. const closeFunction = function(e, v) {
  890. if (openedWindow) {
  891. // Ideally we would close the popup, but this does not seem to work
  892. // on Chrome. Leaving it uncommented in case it could work
  893. // in some version.
  894. openedWindow.close();
  895. openedWindow = null;
  896. }
  897. if (!v) {
  898. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  899. }
  900. };
  901. messageHandler.openTwoButtonDialog({
  902. titleKey: 'dialog.externalInstallationTitle',
  903. msgKey: 'dialog.externalInstallationMsg',
  904. leftButtonKey: 'dialog.goToStore',
  905. submitFunction,
  906. loadedFunction: $.noop,
  907. closeFunction
  908. });
  909. };
  910. /**
  911. * Shows a dialog which asks user to install the extension. This one is
  912. * displayed after installation is triggered from the script, but fails because
  913. * it must be initiated by user gesture.
  914. * @param callback {function} function to be executed after user clicks
  915. * the install button - it should make another attempt to install the extension.
  916. */
  917. UI.showExtensionInlineInstallationDialog = function(callback) {
  918. const submitFunction = function(e, v) {
  919. if (v) {
  920. callback();
  921. }
  922. };
  923. const closeFunction = function(e, v) {
  924. if (!v) {
  925. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  926. }
  927. };
  928. messageHandler.openTwoButtonDialog({
  929. titleKey: 'dialog.externalInstallationTitle',
  930. msgKey: 'dialog.inlineInstallationMsg',
  931. leftButtonKey: 'dialog.inlineInstallExtension',
  932. submitFunction,
  933. loadedFunction: $.noop,
  934. closeFunction
  935. });
  936. };
  937. /**
  938. * Shows a notifications about the passed in microphone error.
  939. *
  940. * @param {JitsiTrackError} micError - An error object related to using or
  941. * acquiring an audio stream.
  942. * @returns {void}
  943. */
  944. UI.showMicErrorNotification = function(micError) {
  945. if (!micError) {
  946. return;
  947. }
  948. const { message, name } = micError;
  949. const micJitsiTrackErrorMsg
  950. = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[name];
  951. const micErrorMsg = micJitsiTrackErrorMsg
  952. || JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  953. .microphone[JitsiTrackErrors.GENERAL];
  954. const additionalMicErrorMsg = micJitsiTrackErrorMsg ? null : message;
  955. APP.store.dispatch(showWarningNotification({
  956. description: additionalMicErrorMsg,
  957. descriptionKey: micErrorMsg,
  958. titleKey: name === JitsiTrackErrors.PERMISSION_DENIED
  959. ? 'deviceError.microphonePermission'
  960. : 'deviceError.microphoneError'
  961. }));
  962. };
  963. /**
  964. * Shows a notifications about the passed in camera error.
  965. *
  966. * @param {JitsiTrackError} cameraError - An error object related to using or
  967. * acquiring a video stream.
  968. * @returns {void}
  969. */
  970. UI.showCameraErrorNotification = function(cameraError) {
  971. if (!cameraError) {
  972. return;
  973. }
  974. const { message, name } = cameraError;
  975. const cameraJitsiTrackErrorMsg
  976. = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[name];
  977. const cameraErrorMsg = cameraJitsiTrackErrorMsg
  978. || JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  979. .camera[JitsiTrackErrors.GENERAL];
  980. const additionalCameraErrorMsg = cameraJitsiTrackErrorMsg ? null : message;
  981. APP.store.dispatch(showWarningNotification({
  982. description: additionalCameraErrorMsg,
  983. descriptionKey: cameraErrorMsg,
  984. titleKey: name === JitsiTrackErrors.PERMISSION_DENIED
  985. ? 'deviceError.cameraPermission' : 'deviceError.cameraError'
  986. }));
  987. };
  988. /**
  989. * Shows error dialog that informs the user that no data is received from the
  990. * device.
  991. *
  992. * @param {boolean} isAudioTrack - Whether or not the dialog is for an audio
  993. * track error.
  994. * @returns {void}
  995. */
  996. UI.showTrackNotWorkingDialog = function(isAudioTrack) {
  997. messageHandler.showError({
  998. descriptionKey: isAudioTrack
  999. ? 'dialog.micNotSendingData' : 'dialog.cameraNotSendingData',
  1000. titleKey: isAudioTrack
  1001. ? 'dialog.micNotSendingDataTitle'
  1002. : 'dialog.cameraNotSendingDataTitle'
  1003. });
  1004. };
  1005. UI.updateDevicesAvailability = function(id, devices) {
  1006. VideoLayout.setDeviceAvailabilityIcons(id, devices);
  1007. };
  1008. /**
  1009. * Show shared video.
  1010. * @param {string} id the id of the sender of the command
  1011. * @param {string} url video url
  1012. * @param {string} attributes
  1013. */
  1014. UI.onSharedVideoStart = function(id, url, attributes) {
  1015. if (sharedVideoManager) {
  1016. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  1017. }
  1018. };
  1019. /**
  1020. * Update shared video.
  1021. * @param {string} id the id of the sender of the command
  1022. * @param {string} url video url
  1023. * @param {string} attributes
  1024. */
  1025. UI.onSharedVideoUpdate = function(id, url, attributes) {
  1026. if (sharedVideoManager) {
  1027. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  1028. }
  1029. };
  1030. /**
  1031. * Stop showing shared video.
  1032. * @param {string} id the id of the sender of the command
  1033. * @param {string} attributes
  1034. */
  1035. UI.onSharedVideoStop = function(id, attributes) {
  1036. if (sharedVideoManager) {
  1037. sharedVideoManager.onSharedVideoStop(id, attributes);
  1038. }
  1039. };
  1040. /**
  1041. * Handles user's features changes.
  1042. */
  1043. UI.onUserFeaturesChanged = user => VideoLayout.onUserFeaturesChanged(user);
  1044. /**
  1045. * Returns the number of known remote videos.
  1046. *
  1047. * @returns {number} The number of remote videos.
  1048. */
  1049. UI.getRemoteVideosCount = () => VideoLayout.getRemoteVideosCount();
  1050. /**
  1051. * Sets the remote control active status for a remote participant.
  1052. *
  1053. * @param {string} participantID - The id of the remote participant.
  1054. * @param {boolean} isActive - The new remote control active status.
  1055. * @returns {void}
  1056. */
  1057. UI.setRemoteControlActiveStatus = function(participantID, isActive) {
  1058. VideoLayout.setRemoteControlActiveStatus(participantID, isActive);
  1059. };
  1060. /**
  1061. * Sets the remote control active status for the local participant.
  1062. *
  1063. * @returns {void}
  1064. */
  1065. UI.setLocalRemoteControlActiveChanged = function() {
  1066. VideoLayout.setLocalRemoteControlActiveChanged();
  1067. };
  1068. /**
  1069. * Remove media tracks and UI elements so the user no longer sees media in the
  1070. * UI. The intent is to provide a feeling that the meeting has ended.
  1071. *
  1072. * @returns {void}
  1073. */
  1074. UI.removeLocalMedia = function() {
  1075. APP.store.dispatch(destroyLocalTracks());
  1076. VideoLayout.resetLargeVideo();
  1077. $('#videospace').hide();
  1078. };
  1079. // TODO: Export every function separately. For now there is no point of doing
  1080. // this because we are importing everything.
  1081. export default UI;