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

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