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

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