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

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