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

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