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

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