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

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