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.

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