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

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