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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  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. * Update user email.
  692. * @param {string} id user id
  693. * @param {string} email user email
  694. */
  695. UI.setUserEmail = function(id, email) {
  696. // update avatar
  697. Avatar.setUserEmail(id, email);
  698. changeAvatar(id, Avatar.getAvatarUrl(id));
  699. if (APP.conference.isLocalId(id)) {
  700. Profile.changeEmail(email);
  701. }
  702. };
  703. /**
  704. * Update user avtar id.
  705. * @param {string} id user id
  706. * @param {string} avatarId user's avatar id
  707. */
  708. UI.setUserAvatarID = function(id, avatarId) {
  709. // update avatar
  710. Avatar.setUserAvatarID(id, avatarId);
  711. changeAvatar(id, Avatar.getAvatarUrl(id));
  712. };
  713. /**
  714. * Update user avatar URL.
  715. * @param {string} id user id
  716. * @param {string} url user avatar url
  717. */
  718. UI.setUserAvatarUrl = function(id, url) {
  719. // update avatar
  720. Avatar.setUserAvatarUrl(id, url);
  721. changeAvatar(id, Avatar.getAvatarUrl(id));
  722. };
  723. /**
  724. * Notify user that connection failed.
  725. * @param {string} stropheErrorMsg raw Strophe error message
  726. */
  727. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  728. let descriptionKey;
  729. let descriptionArguments;
  730. if (stropheErrorMsg) {
  731. descriptionKey = 'dialog.connectErrorWithMsg';
  732. descriptionArguments = { msg: stropheErrorMsg };
  733. } else {
  734. descriptionKey = 'dialog.connectError';
  735. }
  736. messageHandler.showError({
  737. descriptionArguments,
  738. descriptionKey,
  739. titleKey: 'connection.CONNFAIL'
  740. });
  741. };
  742. /**
  743. * Notify user that maximum users limit has been reached.
  744. */
  745. UI.notifyMaxUsersLimitReached = function() {
  746. messageHandler.showError({
  747. hideErrorSupportLink: true,
  748. descriptionKey: 'dialog.maxUsersLimitReached',
  749. titleKey: 'dialog.maxUsersLimitReachedTitle'
  750. });
  751. };
  752. /**
  753. * Notify user that he was automatically muted when joned the conference.
  754. */
  755. UI.notifyInitiallyMuted = function() {
  756. messageHandler.participantNotification(
  757. null,
  758. 'notify.mutedTitle',
  759. 'connected',
  760. 'notify.muted',
  761. null,
  762. 120000);
  763. };
  764. /**
  765. * Mark user as dominant speaker.
  766. * @param {string} id user id
  767. */
  768. UI.markDominantSpeaker = function(id) {
  769. VideoLayout.onDominantSpeakerChanged(id);
  770. };
  771. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  772. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  773. };
  774. /**
  775. * Will handle notification about participant's connectivity status change.
  776. *
  777. * @param {string} id the id of remote participant(MUC jid)
  778. */
  779. UI.participantConnectionStatusChanged = function(id) {
  780. VideoLayout.onParticipantConnectionStatusChanged(id);
  781. };
  782. /**
  783. * Prompt user for nickname.
  784. */
  785. UI.promptDisplayName = () => {
  786. APP.store.dispatch(openDisplayNamePrompt());
  787. };
  788. /**
  789. * Update audio level visualization for specified user.
  790. * @param {string} id user id
  791. * @param {number} lvl audio level
  792. */
  793. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  794. /**
  795. * Update state of desktop sharing buttons.
  796. *
  797. * @returns {void}
  798. */
  799. UI.updateDesktopSharingButtons
  800. = () =>
  801. APP.store.dispatch(setToolbarButton('desktop', {
  802. toggled: APP.conference.isSharingScreen
  803. }));
  804. /**
  805. * Hide connection quality statistics from UI.
  806. */
  807. UI.hideStats = function() {
  808. VideoLayout.hideStats();
  809. };
  810. /**
  811. * Mark video as interrupted or not.
  812. * @param {boolean} interrupted if video is interrupted
  813. */
  814. UI.markVideoInterrupted = function(interrupted) {
  815. if (interrupted) {
  816. VideoLayout.onVideoInterrupted();
  817. } else {
  818. VideoLayout.onVideoRestored();
  819. }
  820. };
  821. /**
  822. * Add chat message.
  823. * @param {string} from user id
  824. * @param {string} displayName user nickname
  825. * @param {string} message message text
  826. * @param {number} stamp timestamp when message was created
  827. */
  828. // eslint-disable-next-line max-params
  829. UI.addMessage = function(from, displayName, message, stamp) {
  830. Chat.updateChatConversation(from, displayName, message, stamp);
  831. };
  832. UI.updateDTMFSupport
  833. = isDTMFSupported => APP.store.dispatch(showDialPadButton(isDTMFSupported));
  834. UI.updateRecordingState = function(state) {
  835. Recording.updateRecordingState(state);
  836. };
  837. UI.notifyTokenAuthFailed = function() {
  838. messageHandler.showError({
  839. descriptionKey: 'dialog.tokenAuthFailed',
  840. titleKey: 'dialog.tokenAuthFailedTitle'
  841. });
  842. };
  843. UI.notifyInternalError = function(error) {
  844. messageHandler.showError({
  845. descriptionArguments: { error },
  846. descriptionKey: 'dialog.internalError',
  847. titleKey: 'dialog.internalErrorTitle'
  848. });
  849. };
  850. UI.notifyFocusDisconnected = function(focus, retrySec) {
  851. messageHandler.participantNotification(
  852. null, 'notify.focus',
  853. 'disconnected', 'notify.focusFail',
  854. { component: focus,
  855. ms: retrySec }
  856. );
  857. };
  858. /**
  859. * Updates auth info on the UI.
  860. * @param {boolean} isAuthEnabled if authentication is enabled
  861. * @param {string} [login] current login
  862. */
  863. UI.updateAuthInfo = function(isAuthEnabled, login) {
  864. const showAuth = isAuthEnabled && UIUtil.isAuthenticationEnabled();
  865. const loggedIn = Boolean(login);
  866. Profile.showAuthenticationButtons(showAuth);
  867. if (showAuth) {
  868. Profile.setAuthenticatedIdentity(login);
  869. Profile.showLoginButton(!loggedIn);
  870. Profile.showLogoutButton(loggedIn);
  871. }
  872. };
  873. /**
  874. * Notifies interested listeners that the raise hand property has changed.
  875. *
  876. * @param {boolean} isRaisedHand indicates the current state of the
  877. * "raised hand"
  878. */
  879. UI.onLocalRaiseHandChanged = function(isRaisedHand) {
  880. eventEmitter.emit(UIEvents.LOCAL_RAISE_HAND_CHANGED, isRaisedHand);
  881. };
  882. /**
  883. * Update list of available physical devices.
  884. * @param {object[]} devices new list of available devices
  885. */
  886. UI.onAvailableDevicesChanged = function(devices) {
  887. APP.store.dispatch(updateDeviceList(devices));
  888. APP.conference.updateAudioIconEnabled();
  889. APP.conference.updateVideoIconEnabled();
  890. };
  891. /**
  892. * Returns the id of the current video shown on large.
  893. * Currently used by tests (torture).
  894. */
  895. UI.getLargeVideoID = function() {
  896. return VideoLayout.getLargeVideoID();
  897. };
  898. /**
  899. * Returns the current video shown on large.
  900. * Currently used by tests (torture).
  901. */
  902. UI.getLargeVideo = function() {
  903. return VideoLayout.getLargeVideo();
  904. };
  905. /**
  906. * Returns whether or not the passed in user id is currently pinned to the large
  907. * video.
  908. *
  909. * @param {string} userId - The id of the user to check is pinned or not.
  910. * @returns {boolean} True if the user is currently pinned to the large video.
  911. */
  912. UI.isPinned = userId => VideoLayout.getPinnedId() === userId;
  913. /**
  914. * Shows dialog with a link to FF extension.
  915. */
  916. UI.showExtensionRequiredDialog = function(url) {
  917. messageHandler.openMessageDialog(
  918. 'dialog.extensionRequired',
  919. '[html]dialog.firefoxExtensionPrompt',
  920. { url });
  921. };
  922. /**
  923. * Shows "Please go to chrome webstore to install the desktop sharing extension"
  924. * 2 button dialog with buttons - cancel and go to web store.
  925. * @param url {string} the url of the extension.
  926. */
  927. UI.showExtensionExternalInstallationDialog = function(url) {
  928. let openedWindow = null;
  929. const submitFunction = function(e, v) {
  930. if (v) {
  931. e.preventDefault();
  932. if (openedWindow === null || openedWindow.closed) {
  933. openedWindow
  934. = window.open(
  935. url,
  936. 'extension_store_window',
  937. 'resizable,scrollbars=yes,status=1');
  938. } else {
  939. openedWindow.focus();
  940. }
  941. }
  942. };
  943. const closeFunction = function(e, v) {
  944. if (openedWindow) {
  945. // Ideally we would close the popup, but this does not seem to work
  946. // on Chrome. Leaving it uncommented in case it could work
  947. // in some version.
  948. openedWindow.close();
  949. openedWindow = null;
  950. }
  951. if (!v) {
  952. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  953. }
  954. };
  955. messageHandler.openTwoButtonDialog({
  956. titleKey: 'dialog.externalInstallationTitle',
  957. msgKey: 'dialog.externalInstallationMsg',
  958. leftButtonKey: 'dialog.goToStore',
  959. submitFunction,
  960. loadedFunction: $.noop,
  961. closeFunction
  962. });
  963. };
  964. /**
  965. * Shows a dialog which asks user to install the extension. This one is
  966. * displayed after installation is triggered from the script, but fails because
  967. * it must be initiated by user gesture.
  968. * @param callback {function} function to be executed after user clicks
  969. * the install button - it should make another attempt to install the extension.
  970. */
  971. UI.showExtensionInlineInstallationDialog = function(callback) {
  972. const submitFunction = function(e, v) {
  973. if (v) {
  974. callback();
  975. }
  976. };
  977. const closeFunction = function(e, v) {
  978. if (!v) {
  979. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  980. }
  981. };
  982. messageHandler.openTwoButtonDialog({
  983. titleKey: 'dialog.externalInstallationTitle',
  984. msgKey: 'dialog.inlineInstallationMsg',
  985. leftButtonKey: 'dialog.inlineInstallExtension',
  986. submitFunction,
  987. loadedFunction: $.noop,
  988. closeFunction
  989. });
  990. };
  991. /**
  992. * Shows a notifications about the passed in microphone error.
  993. *
  994. * @param {JitsiTrackError} micError - An error object related to using or
  995. * acquiring an audio stream.
  996. * @returns {void}
  997. */
  998. UI.showMicErrorNotification = function(micError) {
  999. if (!micError) {
  1000. return;
  1001. }
  1002. const { message, name } = micError;
  1003. const micJitsiTrackErrorMsg
  1004. = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[name];
  1005. const micErrorMsg = micJitsiTrackErrorMsg
  1006. || JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  1007. .microphone[JitsiTrackErrors.GENERAL];
  1008. const additionalMicErrorMsg = micJitsiTrackErrorMsg ? null : message;
  1009. APP.store.dispatch(showWarningNotification({
  1010. description: additionalMicErrorMsg,
  1011. descriptionKey: micErrorMsg,
  1012. titleKey: name === JitsiTrackErrors.PERMISSION_DENIED
  1013. ? 'deviceError.microphonePermission'
  1014. : 'deviceError.microphoneError'
  1015. }));
  1016. };
  1017. /**
  1018. * Shows a notifications about the passed in camera error.
  1019. *
  1020. * @param {JitsiTrackError} cameraError - An error object related to using or
  1021. * acquiring a video stream.
  1022. * @returns {void}
  1023. */
  1024. UI.showCameraErrorNotification = function(cameraError) {
  1025. if (!cameraError) {
  1026. return;
  1027. }
  1028. const { message, name } = cameraError;
  1029. const cameraJitsiTrackErrorMsg
  1030. = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[name];
  1031. const cameraErrorMsg = cameraJitsiTrackErrorMsg
  1032. || JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  1033. .camera[JitsiTrackErrors.GENERAL];
  1034. const additionalCameraErrorMsg = cameraJitsiTrackErrorMsg ? null : message;
  1035. APP.store.dispatch(showWarningNotification({
  1036. description: additionalCameraErrorMsg,
  1037. descriptionKey: cameraErrorMsg,
  1038. titleKey: name === JitsiTrackErrors.PERMISSION_DENIED
  1039. ? 'deviceError.cameraPermission' : 'deviceError.cameraError'
  1040. }));
  1041. };
  1042. /**
  1043. * Shows error dialog that informs the user that no data is received from the
  1044. * device.
  1045. *
  1046. * @param {boolean} isAudioTrack - Whether or not the dialog is for an audio
  1047. * track error.
  1048. * @returns {void}
  1049. */
  1050. UI.showTrackNotWorkingDialog = function(isAudioTrack) {
  1051. messageHandler.showError({
  1052. descriptionKey: isAudioTrack
  1053. ? 'dialog.micNotSendingData' : 'dialog.cameraNotSendingData',
  1054. titleKey: isAudioTrack
  1055. ? 'dialog.micNotSendingDataTitle'
  1056. : 'dialog.cameraNotSendingDataTitle'
  1057. });
  1058. };
  1059. UI.updateDevicesAvailability = function(id, devices) {
  1060. VideoLayout.setDeviceAvailabilityIcons(id, devices);
  1061. };
  1062. /**
  1063. * Show shared video.
  1064. * @param {string} id the id of the sender of the command
  1065. * @param {string} url video url
  1066. * @param {string} attributes
  1067. */
  1068. UI.onSharedVideoStart = function(id, url, attributes) {
  1069. if (sharedVideoManager) {
  1070. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  1071. }
  1072. };
  1073. /**
  1074. * Update shared video.
  1075. * @param {string} id the id of the sender of the command
  1076. * @param {string} url video url
  1077. * @param {string} attributes
  1078. */
  1079. UI.onSharedVideoUpdate = function(id, url, attributes) {
  1080. if (sharedVideoManager) {
  1081. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  1082. }
  1083. };
  1084. /**
  1085. * Stop showing shared video.
  1086. * @param {string} id the id of the sender of the command
  1087. * @param {string} attributes
  1088. */
  1089. UI.onSharedVideoStop = function(id, attributes) {
  1090. if (sharedVideoManager) {
  1091. sharedVideoManager.onSharedVideoStop(id, attributes);
  1092. }
  1093. };
  1094. /**
  1095. * Handles user's features changes.
  1096. */
  1097. UI.onUserFeaturesChanged = user => VideoLayout.onUserFeaturesChanged(user);
  1098. /**
  1099. * Returns the number of known remote videos.
  1100. *
  1101. * @returns {number} The number of remote videos.
  1102. */
  1103. UI.getRemoteVideosCount = () => VideoLayout.getRemoteVideosCount();
  1104. /**
  1105. * Sets the remote control active status for a remote participant.
  1106. *
  1107. * @param {string} participantID - The id of the remote participant.
  1108. * @param {boolean} isActive - The new remote control active status.
  1109. * @returns {void}
  1110. */
  1111. UI.setRemoteControlActiveStatus = function(participantID, isActive) {
  1112. VideoLayout.setRemoteControlActiveStatus(participantID, isActive);
  1113. };
  1114. /**
  1115. * Sets the remote control active status for the local participant.
  1116. *
  1117. * @returns {void}
  1118. */
  1119. UI.setLocalRemoteControlActiveChanged = function() {
  1120. VideoLayout.setLocalRemoteControlActiveChanged();
  1121. };
  1122. // TODO: Export every function separately. For now there is no point of doing
  1123. // this because we are importing everything.
  1124. export default UI;