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

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