Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

UI.js 43KB

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