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

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