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

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