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 35KB

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