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.

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