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

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