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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  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. // Configure avatar
  428. UI.setUserEmail(id);
  429. // set initial display name
  430. if (displayName) {
  431. UI.changeDisplayName(id, displayName);
  432. }
  433. };
  434. /**
  435. * Update videotype for specified user.
  436. * @param {string} id user id
  437. * @param {string} newVideoType new videotype
  438. */
  439. UI.onPeerVideoTypeChanged
  440. = (id, newVideoType) => VideoLayout.onVideoTypeChanged(id, newVideoType);
  441. /**
  442. * Update local user role and show notification if user is moderator.
  443. * @param {boolean} isModerator if local user is moderator or not
  444. */
  445. UI.updateLocalRole = isModerator => {
  446. VideoLayout.showModeratorIndicator();
  447. if (isModerator && !interfaceConfig.DISABLE_FOCUS_INDICATOR) {
  448. messageHandler.participantNotification(
  449. null, 'notify.me', 'connected', 'notify.moderator');
  450. }
  451. };
  452. /**
  453. * Check the role for the user and reflect it in the UI, moderator ui indication
  454. * and notifies user who is the moderator
  455. * @param user to check for moderator
  456. */
  457. UI.updateUserRole = user => {
  458. VideoLayout.showModeratorIndicator();
  459. // We don't need to show moderator notifications when the focus (moderator)
  460. // indicator is disabled.
  461. if (!user.isModerator() || interfaceConfig.DISABLE_FOCUS_INDICATOR) {
  462. return;
  463. }
  464. const displayName = user.getDisplayName();
  465. if (displayName) {
  466. messageHandler.participantNotification(
  467. displayName,
  468. 'notify.somebody',
  469. 'connected',
  470. 'notify.grantedTo',
  471. { to: UIUtil.escapeHtml(displayName) });
  472. } else {
  473. messageHandler.participantNotification(
  474. '',
  475. 'notify.somebody',
  476. 'connected',
  477. 'notify.grantedToUnknown');
  478. }
  479. };
  480. /**
  481. * Updates the user status.
  482. *
  483. * @param {JitsiParticipant} user - The user which status we need to update.
  484. * @param {string} status - The new status.
  485. */
  486. UI.updateUserStatus = (user, status) => {
  487. if (!status) {
  488. return;
  489. }
  490. const displayName = user.getDisplayName();
  491. messageHandler.participantNotification(
  492. displayName,
  493. '',
  494. 'connected',
  495. 'dialOut.statusMessage',
  496. { status: UIUtil.escapeHtml(status) });
  497. };
  498. /**
  499. * Toggles smileys in the chat.
  500. */
  501. UI.toggleSmileys = () => Chat.toggleSmileys();
  502. /**
  503. * Toggles filmstrip.
  504. */
  505. UI.toggleFilmstrip = function() {
  506. // eslint-disable-next-line prefer-rest-params
  507. Filmstrip.toggleFilmstrip(...arguments);
  508. VideoLayout.resizeVideoArea(true, false);
  509. };
  510. /**
  511. * Checks if the filmstrip is currently visible or not.
  512. * @returns {true} if the filmstrip is currently visible, and false otherwise.
  513. */
  514. UI.isFilmstripVisible = () => Filmstrip.isFilmstripVisible();
  515. /**
  516. * @returns {true} if the chat panel is currently visible, and false otherwise.
  517. */
  518. UI.isChatVisible = () => Chat.isVisible();
  519. /**
  520. * Toggles chat panel.
  521. */
  522. UI.toggleChat = () => UI.toggleSidePanel('chat_container');
  523. /**
  524. * Toggles the given side panel.
  525. *
  526. * @param {String} sidePanelId the identifier of the side panel to toggle
  527. */
  528. UI.toggleSidePanel = sidePanelId => SideContainerToggler.toggle(sidePanelId);
  529. /**
  530. * Handle new user display name.
  531. */
  532. UI.inputDisplayNameHandler = function(newDisplayName) {
  533. eventEmitter.emit(UIEvents.NICKNAME_CHANGED, newDisplayName);
  534. };
  535. /**
  536. * Return the type of the remote video.
  537. * @param jid the jid for the remote video
  538. * @returns the video type video or screen.
  539. */
  540. UI.getRemoteVideoType = function(jid) {
  541. return VideoLayout.getRemoteVideoType(jid);
  542. };
  543. // FIXME check if someone user this
  544. UI.showLoginPopup = function(callback) {
  545. logger.log('password is required');
  546. const message
  547. = `<input name="username" type="text"
  548. placeholder="user@domain.net"
  549. class="input-control" autofocus>
  550. <input name="password" type="password"
  551. data-i18n="[placeholder]dialog.userPassword"
  552. class="input-control"
  553. placeholder="user password">`
  554. ;
  555. // eslint-disable-next-line max-params
  556. const submitFunction = (e, v, m, f) => {
  557. if (v && f.username && f.password) {
  558. callback(f.username, f.password);
  559. }
  560. };
  561. messageHandler.openTwoButtonDialog({
  562. titleKey: 'dialog.passwordRequired',
  563. msgString: message,
  564. leftButtonKey: 'dialog.Ok',
  565. submitFunction,
  566. focus: ':input:first'
  567. });
  568. };
  569. UI.askForNickname = function() {
  570. // eslint-disable-next-line no-alert
  571. return window.prompt('Your nickname (optional)');
  572. };
  573. /**
  574. * Sets muted audio state for participant
  575. */
  576. UI.setAudioMuted = function(id, muted) {
  577. VideoLayout.onAudioMute(id, muted);
  578. if (APP.conference.isLocalId(id)) {
  579. APP.conference.updateAudioIconEnabled();
  580. }
  581. };
  582. /**
  583. * Sets muted video state for participant
  584. */
  585. UI.setVideoMuted = function(id, muted) {
  586. VideoLayout.onVideoMute(id, muted);
  587. if (APP.conference.isLocalId(id)) {
  588. APP.conference.updateVideoIconEnabled();
  589. }
  590. };
  591. /**
  592. * Triggers an update of remote video and large video displays so they may pick
  593. * up any state changes that have occurred elsewhere.
  594. *
  595. * @returns {void}
  596. */
  597. UI.updateAllVideos = () => VideoLayout.updateAllVideos();
  598. /**
  599. * Adds a listener that would be notified on the given type of event.
  600. *
  601. * @param type the type of the event we're listening for
  602. * @param listener a function that would be called when notified
  603. */
  604. UI.addListener = function(type, listener) {
  605. eventEmitter.on(type, listener);
  606. };
  607. /**
  608. * Removes the given listener for the given type of event.
  609. *
  610. * @param type the type of the event we're listening for
  611. * @param listener the listener we want to remove
  612. */
  613. UI.removeListener = function(type, listener) {
  614. eventEmitter.removeListener(type, listener);
  615. };
  616. /**
  617. * Emits the event of given type by specifying the parameters in options.
  618. *
  619. * @param type the type of the event we're emitting
  620. * @param options the parameters for the event
  621. */
  622. UI.emitEvent = (type, ...options) => eventEmitter.emit(type, ...options);
  623. UI.clickOnVideo = function(videoNumber) {
  624. const videos = $('#remoteVideos .videocontainer:not(#mixedstream)');
  625. const videosLength = videos.length;
  626. if (videosLength <= videoNumber) {
  627. return;
  628. }
  629. const videoIndex = videoNumber === 0 ? 0 : videosLength - videoNumber;
  630. videos[videoIndex].click();
  631. };
  632. // Used by torture.
  633. UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  634. // Used by torture.
  635. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  636. /**
  637. * Update user email.
  638. * @param {string} id user id
  639. * @param {string} email user email
  640. */
  641. UI.setUserEmail = function(id, email) {
  642. if (APP.conference.isLocalId(id)) {
  643. Profile.changeEmail(email);
  644. }
  645. };
  646. /**
  647. * Updates the displayed avatar for participant.
  648. *
  649. * @param {string} id - User id whose avatar should be updated.
  650. * @param {string} avatarURL - The URL to avatar image to display.
  651. * @returns {void}
  652. */
  653. UI.refreshAvatarDisplay = function(id, avatarURL) {
  654. VideoLayout.changeUserAvatar(id, avatarURL);
  655. };
  656. /**
  657. * Notify user that connection failed.
  658. * @param {string} stropheErrorMsg raw Strophe error message
  659. */
  660. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  661. let descriptionKey;
  662. let descriptionArguments;
  663. if (stropheErrorMsg) {
  664. descriptionKey = 'dialog.connectErrorWithMsg';
  665. descriptionArguments = { msg: stropheErrorMsg };
  666. } else {
  667. descriptionKey = 'dialog.connectError';
  668. }
  669. messageHandler.showError({
  670. descriptionArguments,
  671. descriptionKey,
  672. titleKey: 'connection.CONNFAIL'
  673. });
  674. };
  675. /**
  676. * Notify user that maximum users limit has been reached.
  677. */
  678. UI.notifyMaxUsersLimitReached = function() {
  679. messageHandler.showError({
  680. hideErrorSupportLink: true,
  681. descriptionKey: 'dialog.maxUsersLimitReached',
  682. titleKey: 'dialog.maxUsersLimitReachedTitle'
  683. });
  684. };
  685. /**
  686. * Notify user that he was automatically muted when joned the conference.
  687. */
  688. UI.notifyInitiallyMuted = function() {
  689. messageHandler.participantNotification(
  690. null,
  691. 'notify.mutedTitle',
  692. 'connected',
  693. 'notify.muted',
  694. null);
  695. };
  696. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  697. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  698. };
  699. /**
  700. * Prompt user for nickname.
  701. */
  702. UI.promptDisplayName = () => {
  703. APP.store.dispatch(openDisplayNamePrompt());
  704. };
  705. /**
  706. * Update audio level visualization for specified user.
  707. * @param {string} id user id
  708. * @param {number} lvl audio level
  709. */
  710. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  711. /**
  712. * Hide connection quality statistics from UI.
  713. */
  714. UI.hideStats = function() {
  715. VideoLayout.hideStats();
  716. };
  717. /**
  718. * Mark video as interrupted or not.
  719. * @param {boolean} interrupted if video is interrupted
  720. */
  721. UI.markVideoInterrupted = function(interrupted) {
  722. if (interrupted) {
  723. VideoLayout.onVideoInterrupted();
  724. } else {
  725. VideoLayout.onVideoRestored();
  726. }
  727. };
  728. /**
  729. * Add chat message.
  730. * @param {string} from user id
  731. * @param {string} displayName user nickname
  732. * @param {string} message message text
  733. * @param {number} stamp timestamp when message was created
  734. */
  735. // eslint-disable-next-line max-params
  736. UI.addMessage = function(from, displayName, message, stamp) {
  737. Chat.updateChatConversation(from, displayName, message, stamp);
  738. };
  739. UI.notifyTokenAuthFailed = function() {
  740. messageHandler.showError({
  741. descriptionKey: 'dialog.tokenAuthFailed',
  742. titleKey: 'dialog.tokenAuthFailedTitle'
  743. });
  744. };
  745. UI.notifyInternalError = function(error) {
  746. messageHandler.showError({
  747. descriptionArguments: { error },
  748. descriptionKey: 'dialog.internalError',
  749. titleKey: 'dialog.internalErrorTitle'
  750. });
  751. };
  752. UI.notifyFocusDisconnected = function(focus, retrySec) {
  753. messageHandler.participantNotification(
  754. null, 'notify.focus',
  755. 'disconnected', 'notify.focusFail',
  756. { component: focus,
  757. ms: retrySec }
  758. );
  759. };
  760. /**
  761. * Updates auth info on the UI.
  762. * @param {boolean} isAuthEnabled if authentication is enabled
  763. * @param {string} [login] current login
  764. */
  765. UI.updateAuthInfo = function(isAuthEnabled, login) {
  766. const showAuth = isAuthEnabled && UIUtil.isAuthenticationEnabled();
  767. const loggedIn = Boolean(login);
  768. Profile.showAuthenticationButtons(showAuth);
  769. if (showAuth) {
  770. Profile.setAuthenticatedIdentity(login);
  771. Profile.showLoginButton(!loggedIn);
  772. Profile.showLogoutButton(loggedIn);
  773. }
  774. };
  775. /**
  776. * Notifies interested listeners that the raise hand property has changed.
  777. *
  778. * @param {boolean} isRaisedHand indicates the current state of the
  779. * "raised hand"
  780. */
  781. UI.onLocalRaiseHandChanged = function(isRaisedHand) {
  782. eventEmitter.emit(UIEvents.LOCAL_RAISE_HAND_CHANGED, isRaisedHand);
  783. };
  784. /**
  785. * Update list of available physical devices.
  786. * @param {object[]} devices new list of available devices
  787. */
  788. UI.onAvailableDevicesChanged = function(devices) {
  789. APP.store.dispatch(updateDeviceList(devices));
  790. APP.conference.updateAudioIconEnabled();
  791. APP.conference.updateVideoIconEnabled();
  792. };
  793. /**
  794. * Returns the id of the current video shown on large.
  795. * Currently used by tests (torture).
  796. */
  797. UI.getLargeVideoID = function() {
  798. return VideoLayout.getLargeVideoID();
  799. };
  800. /**
  801. * Returns the current video shown on large.
  802. * Currently used by tests (torture).
  803. */
  804. UI.getLargeVideo = function() {
  805. return VideoLayout.getLargeVideo();
  806. };
  807. /**
  808. * Shows "Please go to chrome webstore to install the desktop sharing extension"
  809. * 2 button dialog with buttons - cancel and go to web store.
  810. * @param url {string} the url of the extension.
  811. */
  812. UI.showExtensionExternalInstallationDialog = function(url) {
  813. let openedWindow = null;
  814. const submitFunction = function(e, v) {
  815. if (v) {
  816. e.preventDefault();
  817. if (openedWindow === null || openedWindow.closed) {
  818. openedWindow
  819. = window.open(
  820. url,
  821. 'extension_store_window',
  822. 'resizable,scrollbars=yes,status=1');
  823. } else {
  824. openedWindow.focus();
  825. }
  826. }
  827. };
  828. const closeFunction = function(e, v) {
  829. if (openedWindow) {
  830. // Ideally we would close the popup, but this does not seem to work
  831. // on Chrome. Leaving it uncommented in case it could work
  832. // in some version.
  833. openedWindow.close();
  834. openedWindow = null;
  835. }
  836. if (!v) {
  837. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  838. }
  839. };
  840. messageHandler.openTwoButtonDialog({
  841. titleKey: 'dialog.externalInstallationTitle',
  842. msgKey: 'dialog.externalInstallationMsg',
  843. leftButtonKey: 'dialog.goToStore',
  844. submitFunction,
  845. loadedFunction: $.noop,
  846. closeFunction
  847. });
  848. };
  849. /**
  850. * Shows a dialog which asks user to install the extension. This one is
  851. * displayed after installation is triggered from the script, but fails because
  852. * it must be initiated by user gesture.
  853. * @param callback {function} function to be executed after user clicks
  854. * the install button - it should make another attempt to install the extension.
  855. */
  856. UI.showExtensionInlineInstallationDialog = function(callback) {
  857. const submitFunction = function(e, v) {
  858. if (v) {
  859. callback();
  860. }
  861. };
  862. const closeFunction = function(e, v) {
  863. if (!v) {
  864. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  865. }
  866. };
  867. messageHandler.openTwoButtonDialog({
  868. titleKey: 'dialog.externalInstallationTitle',
  869. msgKey: 'dialog.inlineInstallationMsg',
  870. leftButtonKey: 'dialog.inlineInstallExtension',
  871. submitFunction,
  872. loadedFunction: $.noop,
  873. closeFunction
  874. });
  875. };
  876. /**
  877. * Shows a notifications about the passed in microphone error.
  878. *
  879. * @param {JitsiTrackError} micError - An error object related to using or
  880. * acquiring an audio stream.
  881. * @returns {void}
  882. */
  883. UI.showMicErrorNotification = function(micError) {
  884. if (!micError) {
  885. return;
  886. }
  887. const { message, name } = micError;
  888. const micJitsiTrackErrorMsg
  889. = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[name];
  890. const micErrorMsg = micJitsiTrackErrorMsg
  891. || JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  892. .microphone[JitsiTrackErrors.GENERAL];
  893. const additionalMicErrorMsg = micJitsiTrackErrorMsg ? null : message;
  894. APP.store.dispatch(showWarningNotification({
  895. description: additionalMicErrorMsg,
  896. descriptionKey: micErrorMsg,
  897. titleKey: name === JitsiTrackErrors.PERMISSION_DENIED
  898. ? 'deviceError.microphonePermission'
  899. : 'deviceError.microphoneError'
  900. }));
  901. };
  902. /**
  903. * Shows a notifications about the passed in camera error.
  904. *
  905. * @param {JitsiTrackError} cameraError - An error object related to using or
  906. * acquiring a video stream.
  907. * @returns {void}
  908. */
  909. UI.showCameraErrorNotification = function(cameraError) {
  910. if (!cameraError) {
  911. return;
  912. }
  913. const { message, name } = cameraError;
  914. const cameraJitsiTrackErrorMsg
  915. = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[name];
  916. const cameraErrorMsg = cameraJitsiTrackErrorMsg
  917. || JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP
  918. .camera[JitsiTrackErrors.GENERAL];
  919. const additionalCameraErrorMsg = cameraJitsiTrackErrorMsg ? null : message;
  920. APP.store.dispatch(showWarningNotification({
  921. description: additionalCameraErrorMsg,
  922. descriptionKey: cameraErrorMsg,
  923. titleKey: name === JitsiTrackErrors.PERMISSION_DENIED
  924. ? 'deviceError.cameraPermission' : 'deviceError.cameraError'
  925. }));
  926. };
  927. /**
  928. * Shows error dialog that informs the user that no data is received from the
  929. * device.
  930. *
  931. * @param {boolean} isAudioTrack - Whether or not the dialog is for an audio
  932. * track error.
  933. * @returns {void}
  934. */
  935. UI.showTrackNotWorkingDialog = function(isAudioTrack) {
  936. messageHandler.showError({
  937. descriptionKey: isAudioTrack
  938. ? 'dialog.micNotSendingData' : 'dialog.cameraNotSendingData',
  939. titleKey: isAudioTrack
  940. ? 'dialog.micNotSendingDataTitle'
  941. : 'dialog.cameraNotSendingDataTitle'
  942. });
  943. };
  944. UI.updateDevicesAvailability = function(id, devices) {
  945. VideoLayout.setDeviceAvailabilityIcons(id, devices);
  946. };
  947. /**
  948. * Show shared video.
  949. * @param {string} id the id of the sender of the command
  950. * @param {string} url video url
  951. * @param {string} attributes
  952. */
  953. UI.onSharedVideoStart = function(id, url, attributes) {
  954. if (sharedVideoManager) {
  955. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  956. }
  957. };
  958. /**
  959. * Update shared video.
  960. * @param {string} id the id of the sender of the command
  961. * @param {string} url video url
  962. * @param {string} attributes
  963. */
  964. UI.onSharedVideoUpdate = function(id, url, attributes) {
  965. if (sharedVideoManager) {
  966. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  967. }
  968. };
  969. /**
  970. * Stop showing shared video.
  971. * @param {string} id the id of the sender of the command
  972. * @param {string} attributes
  973. */
  974. UI.onSharedVideoStop = function(id, attributes) {
  975. if (sharedVideoManager) {
  976. sharedVideoManager.onSharedVideoStop(id, attributes);
  977. }
  978. };
  979. /**
  980. * Handles user's features changes.
  981. */
  982. UI.onUserFeaturesChanged = user => VideoLayout.onUserFeaturesChanged(user);
  983. /**
  984. * Returns the number of known remote videos.
  985. *
  986. * @returns {number} The number of remote videos.
  987. */
  988. UI.getRemoteVideosCount = () => VideoLayout.getRemoteVideosCount();
  989. /**
  990. * Sets the remote control active status for a remote participant.
  991. *
  992. * @param {string} participantID - The id of the remote participant.
  993. * @param {boolean} isActive - The new remote control active status.
  994. * @returns {void}
  995. */
  996. UI.setRemoteControlActiveStatus = function(participantID, isActive) {
  997. VideoLayout.setRemoteControlActiveStatus(participantID, isActive);
  998. };
  999. /**
  1000. * Sets the remote control active status for the local participant.
  1001. *
  1002. * @returns {void}
  1003. */
  1004. UI.setLocalRemoteControlActiveChanged = function() {
  1005. VideoLayout.setLocalRemoteControlActiveChanged();
  1006. };
  1007. /**
  1008. * Remove media tracks and UI elements so the user no longer sees media in the
  1009. * UI. The intent is to provide a feeling that the meeting has ended.
  1010. *
  1011. * @returns {void}
  1012. */
  1013. UI.removeLocalMedia = function() {
  1014. APP.store.dispatch(destroyLocalTracks());
  1015. VideoLayout.resetLargeVideo();
  1016. $('#videospace').hide();
  1017. };
  1018. // TODO: Export every function separately. For now there is no point of doing
  1019. // this because we are importing everything.
  1020. export default UI;