You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UI.js 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290
  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. // Add Peer's container
  440. VideoLayout.addParticipantContainer(user);
  441. // Configure avatar
  442. UI.setUserEmail(id);
  443. // set initial display name
  444. if (displayName) {
  445. UI.changeDisplayName(id, displayName);
  446. }
  447. };
  448. /**
  449. * Remove user from UI.
  450. * @param {string} id user id
  451. * @param {string} displayName user nickname
  452. */
  453. UI.removeUser = function(id, displayName) {
  454. messageHandler.participantNotification(
  455. displayName, 'notify.somebody', 'disconnected', 'notify.disconnected');
  456. VideoLayout.removeParticipantContainer(id);
  457. };
  458. /**
  459. * Update videotype for specified user.
  460. * @param {string} id user id
  461. * @param {string} newVideoType new videotype
  462. */
  463. UI.onPeerVideoTypeChanged
  464. = (id, newVideoType) => VideoLayout.onVideoTypeChanged(id, newVideoType);
  465. /**
  466. * Update local user role and show notification if user is moderator.
  467. * @param {boolean} isModerator if local user is moderator or not
  468. */
  469. UI.updateLocalRole = isModerator => {
  470. VideoLayout.showModeratorIndicator();
  471. APP.store.dispatch(showSharedVideoButton());
  472. Recording.showRecordingButton(isModerator);
  473. if (isModerator) {
  474. if (!interfaceConfig.DISABLE_FOCUS_INDICATOR) {
  475. messageHandler.participantNotification(
  476. null, 'notify.me', 'connected', 'notify.moderator');
  477. }
  478. Recording.checkAutoRecord();
  479. }
  480. };
  481. /**
  482. * Check the role for the user and reflect it in the UI, moderator ui indication
  483. * and notifies user who is the moderator
  484. * @param user to check for moderator
  485. */
  486. UI.updateUserRole = user => {
  487. VideoLayout.showModeratorIndicator();
  488. // We don't need to show moderator notifications when the focus (moderator)
  489. // indicator is disabled.
  490. if (!user.isModerator() || interfaceConfig.DISABLE_FOCUS_INDICATOR) {
  491. return;
  492. }
  493. const displayName = user.getDisplayName();
  494. if (displayName) {
  495. messageHandler.participantNotification(
  496. displayName,
  497. 'notify.somebody',
  498. 'connected',
  499. 'notify.grantedTo',
  500. { to: UIUtil.escapeHtml(displayName) });
  501. } else {
  502. messageHandler.participantNotification(
  503. '',
  504. 'notify.somebody',
  505. 'connected',
  506. 'notify.grantedToUnknown');
  507. }
  508. };
  509. /**
  510. * Updates the user status.
  511. *
  512. * @param {JitsiParticipant} user - The user which status we need to update.
  513. * @param {string} status - The new status.
  514. */
  515. UI.updateUserStatus = (user, status) => {
  516. if (!status) {
  517. return;
  518. }
  519. const displayName = user.getDisplayName();
  520. messageHandler.participantNotification(
  521. displayName,
  522. '',
  523. 'connected',
  524. 'dialOut.statusMessage',
  525. { status: UIUtil.escapeHtml(status) });
  526. };
  527. /**
  528. * Toggles smileys in the chat.
  529. */
  530. UI.toggleSmileys = () => Chat.toggleSmileys();
  531. /**
  532. * Toggles filmstrip.
  533. */
  534. UI.toggleFilmstrip = function() {
  535. // eslint-disable-next-line prefer-rest-params
  536. Filmstrip.toggleFilmstrip(...arguments);
  537. VideoLayout.resizeVideoArea(true, false);
  538. };
  539. /**
  540. * Checks if the filmstrip is currently visible or not.
  541. * @returns {true} if the filmstrip is currently visible, and false otherwise.
  542. */
  543. UI.isFilmstripVisible = () => Filmstrip.isFilmstripVisible();
  544. /**
  545. * @returns {true} if the chat panel is currently visible, and false otherwise.
  546. */
  547. UI.isChatVisible = () => Chat.isVisible();
  548. /**
  549. * Toggles chat panel.
  550. */
  551. UI.toggleChat = () => UI.toggleSidePanel('chat_container');
  552. /**
  553. * Toggles contact list panel.
  554. */
  555. UI.toggleContactList = () => UI.toggleSidePanel('contacts_container');
  556. /**
  557. * Toggles the given side panel.
  558. *
  559. * @param {String} sidePanelId the identifier of the side panel to toggle
  560. */
  561. UI.toggleSidePanel = sidePanelId => SideContainerToggler.toggle(sidePanelId);
  562. /**
  563. * Handle new user display name.
  564. */
  565. UI.inputDisplayNameHandler = function(newDisplayName) {
  566. eventEmitter.emit(UIEvents.NICKNAME_CHANGED, newDisplayName);
  567. };
  568. /**
  569. * Show custom popup/tooltip for a specified button.
  570. *
  571. * @param {string} buttonName - The name of the button as specified in the
  572. * button configurations for the toolbar.
  573. * @param {string} popupSelectorID - The id of the popup to show as specified in
  574. * the button configurations for the toolbar.
  575. * @param {boolean} show - True or false/show or hide the popup
  576. * @param {number} timeout - The time to show the popup
  577. * @returns {void}
  578. */
  579. // eslint-disable-next-line max-params
  580. UI.showCustomToolbarPopup = function(buttonName, popupID, show, timeout) {
  581. const action
  582. = show
  583. ? setButtonPopupTimeout(buttonName, popupID, timeout)
  584. : clearButtonPopup(buttonName);
  585. APP.store.dispatch(action);
  586. };
  587. /**
  588. * Return the type of the remote video.
  589. * @param jid the jid for the remote video
  590. * @returns the video type video or screen.
  591. */
  592. UI.getRemoteVideoType = function(jid) {
  593. return VideoLayout.getRemoteVideoType(jid);
  594. };
  595. // FIXME check if someone user this
  596. UI.showLoginPopup = function(callback) {
  597. logger.log('password is required');
  598. const message
  599. = `<input name="username" type="text"
  600. placeholder="user@domain.net"
  601. class="input-control" autofocus>
  602. <input name="password" type="password"
  603. data-i18n="[placeholder]dialog.userPassword"
  604. class="input-control"
  605. placeholder="user password">`
  606. ;
  607. // eslint-disable-next-line max-params
  608. const submitFunction = (e, v, m, f) => {
  609. if (v && f.username && f.password) {
  610. callback(f.username, f.password);
  611. }
  612. };
  613. messageHandler.openTwoButtonDialog({
  614. titleKey: 'dialog.passwordRequired',
  615. msgString: message,
  616. leftButtonKey: 'dialog.Ok',
  617. submitFunction,
  618. focus: ':input:first'
  619. });
  620. };
  621. UI.askForNickname = function() {
  622. // eslint-disable-next-line no-alert
  623. return window.prompt('Your nickname (optional)');
  624. };
  625. /**
  626. * Sets muted audio state for participant
  627. */
  628. UI.setAudioMuted = function(id, muted) {
  629. VideoLayout.onAudioMute(id, muted);
  630. if (APP.conference.isLocalId(id)) {
  631. APP.conference.updateAudioIconEnabled();
  632. }
  633. };
  634. /**
  635. * Sets muted video state for participant
  636. */
  637. UI.setVideoMuted = function(id, muted) {
  638. VideoLayout.onVideoMute(id, muted);
  639. if (APP.conference.isLocalId(id)) {
  640. APP.conference.updateVideoIconEnabled();
  641. }
  642. };
  643. /**
  644. * Triggers an update of remote video and large video displays so they may pick
  645. * up any state changes that have occurred elsewhere.
  646. *
  647. * @returns {void}
  648. */
  649. UI.updateAllVideos = () => VideoLayout.updateAllVideos();
  650. /**
  651. * Adds a listener that would be notified on the given type of event.
  652. *
  653. * @param type the type of the event we're listening for
  654. * @param listener a function that would be called when notified
  655. */
  656. UI.addListener = function(type, listener) {
  657. eventEmitter.on(type, listener);
  658. };
  659. /**
  660. * Removes the given listener for the given type of event.
  661. *
  662. * @param type the type of the event we're listening for
  663. * @param listener the listener we want to remove
  664. */
  665. UI.removeListener = function(type, listener) {
  666. eventEmitter.removeListener(type, listener);
  667. };
  668. /**
  669. * Emits the event of given type by specifying the parameters in options.
  670. *
  671. * @param type the type of the event we're emitting
  672. * @param options the parameters for the event
  673. */
  674. UI.emitEvent = (type, ...options) => eventEmitter.emit(type, ...options);
  675. UI.clickOnVideo = function(videoNumber) {
  676. const videos = $('#remoteVideos .videocontainer:not(#mixedstream)');
  677. const videosLength = videos.length;
  678. if (videosLength <= videoNumber) {
  679. return;
  680. }
  681. const videoIndex = videoNumber === 0 ? 0 : videosLength - videoNumber;
  682. videos[videoIndex].click();
  683. };
  684. // Used by torture.
  685. UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  686. // Used by torture.
  687. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  688. /**
  689. * Update user email.
  690. * @param {string} id user id
  691. * @param {string} email user email
  692. */
  693. UI.setUserEmail = function(id, email) {
  694. if (APP.conference.isLocalId(id)) {
  695. Profile.changeEmail(email);
  696. }
  697. };
  698. /**
  699. * Updates the displayed avatar for participant.
  700. *
  701. * @param {string} id - User id whose avatar should be updated.
  702. * @param {string} avatarURL - The URL to avatar image to display.
  703. * @returns {void}
  704. */
  705. UI.refreshAvatarDisplay = function(id, avatarURL) {
  706. VideoLayout.changeUserAvatar(id, avatarURL);
  707. };
  708. /**
  709. * Notify user that connection failed.
  710. * @param {string} stropheErrorMsg raw Strophe error message
  711. */
  712. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  713. let descriptionKey;
  714. let descriptionArguments;
  715. if (stropheErrorMsg) {
  716. descriptionKey = 'dialog.connectErrorWithMsg';
  717. descriptionArguments = { msg: stropheErrorMsg };
  718. } else {
  719. descriptionKey = 'dialog.connectError';
  720. }
  721. messageHandler.showError({
  722. descriptionArguments,
  723. descriptionKey,
  724. titleKey: 'connection.CONNFAIL'
  725. });
  726. };
  727. /**
  728. * Notify user that maximum users limit has been reached.
  729. */
  730. UI.notifyMaxUsersLimitReached = function() {
  731. messageHandler.showError({
  732. hideErrorSupportLink: true,
  733. descriptionKey: 'dialog.maxUsersLimitReached',
  734. titleKey: 'dialog.maxUsersLimitReachedTitle'
  735. });
  736. };
  737. /**
  738. * Notify user that he was automatically muted when joned the conference.
  739. */
  740. UI.notifyInitiallyMuted = function() {
  741. messageHandler.participantNotification(
  742. null,
  743. 'notify.mutedTitle',
  744. 'connected',
  745. 'notify.muted',
  746. null);
  747. };
  748. /**
  749. * Mark user as dominant speaker.
  750. * @param {string} id user id
  751. */
  752. UI.markDominantSpeaker = function(id) {
  753. VideoLayout.onDominantSpeakerChanged(id);
  754. };
  755. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  756. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  757. };
  758. /**
  759. * Will handle notification about participant's connectivity status change.
  760. *
  761. * @param {string} id the id of remote participant(MUC jid)
  762. */
  763. UI.participantConnectionStatusChanged = function(id) {
  764. VideoLayout.onParticipantConnectionStatusChanged(id);
  765. };
  766. /**
  767. * Prompt user for nickname.
  768. */
  769. UI.promptDisplayName = () => {
  770. APP.store.dispatch(openDisplayNamePrompt());
  771. };
  772. /**
  773. * Update audio level visualization for specified user.
  774. * @param {string} id user id
  775. * @param {number} lvl audio level
  776. */
  777. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  778. /**
  779. * Update state of desktop sharing buttons.
  780. *
  781. * @returns {void}
  782. */
  783. UI.updateDesktopSharingButtons
  784. = () =>
  785. APP.store.dispatch(setToolbarButton('desktop', {
  786. toggled: APP.conference.isSharingScreen
  787. }));
  788. /**
  789. * Hide connection quality statistics from UI.
  790. */
  791. UI.hideStats = function() {
  792. VideoLayout.hideStats();
  793. };
  794. /**
  795. * Mark video as interrupted or not.
  796. * @param {boolean} interrupted if video is interrupted
  797. */
  798. UI.markVideoInterrupted = function(interrupted) {
  799. if (interrupted) {
  800. VideoLayout.onVideoInterrupted();
  801. } else {
  802. VideoLayout.onVideoRestored();
  803. }
  804. };
  805. /**
  806. * Add chat message.
  807. * @param {string} from user id
  808. * @param {string} displayName user nickname
  809. * @param {string} message message text
  810. * @param {number} stamp timestamp when message was created
  811. */
  812. // eslint-disable-next-line max-params
  813. UI.addMessage = function(from, displayName, message, stamp) {
  814. Chat.updateChatConversation(from, displayName, message, stamp);
  815. };
  816. UI.updateDTMFSupport
  817. = isDTMFSupported => APP.store.dispatch(showDialPadButton(isDTMFSupported));
  818. UI.updateRecordingState = function(state) {
  819. Recording.updateRecordingState(state);
  820. };
  821. UI.notifyTokenAuthFailed = function() {
  822. messageHandler.showError({
  823. descriptionKey: 'dialog.tokenAuthFailed',
  824. titleKey: 'dialog.tokenAuthFailedTitle'
  825. });
  826. };
  827. UI.notifyInternalError = function(error) {
  828. messageHandler.showError({
  829. descriptionArguments: { error },
  830. descriptionKey: 'dialog.internalError',
  831. titleKey: 'dialog.internalErrorTitle'
  832. });
  833. };
  834. UI.notifyFocusDisconnected = function(focus, retrySec) {
  835. messageHandler.participantNotification(
  836. null, 'notify.focus',
  837. 'disconnected', 'notify.focusFail',
  838. { component: focus,
  839. ms: retrySec }
  840. );
  841. };
  842. /**
  843. * Updates auth info on the UI.
  844. * @param {boolean} isAuthEnabled if authentication is enabled
  845. * @param {string} [login] current login
  846. */
  847. UI.updateAuthInfo = function(isAuthEnabled, login) {
  848. const showAuth = isAuthEnabled && UIUtil.isAuthenticationEnabled();
  849. const loggedIn = Boolean(login);
  850. Profile.showAuthenticationButtons(showAuth);
  851. if (showAuth) {
  852. Profile.setAuthenticatedIdentity(login);
  853. Profile.showLoginButton(!loggedIn);
  854. Profile.showLogoutButton(loggedIn);
  855. }
  856. };
  857. /**
  858. * Notifies interested listeners that the raise hand property has changed.
  859. *
  860. * @param {boolean} isRaisedHand indicates the current state of the
  861. * "raised hand"
  862. */
  863. UI.onLocalRaiseHandChanged = function(isRaisedHand) {
  864. eventEmitter.emit(UIEvents.LOCAL_RAISE_HAND_CHANGED, isRaisedHand);
  865. };
  866. /**
  867. * Update list of available physical devices.
  868. * @param {object[]} devices new list of available devices
  869. */
  870. UI.onAvailableDevicesChanged = function(devices) {
  871. APP.store.dispatch(updateDeviceList(devices));
  872. APP.conference.updateAudioIconEnabled();
  873. APP.conference.updateVideoIconEnabled();
  874. };
  875. /**
  876. * Returns the id of the current video shown on large.
  877. * Currently used by tests (torture).
  878. */
  879. UI.getLargeVideoID = function() {
  880. return VideoLayout.getLargeVideoID();
  881. };
  882. /**
  883. * Returns the current video shown on large.
  884. * Currently used by tests (torture).
  885. */
  886. UI.getLargeVideo = function() {
  887. return VideoLayout.getLargeVideo();
  888. };
  889. /**
  890. * Returns whether or not the passed in user id is currently pinned to the large
  891. * video.
  892. *
  893. * @param {string} userId - The id of the user to check is pinned or not.
  894. * @returns {boolean} True if the user is currently pinned to the large video.
  895. */
  896. UI.isPinned = userId => VideoLayout.getPinnedId() === userId;
  897. /**
  898. * Shows dialog with a link to FF extension.
  899. */
  900. UI.showExtensionRequiredDialog = function(url) {
  901. messageHandler.openMessageDialog(
  902. 'dialog.extensionRequired',
  903. '[html]dialog.firefoxExtensionPrompt',
  904. { url });
  905. };
  906. /**
  907. * Shows "Please go to chrome webstore to install the desktop sharing extension"
  908. * 2 button dialog with buttons - cancel and go to web store.
  909. * @param url {string} the url of the extension.
  910. */
  911. UI.showExtensionExternalInstallationDialog = function(url) {
  912. let openedWindow = null;
  913. const submitFunction = function(e, v) {
  914. if (v) {
  915. e.preventDefault();
  916. if (openedWindow === null || openedWindow.closed) {
  917. openedWindow
  918. = window.open(
  919. url,
  920. 'extension_store_window',
  921. 'resizable,scrollbars=yes,status=1');
  922. } else {
  923. openedWindow.focus();
  924. }
  925. }
  926. };
  927. const closeFunction = function(e, v) {
  928. if (openedWindow) {
  929. // Ideally we would close the popup, but this does not seem to work
  930. // on Chrome. Leaving it uncommented in case it could work
  931. // in some version.
  932. openedWindow.close();
  933. openedWindow = null;
  934. }
  935. if (!v) {
  936. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  937. }
  938. };
  939. messageHandler.openTwoButtonDialog({
  940. titleKey: 'dialog.externalInstallationTitle',
  941. msgKey: 'dialog.externalInstallationMsg',
  942. leftButtonKey: 'dialog.goToStore',
  943. submitFunction,
  944. loadedFunction: $.noop,
  945. closeFunction
  946. });
  947. };
  948. /**
  949. * Shows a dialog which asks user to install the extension. This one is
  950. * displayed after installation is triggered from the script, but fails because
  951. * it must be initiated by user gesture.
  952. * @param callback {function} function to be executed after user clicks
  953. * the install button - it should make another attempt to install the extension.
  954. */
  955. UI.showExtensionInlineInstallationDialog = function(callback) {
  956. const submitFunction = function(e, v) {
  957. if (v) {
  958. callback();
  959. }
  960. };
  961. const closeFunction = function(e, v) {
  962. if (!v) {
  963. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  964. }
  965. };
  966. messageHandler.openTwoButtonDialog({
  967. titleKey: 'dialog.externalInstallationTitle',
  968. msgKey: 'dialog.inlineInstallationMsg',
  969. leftButtonKey: 'dialog.inlineInstallExtension',
  970. submitFunction,
  971. loadedFunction: $.noop,
  972. closeFunction
  973. });
  974. };
  975. /**
  976. * Shows a notifications about the passed in microphone error.
  977. *
  978. * @param {JitsiTrackError} micError - An error object related to using or
  979. * acquiring an audio stream.
  980. * @returns {void}
  981. */
  982. UI.showMicErrorNotification = function(micError) {
  983. if (!micError) {
  984. return;
  985. }
  986. const { message, name } = micError;
  987. const micJitsiTrackErrorMsg
  988. = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[name];
  989. const micErrorMsg = micJitsiTrackErrorMsg
  990. || JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  991. .microphone[JitsiTrackErrors.GENERAL];
  992. const additionalMicErrorMsg = micJitsiTrackErrorMsg ? null : message;
  993. APP.store.dispatch(showWarningNotification({
  994. description: additionalMicErrorMsg,
  995. descriptionKey: micErrorMsg,
  996. titleKey: name === JitsiTrackErrors.PERMISSION_DENIED
  997. ? 'deviceError.microphonePermission'
  998. : 'deviceError.microphoneError'
  999. }));
  1000. };
  1001. /**
  1002. * Shows a notifications about the passed in camera error.
  1003. *
  1004. * @param {JitsiTrackError} cameraError - An error object related to using or
  1005. * acquiring a video stream.
  1006. * @returns {void}
  1007. */
  1008. UI.showCameraErrorNotification = function(cameraError) {
  1009. if (!cameraError) {
  1010. return;
  1011. }
  1012. const { message, name } = cameraError;
  1013. const cameraJitsiTrackErrorMsg
  1014. = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[name];
  1015. const cameraErrorMsg = cameraJitsiTrackErrorMsg
  1016. || JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  1017. .camera[JitsiTrackErrors.GENERAL];
  1018. const additionalCameraErrorMsg = cameraJitsiTrackErrorMsg ? null : message;
  1019. APP.store.dispatch(showWarningNotification({
  1020. description: additionalCameraErrorMsg,
  1021. descriptionKey: cameraErrorMsg,
  1022. titleKey: name === JitsiTrackErrors.PERMISSION_DENIED
  1023. ? 'deviceError.cameraPermission' : 'deviceError.cameraError'
  1024. }));
  1025. };
  1026. /**
  1027. * Shows error dialog that informs the user that no data is received from the
  1028. * device.
  1029. *
  1030. * @param {boolean} isAudioTrack - Whether or not the dialog is for an audio
  1031. * track error.
  1032. * @returns {void}
  1033. */
  1034. UI.showTrackNotWorkingDialog = function(isAudioTrack) {
  1035. messageHandler.showError({
  1036. descriptionKey: isAudioTrack
  1037. ? 'dialog.micNotSendingData' : 'dialog.cameraNotSendingData',
  1038. titleKey: isAudioTrack
  1039. ? 'dialog.micNotSendingDataTitle'
  1040. : 'dialog.cameraNotSendingDataTitle'
  1041. });
  1042. };
  1043. UI.updateDevicesAvailability = function(id, devices) {
  1044. VideoLayout.setDeviceAvailabilityIcons(id, devices);
  1045. };
  1046. /**
  1047. * Show shared video.
  1048. * @param {string} id the id of the sender of the command
  1049. * @param {string} url video url
  1050. * @param {string} attributes
  1051. */
  1052. UI.onSharedVideoStart = function(id, url, attributes) {
  1053. if (sharedVideoManager) {
  1054. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  1055. }
  1056. };
  1057. /**
  1058. * Update shared video.
  1059. * @param {string} id the id of the sender of the command
  1060. * @param {string} url video url
  1061. * @param {string} attributes
  1062. */
  1063. UI.onSharedVideoUpdate = function(id, url, attributes) {
  1064. if (sharedVideoManager) {
  1065. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  1066. }
  1067. };
  1068. /**
  1069. * Stop showing shared video.
  1070. * @param {string} id the id of the sender of the command
  1071. * @param {string} attributes
  1072. */
  1073. UI.onSharedVideoStop = function(id, attributes) {
  1074. if (sharedVideoManager) {
  1075. sharedVideoManager.onSharedVideoStop(id, attributes);
  1076. }
  1077. };
  1078. /**
  1079. * Handles user's features changes.
  1080. */
  1081. UI.onUserFeaturesChanged = user => VideoLayout.onUserFeaturesChanged(user);
  1082. /**
  1083. * Returns the number of known remote videos.
  1084. *
  1085. * @returns {number} The number of remote videos.
  1086. */
  1087. UI.getRemoteVideosCount = () => VideoLayout.getRemoteVideosCount();
  1088. /**
  1089. * Sets the remote control active status for a remote participant.
  1090. *
  1091. * @param {string} participantID - The id of the remote participant.
  1092. * @param {boolean} isActive - The new remote control active status.
  1093. * @returns {void}
  1094. */
  1095. UI.setRemoteControlActiveStatus = function(participantID, isActive) {
  1096. VideoLayout.setRemoteControlActiveStatus(participantID, isActive);
  1097. };
  1098. /**
  1099. * Sets the remote control active status for the local participant.
  1100. *
  1101. * @returns {void}
  1102. */
  1103. UI.setLocalRemoteControlActiveChanged = function() {
  1104. VideoLayout.setLocalRemoteControlActiveChanged();
  1105. };
  1106. /**
  1107. * Remove media tracks and UI elements so the user no longer sees media in the
  1108. * UI. The intent is to provide a feeling that the meeting has ended.
  1109. *
  1110. * @returns {void}
  1111. */
  1112. UI.removeLocalMedia = function() {
  1113. APP.store.dispatch(destroyLocalTracks());
  1114. VideoLayout.resetLargeVideo();
  1115. $('#videospace').hide();
  1116. };
  1117. // TODO: Export every function separately. For now there is no point of doing
  1118. // this because we are importing everything.
  1119. export default UI;