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.

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