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

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