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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555
  1. /* global APP, JitsiMeetJS, $, config, interfaceConfig, toastr */
  2. /* jshint -W101 */
  3. var UI = {};
  4. import Chat from "./side_pannels/chat/Chat";
  5. import Toolbar from "./toolbars/Toolbar";
  6. import ToolbarToggler from "./toolbars/ToolbarToggler";
  7. import ContactList from "./side_pannels/contactlist/ContactList";
  8. import Avatar from "./avatar/Avatar";
  9. import SideContainerToggler from "./side_pannels/SideContainerToggler";
  10. import UIUtil from "./util/UIUtil";
  11. import UIEvents from "../../service/UI/UIEvents";
  12. import CQEvents from '../../service/connectionquality/CQEvents';
  13. import EtherpadManager from './etherpad/Etherpad';
  14. import SharedVideoManager from './shared_video/SharedVideo';
  15. import Recording from "./recording/Recording";
  16. import GumPermissionsOverlay from './gum_overlay/UserMediaPermissionsGuidanceOverlay';
  17. import VideoLayout from "./videolayout/VideoLayout";
  18. import FilmStrip from "./videolayout/FilmStrip";
  19. import SettingsMenu from "./side_pannels/settings/SettingsMenu";
  20. import Profile from "./side_pannels/profile/Profile";
  21. import Settings from "./../settings/Settings";
  22. import { reload } from '../util/helpers';
  23. import RingOverlay from "./ring_overlay/RingOverlay";
  24. import UIErrors from './UIErrors';
  25. var EventEmitter = require("events");
  26. UI.messageHandler = require("./util/MessageHandler");
  27. var messageHandler = UI.messageHandler;
  28. var JitsiPopover = require("./util/JitsiPopover");
  29. var Feedback = require("./feedback/Feedback");
  30. import FollowMe from "../FollowMe";
  31. var eventEmitter = new EventEmitter();
  32. UI.eventEmitter = eventEmitter;
  33. let etherpadManager;
  34. let sharedVideoManager;
  35. let followMeHandler;
  36. let deviceErrorDialog;
  37. const TrackErrors = JitsiMeetJS.errors.track;
  38. const JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP = {
  39. microphone: {},
  40. camera: {}
  41. };
  42. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.UNSUPPORTED_RESOLUTION]
  43. = "dialog.cameraUnsupportedResolutionError";
  44. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.GENERAL]
  45. = "dialog.cameraUnknownError";
  46. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.PERMISSION_DENIED]
  47. = "dialog.cameraPermissionDeniedError";
  48. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.NOT_FOUND]
  49. = "dialog.cameraNotFoundError";
  50. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.CONSTRAINT_FAILED]
  51. = "dialog.cameraConstraintFailedError";
  52. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.NO_DATA_FROM_SOURCE]
  53. = "dialog.cameraNotSendingData";
  54. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.GENERAL]
  55. = "dialog.micUnknownError";
  56. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.PERMISSION_DENIED]
  57. = "dialog.micPermissionDeniedError";
  58. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.NOT_FOUND]
  59. = "dialog.micNotFoundError";
  60. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.CONSTRAINT_FAILED]
  61. = "dialog.micConstraintFailedError";
  62. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.NO_DATA_FROM_SOURCE]
  63. = "dialog.micNotSendingData";
  64. /**
  65. * Prompt user for nickname.
  66. */
  67. function promptDisplayName() {
  68. let nickRequiredMsg
  69. = APP.translation.translateString("dialog.displayNameRequired");
  70. let defaultNickMsg = APP.translation.translateString("defaultNickname");
  71. let message = `
  72. <h2 data-i18n="dialog.displayNameRequired">${nickRequiredMsg}</h2>
  73. <input name="displayName" type="text"
  74. data-i18n="[placeholder]defaultNickname"
  75. placeholder="${defaultNickMsg}" autofocus>`;
  76. // Don't use a translation string, because we're too early in the call and
  77. // the translation may not be initialised.
  78. let buttons = {Ok:true};
  79. let dialog = messageHandler.openDialog(
  80. null,
  81. message,
  82. true,
  83. buttons,
  84. function (e, v, m, f) {
  85. e.preventDefault();
  86. if (v) {
  87. let displayName = f.displayName;
  88. if (displayName) {
  89. UI.inputDisplayNameHandler(displayName);
  90. dialog.close();
  91. return;
  92. }
  93. }
  94. },
  95. function () {
  96. let form = $.prompt.getPrompt();
  97. let input = form.find("input[name='displayName']");
  98. input.focus();
  99. let button = form.find("button");
  100. button.attr("disabled", "disabled");
  101. input.keyup(function () {
  102. if (input.val()) {
  103. button.removeAttr("disabled");
  104. } else {
  105. button.attr("disabled", "disabled");
  106. }
  107. });
  108. }
  109. );
  110. }
  111. /**
  112. * Initialize chat.
  113. */
  114. function setupChat() {
  115. Chat.init(eventEmitter);
  116. $("#toggle_smileys").click(function() {
  117. Chat.toggleSmileys();
  118. });
  119. }
  120. /**
  121. * Initialize toolbars.
  122. */
  123. function setupToolbars() {
  124. Toolbar.init(eventEmitter);
  125. }
  126. /**
  127. * Toggles the application in and out of full screen mode
  128. * (a.k.a. presentation mode in Chrome).
  129. * @see https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API
  130. */
  131. UI.toggleFullScreen = function() {
  132. // alternative standard method
  133. let isNotFullScreen = !document.fullscreenElement &&
  134. !document.mozFullScreenElement && // current working methods
  135. !document.webkitFullscreenElement &&
  136. !document.msFullscreenElement;
  137. if (isNotFullScreen) {
  138. if (document.documentElement.requestFullscreen) {
  139. document.documentElement.requestFullscreen();
  140. } else if (document.documentElement.msRequestFullscreen) {
  141. document.documentElement.msRequestFullscreen();
  142. } else if (document.documentElement.mozRequestFullScreen) {
  143. document.documentElement.mozRequestFullScreen();
  144. } else if (document.documentElement.webkitRequestFullscreen) {
  145. document.documentElement
  146. .webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  147. }
  148. } else {
  149. if (document.exitFullscreen) {
  150. document.exitFullscreen();
  151. } else if (document.msExitFullscreen) {
  152. document.msExitFullscreen();
  153. } else if (document.mozCancelFullScreen) {
  154. document.mozCancelFullScreen();
  155. } else if (document.webkitExitFullscreen) {
  156. document.webkitExitFullscreen();
  157. }
  158. }
  159. };
  160. /**
  161. * Notify user that server has shut down.
  162. */
  163. UI.notifyGracefulShutdown = function () {
  164. messageHandler.openMessageDialog(
  165. 'dialog.serviceUnavailable',
  166. 'dialog.gracefulShutdown'
  167. );
  168. };
  169. /**
  170. * Notify user that reservation error happened.
  171. */
  172. UI.notifyReservationError = function (code, msg) {
  173. var title = APP.translation.generateTranslationHTML(
  174. "dialog.reservationError");
  175. var message = APP.translation.generateTranslationHTML(
  176. "dialog.reservationErrorMsg", {code: code, msg: msg});
  177. messageHandler.openDialog(
  178. title,
  179. message,
  180. true, {},
  181. function (event, value, message, formVals) {
  182. return false;
  183. }
  184. );
  185. };
  186. /**
  187. * Notify user that he has been kicked from the server.
  188. */
  189. UI.notifyKicked = function () {
  190. messageHandler.openMessageDialog("dialog.sessTerminated", "dialog.kickMessage");
  191. };
  192. /**
  193. * Notify user that conference was destroyed.
  194. * @param reason {string} the reason text
  195. */
  196. UI.notifyConferenceDestroyed = function (reason) {
  197. //FIXME: use Session Terminated from translation, but
  198. // 'reason' text comes from XMPP packet and is not translated
  199. var title = APP.translation.generateTranslationHTML("dialog.sessTerminated");
  200. messageHandler.openDialog(
  201. title, reason, true, {},
  202. function (event, value, message, formVals) {
  203. return false;
  204. }
  205. );
  206. };
  207. /**
  208. * Notify user that Jitsi Videobridge is not accessible.
  209. */
  210. UI.notifyBridgeDown = function () {
  211. messageHandler.showError("dialog.error", "dialog.bridgeUnavailable");
  212. };
  213. /**
  214. * Show chat error.
  215. * @param err the Error
  216. * @param msg
  217. */
  218. UI.showChatError = function (err, msg) {
  219. if (interfaceConfig.filmStripOnly) {
  220. return;
  221. }
  222. Chat.chatAddError(err, msg);
  223. };
  224. /**
  225. * Change nickname for the user.
  226. * @param {string} id user id
  227. * @param {string} displayName new nickname
  228. */
  229. UI.changeDisplayName = function (id, displayName) {
  230. ContactList.onDisplayNameChange(id, displayName);
  231. VideoLayout.onDisplayNameChanged(id, displayName);
  232. if (APP.conference.isLocalId(id) || id === 'localVideoContainer') {
  233. Profile.changeDisplayName(displayName);
  234. Chat.setChatConversationMode(!!displayName);
  235. }
  236. };
  237. /**
  238. * Shows/hides the indication about local connection being interrupted.
  239. *
  240. * @param {boolean} isInterrupted <tt>true</tt> if local connection is
  241. * currently in the interrupted state or <tt>false</tt> if the connection
  242. * is fine.
  243. */
  244. UI.showLocalConnectionInterrupted = function (isInterrupted) {
  245. VideoLayout.showLocalConnectionInterrupted(isInterrupted);
  246. };
  247. /**
  248. * Sets the "raised hand" status for a participant.
  249. */
  250. UI.setRaisedHandStatus = (participant, raisedHandStatus) => {
  251. VideoLayout.setRaisedHandStatus(participant.getId(), raisedHandStatus);
  252. if (raisedHandStatus) {
  253. messageHandler.notify(participant.getDisplayName(), 'notify.somebody',
  254. 'connected', 'notify.raisedHand');
  255. }
  256. };
  257. /**
  258. * Sets the local "raised hand" status.
  259. */
  260. UI.setLocalRaisedHandStatus = (raisedHandStatus) => {
  261. VideoLayout.setRaisedHandStatus(APP.conference.getMyUserId(), raisedHandStatus);
  262. };
  263. /**
  264. * Initialize conference UI.
  265. */
  266. UI.initConference = function () {
  267. let id = APP.conference.getMyUserId();
  268. // Do not include query parameters in the invite URL
  269. // "https:" + "//" + "example.com:8888" + "/SomeConference1245"
  270. var inviteURL = window.location.protocol + "//" +
  271. window.location.host + window.location.pathname;
  272. Toolbar.updateRoomUrl(inviteURL);
  273. // Clean up the URL displayed by the browser
  274. if (window.history && typeof window.history.replaceState === 'function') {
  275. window.history.replaceState({}, document.title, inviteURL);
  276. }
  277. // Add myself to the contact list.
  278. ContactList.addContact(id, true);
  279. // Update default button states before showing the toolbar
  280. // if local role changes buttons state will be again updated.
  281. UI.updateLocalRole(APP.conference.isModerator);
  282. UI.showToolbar();
  283. let displayName = config.displayJids ? id : Settings.getDisplayName();
  284. if (displayName) {
  285. UI.changeDisplayName('localVideoContainer', displayName);
  286. }
  287. // Make sure we configure our avatar id, before creating avatar for us
  288. let email = Settings.getEmail();
  289. if (email) {
  290. UI.setUserEmail(id, email);
  291. } else {
  292. UI.setUserAvatarID(id, Settings.getAvatarId());
  293. }
  294. Toolbar.checkAutoEnableDesktopSharing();
  295. if(!interfaceConfig.filmStripOnly) {
  296. Feedback.init(eventEmitter);
  297. }
  298. // FollowMe attempts to copy certain aspects of the moderator's UI into the
  299. // other participants' UI. Consequently, it needs (1) read and write access
  300. // to the UI (depending on the moderator role of the local participant) and
  301. // (2) APP.conference as means of communication between the participants.
  302. followMeHandler = new FollowMe(APP.conference, UI);
  303. UIUtil.activateTooltips();
  304. };
  305. UI.mucJoined = function () {
  306. VideoLayout.mucJoined();
  307. };
  308. /***
  309. * Handler for toggling filmstrip
  310. */
  311. UI.handleToggleFilmStrip = () => {
  312. UI.toggleFilmStrip();
  313. VideoLayout.resizeVideoArea(true, false);
  314. };
  315. /**
  316. * Sets tooltip defaults.
  317. *
  318. * @private
  319. */
  320. function _setTooltipDefaults() {
  321. $.fn.tooltip.defaults = {
  322. opacity: 1, //defaults to 1
  323. offset: 1,
  324. delayIn: 0, //defaults to 500
  325. hoverable: true,
  326. hideOnClick: true,
  327. aria: true
  328. };
  329. }
  330. /**
  331. * Setup some UI event listeners.
  332. */
  333. function registerListeners() {
  334. UI.addListener(UIEvents.ETHERPAD_CLICKED, function () {
  335. if (etherpadManager) {
  336. etherpadManager.toggleEtherpad();
  337. }
  338. });
  339. UI.addListener(UIEvents.SHARED_VIDEO_CLICKED, function () {
  340. if (sharedVideoManager) {
  341. sharedVideoManager.toggleSharedVideo();
  342. }
  343. });
  344. UI.addListener(UIEvents.FULLSCREEN_TOGGLE, UI.toggleFullScreen);
  345. UI.addListener(UIEvents.TOGGLE_CHAT, UI.toggleChat);
  346. UI.addListener(UIEvents.TOGGLE_SETTINGS, function () {
  347. UI.toggleSidePanel("settings_container");
  348. });
  349. UI.addListener(UIEvents.TOGGLE_CONTACT_LIST, UI.toggleContactList);
  350. UI.addListener( UIEvents.TOGGLE_PROFILE, function() {
  351. if(APP.tokenData.isGuest)
  352. UI.toggleSidePanel("profile_container");
  353. });
  354. UI.addListener(UIEvents.TOGGLE_FILM_STRIP, UI.handleToggleFilmStrip);
  355. UI.addListener(UIEvents.FOLLOW_ME_ENABLED, function (isEnabled) {
  356. if (followMeHandler)
  357. followMeHandler.enableFollowMe(isEnabled);
  358. });
  359. }
  360. /**
  361. * Setup some DOM event listeners.
  362. */
  363. function bindEvents() {
  364. function onResize() {
  365. SideContainerToggler.resize();
  366. VideoLayout.resizeVideoArea();
  367. }
  368. // Resize and reposition videos in full screen mode.
  369. $(document).on(
  370. 'webkitfullscreenchange mozfullscreenchange fullscreenchange',
  371. onResize
  372. );
  373. $(window).resize(onResize);
  374. }
  375. /**
  376. * Returns the shared document manager object.
  377. * @return {EtherpadManager} the shared document manager object
  378. */
  379. UI.getSharedVideoManager = function () {
  380. return sharedVideoManager;
  381. };
  382. /**
  383. * Starts the UI module and initializes all related components.
  384. *
  385. * @returns {boolean} true if the UI is ready and the conference should be
  386. * esablished, false - otherwise (for example in the case of welcome page)
  387. */
  388. UI.start = function () {
  389. document.title = interfaceConfig.APP_NAME;
  390. var setupWelcomePage = null;
  391. if(config.enableWelcomePage && window.location.pathname == "/" &&
  392. Settings.isWelcomePageEnabled()) {
  393. $("#videoconference_page").hide();
  394. if (!setupWelcomePage)
  395. setupWelcomePage = require("./welcome_page/WelcomePage");
  396. setupWelcomePage();
  397. // Return false to indicate that the UI hasn't been fully started and
  398. // conference ready. We're still waiting for input from the user.
  399. return false;
  400. }
  401. $("#welcome_page").hide();
  402. // Set the defaults for prompt dialogs.
  403. $.prompt.setDefaults({persistent: false});
  404. // Set the defaults for tooltips.
  405. _setTooltipDefaults();
  406. registerListeners();
  407. ToolbarToggler.init();
  408. SideContainerToggler.init(eventEmitter);
  409. FilmStrip.init(eventEmitter);
  410. VideoLayout.init(eventEmitter);
  411. if (!interfaceConfig.filmStripOnly) {
  412. VideoLayout.initLargeVideo();
  413. }
  414. VideoLayout.resizeVideoArea(true, true);
  415. ContactList.init(eventEmitter);
  416. bindEvents();
  417. sharedVideoManager = new SharedVideoManager(eventEmitter);
  418. if (!interfaceConfig.filmStripOnly) {
  419. $("#videoconference_page").mousemove(function () {
  420. return UI.showToolbar();
  421. });
  422. setupToolbars();
  423. setupChat();
  424. // Initialise the recording module.
  425. if (config.enableRecording)
  426. Recording.init(eventEmitter, config.recordingType);
  427. // Display notice message at the top of the toolbar
  428. if (config.noticeMessage) {
  429. $('#noticeText').text(config.noticeMessage);
  430. $('#notice').css({display: 'block'});
  431. }
  432. } else {
  433. $("#mainToolbarContainer").css("display", "none");
  434. FilmStrip.setupFilmStripOnly();
  435. messageHandler.enableNotifications(false);
  436. JitsiPopover.enabled = false;
  437. }
  438. document.title = interfaceConfig.APP_NAME;
  439. if(config.requireDisplayName) {
  440. if (!APP.settings.getDisplayName()) {
  441. promptDisplayName();
  442. }
  443. }
  444. if (!interfaceConfig.filmStripOnly) {
  445. toastr.options = {
  446. "closeButton": true,
  447. "debug": false,
  448. "positionClass": "notification-bottom-right",
  449. "onclick": null,
  450. "showDuration": "300",
  451. "hideDuration": "1000",
  452. "timeOut": "2000",
  453. "extendedTimeOut": "1000",
  454. "showEasing": "swing",
  455. "hideEasing": "linear",
  456. "showMethod": "fadeIn",
  457. "hideMethod": "fadeOut",
  458. "newestOnTop": false
  459. };
  460. SettingsMenu.init(eventEmitter);
  461. Profile.init(eventEmitter);
  462. }
  463. if(APP.tokenData.callee) {
  464. UI.showRingOverLay();
  465. }
  466. // Return true to indicate that the UI has been fully started and
  467. // conference ready.
  468. return true;
  469. };
  470. /**
  471. * Show local stream on UI.
  472. * @param {JitsiTrack} track stream to show
  473. */
  474. UI.addLocalStream = function (track) {
  475. switch (track.getType()) {
  476. case 'audio':
  477. VideoLayout.changeLocalAudio(track);
  478. break;
  479. case 'video':
  480. VideoLayout.changeLocalVideo(track);
  481. break;
  482. default:
  483. console.error("Unknown stream type: " + track.getType());
  484. break;
  485. }
  486. };
  487. /**
  488. * Show remote stream on UI.
  489. * @param {JitsiTrack} track stream to show
  490. */
  491. UI.addRemoteStream = function (track) {
  492. VideoLayout.onRemoteStreamAdded(track);
  493. };
  494. /**
  495. * Removed remote stream from UI.
  496. * @param {JitsiTrack} track stream to remove
  497. */
  498. UI.removeRemoteStream = function (track) {
  499. VideoLayout.onRemoteStreamRemoved(track);
  500. };
  501. function chatAddError(errorMessage, originalText) {
  502. return Chat.chatAddError(errorMessage, originalText);
  503. }
  504. /**
  505. * Update chat subject.
  506. * @param {string} subject new chat subject
  507. */
  508. UI.setSubject = function (subject) {
  509. Chat.setSubject(subject);
  510. };
  511. /**
  512. * Setup and show Etherpad.
  513. * @param {string} name etherpad id
  514. */
  515. UI.initEtherpad = function (name) {
  516. if (etherpadManager || !config.etherpad_base || !name) {
  517. return;
  518. }
  519. console.log('Etherpad is enabled');
  520. etherpadManager
  521. = new EtherpadManager(config.etherpad_base, name, eventEmitter);
  522. Toolbar.showEtherpadButton();
  523. };
  524. /**
  525. * Returns the shared document manager object.
  526. * @return {EtherpadManager} the shared document manager object
  527. */
  528. UI.getSharedDocumentManager = function () {
  529. return etherpadManager;
  530. };
  531. /**
  532. * Show user on UI.
  533. * @param {JitsiParticipant} user
  534. */
  535. UI.addUser = function (user) {
  536. var id = user.getId();
  537. var displayName = user.getDisplayName();
  538. UI.hideRingOverLay();
  539. ContactList.addContact(id);
  540. messageHandler.notify(
  541. displayName,'notify.somebody', 'connected', 'notify.connected'
  542. );
  543. if (!config.startAudioMuted ||
  544. config.startAudioMuted > APP.conference.membersCount)
  545. UIUtil.playSoundNotification('userJoined');
  546. // Add Peer's container
  547. VideoLayout.addParticipantContainer(user);
  548. // Configure avatar
  549. UI.setUserEmail(id);
  550. // set initial display name
  551. if(displayName)
  552. UI.changeDisplayName(id, displayName);
  553. };
  554. /**
  555. * Remove user from UI.
  556. * @param {string} id user id
  557. * @param {string} displayName user nickname
  558. */
  559. UI.removeUser = function (id, displayName) {
  560. ContactList.removeContact(id);
  561. messageHandler.notify(
  562. displayName,'notify.somebody', 'disconnected', 'notify.disconnected'
  563. );
  564. if (!config.startAudioMuted
  565. || config.startAudioMuted > APP.conference.membersCount) {
  566. UIUtil.playSoundNotification('userLeft');
  567. }
  568. VideoLayout.removeParticipantContainer(id);
  569. };
  570. UI.updateUserStatus = function (id, status) {
  571. VideoLayout.setPresenceStatus(id, status);
  572. };
  573. /**
  574. * Update videotype for specified user.
  575. * @param {string} id user id
  576. * @param {string} newVideoType new videotype
  577. */
  578. UI.onPeerVideoTypeChanged = (id, newVideoType) => {
  579. VideoLayout.onVideoTypeChanged(id, newVideoType);
  580. };
  581. /**
  582. * Update local user role and show notification if user is moderator.
  583. * @param {boolean} isModerator if local user is moderator or not
  584. */
  585. UI.updateLocalRole = function (isModerator) {
  586. VideoLayout.showModeratorIndicator();
  587. Toolbar.showSipCallButton(isModerator);
  588. Toolbar.showSharedVideoButton(isModerator);
  589. Recording.showRecordingButton(isModerator);
  590. SettingsMenu.showStartMutedOptions(isModerator);
  591. SettingsMenu.showFollowMeOptions(isModerator);
  592. if (isModerator) {
  593. if (!interfaceConfig.DISABLE_FOCUS_INDICATOR)
  594. messageHandler
  595. .notify(null, "notify.me", 'connected', "notify.moderator");
  596. Recording.checkAutoRecord();
  597. }
  598. };
  599. /**
  600. * Check the role for the user and reflect it in the UI, moderator ui indication
  601. * and notifies user who is the moderator
  602. * @param user to check for moderator
  603. */
  604. UI.updateUserRole = function (user) {
  605. VideoLayout.showModeratorIndicator();
  606. // We don't need to show moderator notifications when the focus (moderator)
  607. // indicator is disabled.
  608. if (!user.isModerator() || interfaceConfig.DISABLE_FOCUS_INDICATOR) {
  609. return;
  610. }
  611. var displayName = user.getDisplayName();
  612. if (displayName) {
  613. messageHandler.notify(
  614. displayName, 'notify.somebody',
  615. 'connected', 'notify.grantedTo', {
  616. to: UIUtil.escapeHtml(displayName)
  617. }
  618. );
  619. } else {
  620. messageHandler.notify(
  621. '', 'notify.somebody',
  622. 'connected', 'notify.grantedToUnknown', {}
  623. );
  624. }
  625. };
  626. /**
  627. * Toggles smileys in the chat.
  628. */
  629. UI.toggleSmileys = function () {
  630. Chat.toggleSmileys();
  631. };
  632. /**
  633. * Toggles film strip.
  634. */
  635. UI.toggleFilmStrip = function () {
  636. var self = FilmStrip;
  637. self.toggleFilmStrip.apply(self, arguments);
  638. };
  639. /**
  640. * Indicates if the film strip is currently visible or not.
  641. * @returns {true} if the film strip is currently visible, otherwise
  642. */
  643. UI.isFilmStripVisible = function () {
  644. return FilmStrip.isFilmStripVisible();
  645. };
  646. /**
  647. * Toggles chat panel.
  648. */
  649. UI.toggleChat = function () {
  650. UI.toggleSidePanel("chat_container");
  651. };
  652. /**
  653. * Toggles contact list panel.
  654. */
  655. UI.toggleContactList = function () {
  656. UI.toggleSidePanel("contacts_container");
  657. };
  658. /**
  659. * Toggles the given side panel.
  660. *
  661. * @param {String} sidePanelId the identifier of the side panel to toggle
  662. */
  663. UI.toggleSidePanel = function (sidePanelId) {
  664. SideContainerToggler.toggle(sidePanelId);
  665. };
  666. /**
  667. * Handle new user display name.
  668. */
  669. UI.inputDisplayNameHandler = function (newDisplayName) {
  670. eventEmitter.emit(UIEvents.NICKNAME_CHANGED, newDisplayName);
  671. };
  672. /**
  673. * Return the type of the remote video.
  674. * @param jid the jid for the remote video
  675. * @returns the video type video or screen.
  676. */
  677. UI.getRemoteVideoType = function (jid) {
  678. return VideoLayout.getRemoteVideoType(jid);
  679. };
  680. UI.connectionIndicatorShowMore = function(id) {
  681. VideoLayout.showMore(id);
  682. };
  683. // FIXME check if someone user this
  684. UI.showLoginPopup = function(callback) {
  685. console.log('password is required');
  686. var message = '<h2 data-i18n="dialog.passwordRequired">';
  687. message += APP.translation.translateString(
  688. "dialog.passwordRequired");
  689. message += '</h2>' +
  690. '<input name="username" type="text" ' +
  691. 'placeholder="user@domain.net" autofocus>' +
  692. '<input name="password" ' +
  693. 'type="password" data-i18n="[placeholder]dialog.userPassword"' +
  694. ' placeholder="user password">';
  695. messageHandler.openTwoButtonDialog(null, null, null, message,
  696. true,
  697. "dialog.Ok",
  698. function (e, v, m, f) {
  699. if (v) {
  700. if (f.username && f.password) {
  701. callback(f.username, f.password);
  702. }
  703. }
  704. },
  705. null, null, ':input:first'
  706. );
  707. };
  708. UI.askForNickname = function () {
  709. return window.prompt('Your nickname (optional)');
  710. };
  711. /**
  712. * Sets muted audio state for participant
  713. */
  714. UI.setAudioMuted = function (id, muted) {
  715. VideoLayout.onAudioMute(id, muted);
  716. if (APP.conference.isLocalId(id)) {
  717. Toolbar.markAudioIconAsMuted(muted);
  718. }
  719. };
  720. /**
  721. * Sets muted video state for participant
  722. */
  723. UI.setVideoMuted = function (id, muted) {
  724. VideoLayout.onVideoMute(id, muted);
  725. if (APP.conference.isLocalId(id)) {
  726. Toolbar.markVideoIconAsMuted(muted);
  727. }
  728. };
  729. /**
  730. * Adds a listener that would be notified on the given type of event.
  731. *
  732. * @param type the type of the event we're listening for
  733. * @param listener a function that would be called when notified
  734. */
  735. UI.addListener = function (type, listener) {
  736. eventEmitter.on(type, listener);
  737. };
  738. /**
  739. * Removes the given listener for the given type of event.
  740. *
  741. * @param type the type of the event we're listening for
  742. * @param listener the listener we want to remove
  743. */
  744. UI.removeListener = function (type, listener) {
  745. eventEmitter.removeListener(type, listener);
  746. };
  747. /**
  748. * Emits the event of given type by specifying the parameters in options.
  749. *
  750. * @param type the type of the event we're emitting
  751. * @param options the parameters for the event
  752. */
  753. UI.emitEvent = function (type, options) {
  754. eventEmitter.emit(type, options);
  755. };
  756. UI.clickOnVideo = function (videoNumber) {
  757. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  758. if (remoteVideos.length > videoNumber) {
  759. remoteVideos[videoNumber].click();
  760. }
  761. };
  762. //Used by torture
  763. UI.showToolbar = function (timeout) {
  764. return ToolbarToggler.showToolbar(timeout);
  765. };
  766. //Used by torture
  767. UI.dockToolbar = function (isDock) {
  768. ToolbarToggler.dockToolbar(isDock);
  769. };
  770. /**
  771. * Updates the avatar for participant.
  772. * @param {string} id user id
  773. * @param {string} avatarUrl the URL for the avatar
  774. */
  775. function changeAvatar(id, avatarUrl) {
  776. VideoLayout.changeUserAvatar(id, avatarUrl);
  777. ContactList.changeUserAvatar(id, avatarUrl);
  778. if (APP.conference.isLocalId(id)) {
  779. Profile.changeAvatar(avatarUrl);
  780. }
  781. }
  782. /**
  783. * Update user email.
  784. * @param {string} id user id
  785. * @param {string} email user email
  786. */
  787. UI.setUserEmail = function (id, email) {
  788. // update avatar
  789. Avatar.setUserEmail(id, email);
  790. changeAvatar(id, Avatar.getAvatarUrl(id));
  791. };
  792. /**
  793. * Update user avtar id.
  794. * @param {string} id user id
  795. * @param {string} avatarId user's avatar id
  796. */
  797. UI.setUserAvatarID = function (id, avatarId) {
  798. // update avatar
  799. Avatar.setUserAvatarID(id, avatarId);
  800. changeAvatar(id, Avatar.getAvatarUrl(id));
  801. };
  802. /**
  803. * Update user avatar URL.
  804. * @param {string} id user id
  805. * @param {string} url user avatar url
  806. */
  807. UI.setUserAvatarUrl = function (id, url) {
  808. // update avatar
  809. Avatar.setUserAvatarUrl(id, url);
  810. changeAvatar(id, Avatar.getAvatarUrl(id));
  811. };
  812. /**
  813. * Notify user that connection failed.
  814. * @param {string} stropheErrorMsg raw Strophe error message
  815. */
  816. UI.notifyConnectionFailed = function (stropheErrorMsg) {
  817. var title = APP.translation.generateTranslationHTML(
  818. "dialog.error");
  819. var message;
  820. if (stropheErrorMsg) {
  821. message = APP.translation.generateTranslationHTML(
  822. "dialog.connectErrorWithMsg", {msg: stropheErrorMsg});
  823. } else {
  824. message = APP.translation.generateTranslationHTML(
  825. "dialog.connectError");
  826. }
  827. messageHandler.openDialog(
  828. title, message, true, {}, function (e, v, m, f) { return false; }
  829. );
  830. };
  831. /**
  832. * Notify user that maximum users limit has been reached.
  833. */
  834. UI.notifyMaxUsersLimitReached = function () {
  835. var title = APP.translation.generateTranslationHTML(
  836. "dialog.error");
  837. var message = APP.translation.generateTranslationHTML(
  838. "dialog.maxUsersLimitReached");
  839. messageHandler.openDialog(
  840. title, message, true, {}, function (e, v, m, f) { return false; }
  841. );
  842. };
  843. /**
  844. * Notify user that he was automatically muted when joned the conference.
  845. */
  846. UI.notifyInitiallyMuted = function () {
  847. messageHandler.notify(
  848. null, "notify.mutedTitle", "connected", "notify.muted", null, {timeOut: 120000}
  849. );
  850. };
  851. /**
  852. * Mark user as dominant speaker.
  853. * @param {string} id user id
  854. */
  855. UI.markDominantSpeaker = function (id) {
  856. VideoLayout.onDominantSpeakerChanged(id);
  857. };
  858. UI.handleLastNEndpoints = function (ids, enteringIds) {
  859. VideoLayout.onLastNEndpointsChanged(ids, enteringIds);
  860. };
  861. /**
  862. * Will handle notification about participant's connectivity status change.
  863. *
  864. * @param {string} id the id of remote participant(MUC jid)
  865. * @param {boolean} isActive true if the connection is ok or false if the user
  866. * is having connectivity issues.
  867. */
  868. UI.participantConnectionStatusChanged = function (id, isActive) {
  869. VideoLayout.onParticipantConnectionStatusChanged(id, isActive);
  870. };
  871. /**
  872. * Update audio level visualization for specified user.
  873. * @param {string} id user id
  874. * @param {number} lvl audio level
  875. */
  876. UI.setAudioLevel = function (id, lvl) {
  877. VideoLayout.setAudioLevel(id, lvl);
  878. };
  879. /**
  880. * Update state of desktop sharing buttons.
  881. */
  882. UI.updateDesktopSharingButtons = function () {
  883. Toolbar.updateDesktopSharingButtonState();
  884. };
  885. /**
  886. * Hide connection quality statistics from UI.
  887. */
  888. UI.hideStats = function () {
  889. VideoLayout.hideStats();
  890. };
  891. /**
  892. * Update local connection quality statistics.
  893. * @param {number} percent
  894. * @param {object} stats
  895. */
  896. UI.updateLocalStats = function (percent, stats) {
  897. VideoLayout.updateLocalConnectionStats(percent, stats);
  898. };
  899. /**
  900. * Update connection quality statistics for remote user.
  901. * @param {string} id user id
  902. * @param {number} percent
  903. * @param {object} stats
  904. */
  905. UI.updateRemoteStats = function (id, percent, stats) {
  906. VideoLayout.updateConnectionStats(id, percent, stats);
  907. };
  908. /**
  909. * Mark video as interrupted or not.
  910. * @param {boolean} interrupted if video is interrupted
  911. */
  912. UI.markVideoInterrupted = function (interrupted) {
  913. if (interrupted) {
  914. VideoLayout.onVideoInterrupted();
  915. } else {
  916. VideoLayout.onVideoRestored();
  917. }
  918. };
  919. /**
  920. * Mark room as locked or not.
  921. * @param {boolean} locked if room is locked.
  922. */
  923. UI.markRoomLocked = function (locked) {
  924. if (locked) {
  925. Toolbar.lockLockButton();
  926. } else {
  927. Toolbar.unlockLockButton();
  928. }
  929. };
  930. /**
  931. * Add chat message.
  932. * @param {string} from user id
  933. * @param {string} displayName user nickname
  934. * @param {string} message message text
  935. * @param {number} stamp timestamp when message was created
  936. */
  937. UI.addMessage = function (from, displayName, message, stamp) {
  938. Chat.updateChatConversation(from, displayName, message, stamp);
  939. };
  940. UI.updateDTMFSupport = function (isDTMFSupported) {
  941. //TODO: enable when the UI is ready
  942. //Toolbar.showDialPadButton(dtmfSupport);
  943. };
  944. /**
  945. * Show user feedback dialog if its required or just show "thank you" dialog.
  946. * @returns {Promise} when dialog is closed.
  947. */
  948. UI.requestFeedback = function () {
  949. if (Feedback.isVisible())
  950. return Promise.reject(UIErrors.FEEDBACK_REQUEST_IN_PROGRESS);
  951. // Feedback has been submitted already.
  952. else if (Feedback.isEnabled() && Feedback.isSubmitted())
  953. return Promise.resolve();
  954. else
  955. return new Promise(function (resolve, reject) {
  956. if (Feedback.isEnabled()) {
  957. // If the user has already entered feedback, we'll show the
  958. // window and immidiately start the conference dispose timeout.
  959. if (Feedback.getFeedbackScore() > 0) {
  960. Feedback.openFeedbackWindow();
  961. resolve();
  962. } else { // Otherwise we'll wait for user's feedback.
  963. Feedback.openFeedbackWindow(resolve);
  964. }
  965. } else {
  966. // If the feedback functionality isn't enabled we show a thank
  967. // you dialog. Signaling it (true), so the caller
  968. // of requestFeedback can act on it
  969. resolve(true);
  970. }
  971. });
  972. };
  973. UI.updateRecordingState = function (state) {
  974. Recording.updateRecordingState(state);
  975. };
  976. UI.notifyTokenAuthFailed = function () {
  977. messageHandler.showError( "dialog.tokenAuthFailedTitle",
  978. "dialog.tokenAuthFailed");
  979. };
  980. UI.notifyInternalError = function () {
  981. messageHandler.showError( "dialog.internalErrorTitle",
  982. "dialog.internalError");
  983. };
  984. UI.notifyFocusDisconnected = function (focus, retrySec) {
  985. messageHandler.notify(
  986. null, "notify.focus",
  987. 'disconnected', "notify.focusFail",
  988. {component: focus, ms: retrySec}
  989. );
  990. };
  991. /**
  992. * Notify user that focus left the conference so page should be reloaded.
  993. */
  994. UI.notifyFocusLeft = function () {
  995. let title = APP.translation.generateTranslationHTML(
  996. 'dialog.serviceUnavailable'
  997. );
  998. let msg = APP.translation.generateTranslationHTML(
  999. 'dialog.jicofoUnavailable'
  1000. );
  1001. messageHandler.openDialog(
  1002. title,
  1003. msg,
  1004. true, // persistent
  1005. [{title: 'retry'}],
  1006. function () {
  1007. reload();
  1008. return false;
  1009. }
  1010. );
  1011. };
  1012. /**
  1013. * Updates auth info on the UI.
  1014. * @param {boolean} isAuthEnabled if authentication is enabled
  1015. * @param {string} [login] current login
  1016. */
  1017. UI.updateAuthInfo = function (isAuthEnabled, login) {
  1018. let loggedIn = !!login;
  1019. Toolbar.showAuthenticateButton(isAuthEnabled);
  1020. if (isAuthEnabled) {
  1021. Toolbar.setAuthenticatedIdentity(login);
  1022. Toolbar.showLoginButton(!loggedIn);
  1023. Toolbar.showLogoutButton(loggedIn);
  1024. }
  1025. };
  1026. UI.onStartMutedChanged = function (startAudioMuted, startVideoMuted) {
  1027. SettingsMenu.updateStartMutedBox(startAudioMuted, startVideoMuted);
  1028. };
  1029. /**
  1030. * Notifies interested listeners that the raise hand property has changed.
  1031. *
  1032. * @param {boolean} isRaisedHand indicates the current state of the
  1033. * "raised hand"
  1034. */
  1035. UI.onLocalRaiseHandChanged = function (isRaisedHand) {
  1036. eventEmitter.emit(UIEvents.LOCAL_RAISE_HAND_CHANGED, isRaisedHand);
  1037. };
  1038. /**
  1039. * Update list of available physical devices.
  1040. * @param {object[]} devices new list of available devices
  1041. */
  1042. UI.onAvailableDevicesChanged = function (devices) {
  1043. SettingsMenu.changeDevicesList(devices);
  1044. };
  1045. /**
  1046. * Sets microphone's <select> element to select microphone ID from settings.
  1047. */
  1048. UI.setSelectedMicFromSettings = function () {
  1049. SettingsMenu.setSelectedMicFromSettings();
  1050. };
  1051. /**
  1052. * Sets camera's <select> element to select camera ID from settings.
  1053. */
  1054. UI.setSelectedCameraFromSettings = function () {
  1055. SettingsMenu.setSelectedCameraFromSettings();
  1056. };
  1057. /**
  1058. * Sets audio outputs's <select> element to select audio output ID from
  1059. * settings.
  1060. */
  1061. UI.setSelectedAudioOutputFromSettings = function () {
  1062. SettingsMenu.setSelectedAudioOutputFromSettings();
  1063. };
  1064. /**
  1065. * Returns the id of the current video shown on large.
  1066. * Currently used by tests (torture).
  1067. */
  1068. UI.getLargeVideoID = function () {
  1069. return VideoLayout.getLargeVideoID();
  1070. };
  1071. /**
  1072. * Returns the current video shown on large.
  1073. * Currently used by tests (torture).
  1074. */
  1075. UI.getLargeVideo = function () {
  1076. return VideoLayout.getLargeVideo();
  1077. };
  1078. /**
  1079. * Shows dialog with a link to FF extension.
  1080. */
  1081. UI.showExtensionRequiredDialog = function (url) {
  1082. messageHandler.openMessageDialog(
  1083. "dialog.extensionRequired",
  1084. null,
  1085. null,
  1086. APP.translation.generateTranslationHTML(
  1087. "dialog.firefoxExtensionPrompt", {url: url}));
  1088. };
  1089. /**
  1090. * Shows "Please go to chrome webstore to install the desktop sharing extension"
  1091. * 2 button dialog with buttons - cancel and go to web store.
  1092. * @param url {string} the url of the extension.
  1093. */
  1094. UI.showExtensionExternalInstallationDialog = function (url) {
  1095. messageHandler.openTwoButtonDialog(
  1096. "dialog.externalInstallationTitle",
  1097. null,
  1098. "dialog.externalInstallationMsg",
  1099. null,
  1100. true,
  1101. "dialog.goToStore",
  1102. function(e,v,m,f){
  1103. if (v) {
  1104. e.preventDefault();
  1105. eventEmitter.emit(UIEvents.OPEN_EXTENSION_STORE, url);
  1106. }
  1107. },
  1108. function () {},
  1109. function () {
  1110. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  1111. }
  1112. );
  1113. };
  1114. /**
  1115. * Shows dialog with combined information about camera and microphone errors.
  1116. * @param {JitsiTrackError} micError
  1117. * @param {JitsiTrackError} cameraError
  1118. */
  1119. UI.showDeviceErrorDialog = function (micError, cameraError) {
  1120. let localStoragePropName = "doNotShowErrorAgain";
  1121. let isMicJitsiTrackErrorAndHasName = micError && micError.name &&
  1122. micError instanceof JitsiMeetJS.errorTypes.JitsiTrackError;
  1123. let isCameraJitsiTrackErrorAndHasName = cameraError && cameraError.name &&
  1124. cameraError instanceof JitsiMeetJS.errorTypes.JitsiTrackError;
  1125. let showDoNotShowWarning = false;
  1126. if (micError && cameraError && isMicJitsiTrackErrorAndHasName &&
  1127. isCameraJitsiTrackErrorAndHasName) {
  1128. showDoNotShowWarning = true;
  1129. } else if (micError && isMicJitsiTrackErrorAndHasName && !cameraError) {
  1130. showDoNotShowWarning = true;
  1131. } else if (cameraError && isCameraJitsiTrackErrorAndHasName && !micError) {
  1132. showDoNotShowWarning = true;
  1133. }
  1134. if (micError) {
  1135. localStoragePropName += "-mic-" + micError.name;
  1136. }
  1137. if (cameraError) {
  1138. localStoragePropName += "-camera-" + cameraError.name;
  1139. }
  1140. if (showDoNotShowWarning) {
  1141. if (window.localStorage[localStoragePropName] === "true") {
  1142. return;
  1143. }
  1144. }
  1145. let title = getTitleKey();
  1146. let titleMsg = `<span data-i18n="${title}"></span>`;
  1147. let cameraJitsiTrackErrorMsg = cameraError
  1148. ? JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[cameraError.name]
  1149. : undefined;
  1150. let micJitsiTrackErrorMsg = micError
  1151. ? JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[micError.name]
  1152. : undefined;
  1153. let cameraErrorMsg = cameraError
  1154. ? cameraJitsiTrackErrorMsg ||
  1155. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.GENERAL]
  1156. : "";
  1157. let micErrorMsg = micError
  1158. ? micJitsiTrackErrorMsg ||
  1159. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.GENERAL]
  1160. : "";
  1161. let additionalCameraErrorMsg = !cameraJitsiTrackErrorMsg && cameraError &&
  1162. cameraError.message
  1163. ? `<div>${cameraError.message}</div>`
  1164. : ``;
  1165. let additionalMicErrorMsg = !micJitsiTrackErrorMsg && micError &&
  1166. micError.message
  1167. ? `<div>${micError.message}</div>`
  1168. : ``;
  1169. let doNotShowWarningAgainSection = showDoNotShowWarning
  1170. ? `<label>
  1171. <input type='checkbox' id='doNotShowWarningAgain'>
  1172. <span data-i18n='dialog.doNotShowWarningAgain'></span>
  1173. </label>`
  1174. : ``;
  1175. let message = '';
  1176. if (micError) {
  1177. message = `
  1178. ${message}
  1179. <h3 data-i18n='dialog.micErrorPresent'></h3>
  1180. <h4 data-i18n='${micErrorMsg}'></h4>
  1181. ${additionalMicErrorMsg}`;
  1182. }
  1183. if (cameraError) {
  1184. message = `
  1185. ${message}
  1186. <h3 data-i18n='dialog.cameraErrorPresent'></h3>
  1187. <h4 data-i18n='${cameraErrorMsg}'></h4>
  1188. ${additionalCameraErrorMsg}`;
  1189. }
  1190. message = `${message}${doNotShowWarningAgainSection}`;
  1191. // To make sure we don't have multiple error dialogs open at the same time,
  1192. // we will just close the previous one if we are going to show a new one.
  1193. deviceErrorDialog && deviceErrorDialog.close();
  1194. deviceErrorDialog = messageHandler.openDialog(
  1195. titleMsg,
  1196. message,
  1197. false,
  1198. {Ok: true},
  1199. function () {
  1200. let form = $.prompt.getPrompt();
  1201. if (form) {
  1202. let input = form.find("#doNotShowWarningAgain");
  1203. if (input.length) {
  1204. window.localStorage[localStoragePropName] =
  1205. input.prop("checked");
  1206. }
  1207. }
  1208. },
  1209. null,
  1210. function () {
  1211. // Reset dialog reference to null to avoid memory leaks when
  1212. // user closed the dialog manually.
  1213. deviceErrorDialog = null;
  1214. }
  1215. );
  1216. APP.translation.translateElement($(".jqibox"));
  1217. function getTitleKey() {
  1218. let title = "dialog.error";
  1219. if (micError && micError.name === TrackErrors.PERMISSION_DENIED) {
  1220. if (cameraError && cameraError.name === TrackErrors.PERMISSION_DENIED) {
  1221. title = "dialog.permissionDenied";
  1222. } else if (!cameraError) {
  1223. title = "dialog.permissionDenied";
  1224. }
  1225. } else if (cameraError &&
  1226. cameraError.name === TrackErrors.PERMISSION_DENIED) {
  1227. title = "dialog.permissionDenied";
  1228. }
  1229. return title;
  1230. }
  1231. };
  1232. /**
  1233. * Shows error dialog that informs the user that no data is received from the
  1234. * device.
  1235. */
  1236. UI.showTrackNotWorkingDialog = function (stream) {
  1237. messageHandler.openMessageDialog(
  1238. "dialog.error",
  1239. stream.isAudioTrack()? "dialog.micNotSendingData" :
  1240. "dialog.cameraNotSendingData",
  1241. null,
  1242. null);
  1243. };
  1244. UI.updateDevicesAvailability = function (id, devices) {
  1245. VideoLayout.setDeviceAvailabilityIcons(id, devices);
  1246. };
  1247. /**
  1248. * Show shared video.
  1249. * @param {string} id the id of the sender of the command
  1250. * @param {string} url video url
  1251. * @param {string} attributes
  1252. */
  1253. UI.onSharedVideoStart = function (id, url, attributes) {
  1254. if (sharedVideoManager)
  1255. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  1256. };
  1257. /**
  1258. * Update shared video.
  1259. * @param {string} id the id of the sender of the command
  1260. * @param {string} url video url
  1261. * @param {string} attributes
  1262. */
  1263. UI.onSharedVideoUpdate = function (id, url, attributes) {
  1264. if (sharedVideoManager)
  1265. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  1266. };
  1267. /**
  1268. * Stop showing shared video.
  1269. * @param {string} id the id of the sender of the command
  1270. * @param {string} attributes
  1271. */
  1272. UI.onSharedVideoStop = function (id, attributes) {
  1273. if (sharedVideoManager)
  1274. sharedVideoManager.onSharedVideoStop(id, attributes);
  1275. };
  1276. /**
  1277. * Disables camera toolbar button.
  1278. */
  1279. UI.disableCameraButton = function () {
  1280. Toolbar.markVideoIconAsDisabled(true);
  1281. };
  1282. /**
  1283. * Enables camera toolbar button.
  1284. */
  1285. UI.enableCameraButton = function () {
  1286. Toolbar.markVideoIconAsDisabled(false);
  1287. };
  1288. /**
  1289. * Disables microphone toolbar button.
  1290. */
  1291. UI.disableMicrophoneButton = function () {
  1292. Toolbar.markAudioIconAsDisabled(true);
  1293. };
  1294. /**
  1295. * Enables microphone toolbar button.
  1296. */
  1297. UI.enableMicrophoneButton = function () {
  1298. Toolbar.markAudioIconAsDisabled(false);
  1299. };
  1300. UI.showRingOverLay = function () {
  1301. RingOverlay.show(APP.tokenData.callee);
  1302. FilmStrip.toggleFilmStrip(false);
  1303. };
  1304. UI.hideRingOverLay = function () {
  1305. if (!RingOverlay.hide())
  1306. return;
  1307. FilmStrip.toggleFilmStrip(true);
  1308. };
  1309. /**
  1310. * Indicates if the ring overlay is currently visible.
  1311. *
  1312. * @returns {*|boolean} {true} if the ring overlay is visible, {false} otherwise
  1313. */
  1314. UI.isRingOverlayVisible = function () {
  1315. return RingOverlay.isVisible();
  1316. };
  1317. /**
  1318. * Shows browser-specific overlay with guidance how to proceed with gUM prompt.
  1319. * @param {string} browser - name of browser for which to show the guidance
  1320. * overlay.
  1321. */
  1322. UI.showUserMediaPermissionsGuidanceOverlay = function (browser) {
  1323. GumPermissionsOverlay.show(browser);
  1324. };
  1325. /**
  1326. * Hides browser-specific overlay with guidance how to proceed with gUM prompt.
  1327. */
  1328. UI.hideUserMediaPermissionsGuidanceOverlay = function () {
  1329. GumPermissionsOverlay.hide();
  1330. };
  1331. /**
  1332. * Shows or hides the keyboard shortcuts panel, depending on the current state.'
  1333. */
  1334. UI.toggleKeyboardShortcutsPanel = function() {
  1335. $('#keyboard-shortcuts').toggle();
  1336. };
  1337. /**
  1338. * Shows or hides the keyboard shortcuts panel.'
  1339. */
  1340. UI.showKeyboardShortcutsPanel = function(show) {
  1341. if (show) {
  1342. $('#keyboard-shortcuts').show();
  1343. } else {
  1344. $('#keyboard-shortcuts').hide();
  1345. }
  1346. };
  1347. module.exports = UI;