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.

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