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

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