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

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