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

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