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

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