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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. /* global APP, $, 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 BottomToolbar from "./toolbars/BottomToolbar";
  8. import ContactList from "./side_pannels/contactlist/ContactList";
  9. import Avatar from "./avatar/Avatar";
  10. import PanelToggler from "./side_pannels/SidePanelToggler";
  11. import UIUtil from "./util/UIUtil";
  12. import UIEvents from "../../service/UI/UIEvents";
  13. import CQEvents from '../../service/connectionquality/CQEvents';
  14. import PreziManager from './prezi/Prezi';
  15. import EtherpadManager from './etherpad/Etherpad';
  16. import VideoLayout from "./videolayout/VideoLayout";
  17. import SettingsMenu from "./side_pannels/settings/SettingsMenu";
  18. import Settings from "./../settings/Settings";
  19. var EventEmitter = require("events");
  20. UI.messageHandler = require("./util/MessageHandler");
  21. var messageHandler = UI.messageHandler;
  22. var JitsiPopover = require("./util/JitsiPopover");
  23. var Feedback = require("./Feedback");
  24. var eventEmitter = new EventEmitter();
  25. UI.eventEmitter = eventEmitter;
  26. let preziManager;
  27. let etherpadManager;
  28. function promptDisplayName() {
  29. let nickRequiredMsg = APP.translation.translateString("dialog.displayNameRequired");
  30. let defaultNickMsg = APP.translation.translateString(
  31. "defaultNickname", {name: "Jane Pink"}
  32. );
  33. let message = `
  34. <h2 data-i18n="dialog.displayNameRequired">${nickRequiredMsg}</h2>
  35. <input name="displayName" type="text"
  36. data-i18n="[placeholder]defaultNickname"
  37. placeholder="${defaultNickMsg}" autofocus>`;
  38. let buttonTxt = APP.translation.generateTranslationHTML("dialog.Ok");
  39. let buttons = [{title: buttonTxt, value: "ok"}];
  40. messageHandler.openDialog(
  41. null, message,
  42. true,
  43. buttons,
  44. function (e, v, m, f) {
  45. if (v == "ok") {
  46. let displayName = f.displayName;
  47. if (displayName) {
  48. UI.inputDisplayNameHandler(displayName);
  49. return true;
  50. }
  51. }
  52. e.preventDefault();
  53. },
  54. function () {
  55. let form = $.prompt.getPrompt();
  56. let input = form.find("input[name='displayName']");
  57. input.focus();
  58. let button = form.find("button");
  59. button.attr("disabled", "disabled");
  60. input.keyup(function () {
  61. if (input.val()) {
  62. button.removeAttr("disabled");
  63. } else {
  64. button.attr("disabled", "disabled");
  65. }
  66. });
  67. }
  68. );
  69. }
  70. function setupChat() {
  71. Chat.init(eventEmitter);
  72. $("#toggle_smileys").click(function() {
  73. Chat.toggleSmileys();
  74. });
  75. }
  76. function setupToolbars() {
  77. Toolbar.init(eventEmitter);
  78. Toolbar.setupButtonsFromConfig();
  79. BottomToolbar.setupListeners(eventEmitter);
  80. }
  81. /**
  82. * Toggles the application in and out of full screen mode
  83. * (a.k.a. presentation mode in Chrome).
  84. */
  85. function toggleFullScreen () {
  86. let fsElement = document.documentElement;
  87. if (!document.mozFullScreen && !document.webkitIsFullScreen) {
  88. //Enter Full Screen
  89. if (fsElement.mozRequestFullScreen) {
  90. fsElement.mozRequestFullScreen();
  91. } else {
  92. fsElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
  93. }
  94. } else {
  95. //Exit Full Screen
  96. if (document.mozCancelFullScreen) {
  97. document.mozCancelFullScreen();
  98. } else {
  99. document.webkitCancelFullScreen();
  100. }
  101. }
  102. }
  103. UI.notifyGracefulShudown = function () {
  104. messageHandler.openMessageDialog(
  105. 'dialog.serviceUnavailable',
  106. 'dialog.gracefulShutdown'
  107. );
  108. };
  109. UI.notifyReservationError = function (code, msg) {
  110. var title = APP.translation.generateTranslationHTML(
  111. "dialog.reservationError");
  112. var message = APP.translation.generateTranslationHTML(
  113. "dialog.reservationErrorMsg", {code: code, msg: msg});
  114. messageHandler.openDialog(
  115. title,
  116. message,
  117. true, {},
  118. function (event, value, message, formVals) {
  119. return false;
  120. }
  121. );
  122. };
  123. UI.notifyKicked = function () {
  124. messageHandler.openMessageDialog("dialog.sessTerminated", "dialog.kickMessage");
  125. };
  126. UI.notifyBridgeDown = function () {
  127. messageHandler.showError("dialog.error", "dialog.bridgeUnavailable");
  128. };
  129. UI.changeDisplayName = function (id, displayName) {
  130. ContactList.onDisplayNameChange(id, displayName);
  131. SettingsMenu.onDisplayNameChange(id, displayName);
  132. VideoLayout.onDisplayNameChanged(id, displayName);
  133. if (APP.conference.isLocalId(id)) {
  134. Chat.setChatConversationMode(!!displayName);
  135. }
  136. };
  137. UI.initConference = function () {
  138. var id = APP.conference.localId;
  139. Toolbar.updateRoomUrl(window.location.href);
  140. var meHTML = APP.translation.generateTranslationHTML("me");
  141. var settings = Settings.getSettings();
  142. $("#localNick").html(settings.email || settings.uid + " (" + meHTML + ")");
  143. // Add myself to the contact list.
  144. ContactList.addContact(id);
  145. // Once we've joined the muc show the toolbar
  146. ToolbarToggler.showToolbar();
  147. var displayName = config.displayJids ? id : settings.displayName;
  148. if (displayName) {
  149. UI.changeDisplayName('localVideoContainer', displayName);
  150. }
  151. // Make sure we configure our avatar id, before creating avatar for us
  152. UI.setUserAvatar(id, settings.email || settings.uid);
  153. Toolbar.checkAutoEnableDesktopSharing();
  154. };
  155. UI.mucJoined = function () {
  156. VideoLayout.mucJoined();
  157. };
  158. function registerListeners() {
  159. UI.addListener(UIEvents.EMAIL_CHANGED, function (email) {
  160. UI.setUserAvatar(APP.conference.localId, email);
  161. });
  162. UI.addListener(UIEvents.PREZI_CLICKED, function () {
  163. preziManager.handlePreziButtonClicked();
  164. });
  165. UI.addListener(UIEvents.ETHERPAD_CLICKED, function () {
  166. if (etherpadManager) {
  167. etherpadManager.toggleEtherpad();
  168. }
  169. });
  170. UI.addListener(UIEvents.FULLSCREEN_TOGGLE, toggleFullScreen);
  171. UI.addListener(UIEvents.TOGGLE_CHAT, UI.toggleChat);
  172. UI.addListener(UIEvents.TOGGLE_SETTINGS, function () {
  173. PanelToggler.toggleSettingsMenu();
  174. });
  175. UI.addListener(UIEvents.TOGGLE_CONTACT_LIST, UI.toggleContactList);
  176. UI.addListener(UIEvents.TOGGLE_FILM_STRIP, UI.toggleFilmStrip);
  177. }
  178. function bindEvents() {
  179. function onResize() {
  180. PanelToggler.resizeChat();
  181. VideoLayout.resizeLargeVideoContainer(PanelToggler.isVisible());
  182. }
  183. // Resize and reposition videos in full screen mode.
  184. $(document).on(
  185. 'webkitfullscreenchange mozfullscreenchange fullscreenchange', onResize
  186. );
  187. $(window).resize(onResize);
  188. }
  189. /**
  190. * Starts the UI module and initializes all related components.
  191. *
  192. * @returns {boolean} true if the UI is ready and the conference should be
  193. * esablished, false - otherwise (for example in the case of welcome page)
  194. */
  195. UI.start = function () {
  196. document.title = interfaceConfig.APP_NAME;
  197. var setupWelcomePage = null;
  198. if(config.enableWelcomePage && window.location.pathname == "/" &&
  199. (!window.localStorage.welcomePageDisabled ||
  200. window.localStorage.welcomePageDisabled == "false")) {
  201. $("#videoconference_page").hide();
  202. if (!setupWelcomePage)
  203. setupWelcomePage = require("./welcome_page/WelcomePage");
  204. setupWelcomePage();
  205. // Return false to indicate that the UI hasn't been fully started and
  206. // conference ready. We're still waiting for input from the user.
  207. return false;
  208. }
  209. $("#welcome_page").hide();
  210. // Set the defaults for prompt dialogs.
  211. $.prompt.setDefaults({persistent: false});
  212. registerListeners();
  213. BottomToolbar.init();
  214. VideoLayout.init(eventEmitter);
  215. if (!interfaceConfig.filmStripOnly) {
  216. VideoLayout.initLargeVideo(PanelToggler.isVisible());
  217. }
  218. VideoLayout.resizeLargeVideoContainer(PanelToggler.isVisible());
  219. ContactList.init(eventEmitter);
  220. bindEvents();
  221. preziManager = new PreziManager(eventEmitter);
  222. if (!interfaceConfig.filmStripOnly) {
  223. $("#videospace").mousemove(function () {
  224. return ToolbarToggler.showToolbar();
  225. });
  226. setupToolbars();
  227. setupChat();
  228. // Display notice message at the top of the toolbar
  229. if (config.noticeMessage) {
  230. $('#noticeText').text(config.noticeMessage);
  231. $('#notice').css({display: 'block'});
  232. }
  233. $("#downloadlog").click(function (event) {
  234. // dump(event.target);
  235. // FIXME integrate logs
  236. });
  237. Feedback.init();
  238. } else {
  239. $("#header").css("display", "none");
  240. $("#bottomToolbar").css("display", "none");
  241. $("#downloadlog").css("display", "none");
  242. BottomToolbar.setupFilmStripOnly();
  243. messageHandler.disableNotifications();
  244. $('body').popover("disable");
  245. JitsiPopover.enabled = false;
  246. }
  247. document.title = interfaceConfig.APP_NAME;
  248. if(config.requireDisplayName) {
  249. if (APP.settings.getDisplayName()) {
  250. promptDisplayName();
  251. }
  252. }
  253. if (!interfaceConfig.filmStripOnly) {
  254. toastr.options = {
  255. "closeButton": true,
  256. "debug": false,
  257. "positionClass": "notification-bottom-right",
  258. "onclick": null,
  259. "showDuration": "300",
  260. "hideDuration": "1000",
  261. "timeOut": "2000",
  262. "extendedTimeOut": "1000",
  263. "showEasing": "swing",
  264. "hideEasing": "linear",
  265. "showMethod": "fadeIn",
  266. "hideMethod": "fadeOut",
  267. "reposition": function () {
  268. if (PanelToggler.isVisible()) {
  269. $("#toast-container").addClass("notification-bottom-right-center");
  270. } else {
  271. $("#toast-container").removeClass("notification-bottom-right-center");
  272. }
  273. },
  274. "newestOnTop": false
  275. };
  276. SettingsMenu.init(eventEmitter);
  277. }
  278. // Return true to indicate that the UI has been fully started and
  279. // conference ready.
  280. return true;
  281. };
  282. UI.addLocalStream = function (track) {
  283. switch (track.getType()) {
  284. case 'audio':
  285. VideoLayout.changeLocalAudio(track);
  286. break;
  287. case 'video':
  288. VideoLayout.changeLocalVideo(track);
  289. break;
  290. default:
  291. console.error("Unknown stream type: " + track.getType());
  292. break;
  293. }
  294. };
  295. UI.addRemoteStream = function (stream) {
  296. VideoLayout.onRemoteStreamAdded(stream);
  297. };
  298. function chatAddError(errorMessage, originalText) {
  299. return Chat.chatAddError(errorMessage, originalText);
  300. }
  301. UI.setSubject = function (subject) {
  302. Chat.setSubject(subject);
  303. };
  304. UI.initEtherpad = function (name) {
  305. if (etherpadManager || !config.etherpad_base || !name) {
  306. return;
  307. }
  308. console.log('Etherpad is enabled');
  309. etherpadManager = new EtherpadManager(config.etherpad_base, name);
  310. Toolbar.showEtherpadButton();
  311. };
  312. UI.addUser = function (id, displayName) {
  313. ContactList.addContact(id);
  314. messageHandler.notify(
  315. displayName,'notify.somebody', 'connected', 'notify.connected'
  316. );
  317. if (!config.startAudioMuted ||
  318. config.startAudioMuted > APP.conference.membersCount)
  319. UIUtil.playSoundNotification('userJoined');
  320. // Configure avatar
  321. UI.setUserAvatar(id, displayName);
  322. // Add Peer's container
  323. VideoLayout.addParticipantContainer(id);
  324. };
  325. UI.removeUser = function (id, displayName) {
  326. ContactList.removeContact(id);
  327. messageHandler.notify(
  328. displayName,'notify.somebody', 'disconnected', 'notify.disconnected'
  329. );
  330. if (!config.startAudioMuted
  331. || config.startAudioMuted > APP.conference.membersCount) {
  332. UIUtil.playSoundNotification('userLeft');
  333. }
  334. VideoLayout.removeParticipantContainer(id);
  335. };
  336. //FIXME: NOT USED. Should start using the lib
  337. // function onMucPresenceStatus(jid, info) {
  338. // VideoLayout.setPresenceStatus(Strophe.getResourceFromJid(jid), info.status);
  339. // }
  340. UI.onPeerVideoTypeChanged = (id, newVideoType) => {
  341. VideoLayout.onVideoTypeChanged(id, newVideoType);
  342. };
  343. UI.updateLocalRole = function (isModerator) {
  344. VideoLayout.showModeratorIndicator();
  345. Toolbar.showSipCallButton(isModerator);
  346. Toolbar.showRecordingButton(isModerator);
  347. SettingsMenu.onRoleChanged();
  348. if (isModerator) {
  349. messageHandler.notify(null, "notify.me", 'connected', "notify.moderator");
  350. Toolbar.checkAutoRecord();
  351. }
  352. };
  353. /**
  354. * Check the role for the user and reflect it in the UI, moderator ui indication
  355. * and notifies user who is the moderator
  356. * @param user to check for moderator
  357. */
  358. UI.updateUserRole = function (user) {
  359. VideoLayout.showModeratorIndicator();
  360. if (!user.isModerator()) {
  361. return;
  362. }
  363. var displayName = user.getDisplayName();
  364. if (displayName) {
  365. messageHandler.notify(
  366. displayName, 'notify.somebody',
  367. 'connected', 'notify.grantedTo', {
  368. to: displayName
  369. }
  370. );
  371. } else {
  372. messageHandler.notify(
  373. '', 'notify.somebody',
  374. 'connected', 'notify.grantedToUnknown', {}
  375. );
  376. }
  377. };
  378. UI.toggleSmileys = function () {
  379. Chat.toggleSmileys();
  380. };
  381. UI.getSettings = function () {
  382. return Settings.getSettings();
  383. };
  384. UI.toggleFilmStrip = function () {
  385. BottomToolbar.toggleFilmStrip();
  386. };
  387. UI.toggleChat = function () {
  388. PanelToggler.toggleChat();
  389. };
  390. UI.toggleContactList = function () {
  391. PanelToggler.toggleContactList();
  392. };
  393. UI.inputDisplayNameHandler = function (value) {
  394. VideoLayout.inputDisplayNameHandler(value);
  395. };
  396. /**
  397. * Return the type of the remote video.
  398. * @param jid the jid for the remote video
  399. * @returns the video type video or screen.
  400. */
  401. UI.getRemoteVideoType = function (jid) {
  402. return VideoLayout.getRemoteVideoType(jid);
  403. };
  404. UI.connectionIndicatorShowMore = function(jid) {
  405. return VideoLayout.showMore(jid);
  406. };
  407. UI.showLoginPopup = function(callback) {
  408. console.log('password is required');
  409. var message = '<h2 data-i18n="dialog.passwordRequired">';
  410. message += APP.translation.translateString(
  411. "dialog.passwordRequired");
  412. message += '</h2>' +
  413. '<input name="username" type="text" ' +
  414. 'placeholder="user@domain.net" autofocus>' +
  415. '<input name="password" ' +
  416. 'type="password" data-i18n="[placeholder]dialog.userPassword"' +
  417. ' placeholder="user password">';
  418. UI.messageHandler.openTwoButtonDialog(null, null, null, message,
  419. true,
  420. "dialog.Ok",
  421. function (e, v, m, f) {
  422. if (v) {
  423. if (f.username && f.password) {
  424. callback(f.username, f.password);
  425. }
  426. }
  427. },
  428. null, null, ':input:first'
  429. );
  430. };
  431. UI.askForNickname = function () {
  432. return window.prompt('Your nickname (optional)');
  433. };
  434. /**
  435. * Sets muted audio state for participant
  436. */
  437. UI.setAudioMuted = function (id, muted) {
  438. VideoLayout.onAudioMute(id, muted);
  439. if(APP.conference.isLocalId(id))
  440. UIUtil.buttonClick("#toolbar_button_mute",
  441. "icon-microphone icon-mic-disabled");
  442. };
  443. /**
  444. * Sets muted video state for participant
  445. */
  446. UI.setVideoMuted = function (id, muted) {
  447. VideoLayout.onVideoMute(id, muted);
  448. if(APP.conference.isLocalId(id))
  449. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  450. };
  451. UI.addListener = function (type, listener) {
  452. eventEmitter.on(type, listener);
  453. };
  454. UI.clickOnVideo = function (videoNumber) {
  455. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  456. if (remoteVideos.length > videoNumber) {
  457. remoteVideos[videoNumber].click();
  458. }
  459. };
  460. //Used by torture
  461. UI.showToolbar = function () {
  462. return ToolbarToggler.showToolbar();
  463. };
  464. //Used by torture
  465. UI.dockToolbar = function (isDock) {
  466. ToolbarToggler.dockToolbar(isDock);
  467. };
  468. UI.setUserAvatar = function (id, email) {
  469. // update avatar
  470. Avatar.setUserAvatar(id, email);
  471. var thumbUrl = Avatar.getThumbUrl(id);
  472. var contactListUrl = Avatar.getContactListUrl(id);
  473. VideoLayout.changeUserAvatar(id, thumbUrl);
  474. ContactList.changeUserAvatar(id, contactListUrl);
  475. if (APP.conference.isLocalId(id)) {
  476. SettingsMenu.changeAvatar(thumbUrl);
  477. }
  478. };
  479. UI.notifyConnectionFailed = function (stropheErrorMsg) {
  480. var title = APP.translation.generateTranslationHTML(
  481. "dialog.error");
  482. var message;
  483. if (stropheErrorMsg) {
  484. message = APP.translation.generateTranslationHTML(
  485. "dialog.connectErrorWithMsg", {msg: stropheErrorMsg});
  486. } else {
  487. message = APP.translation.generateTranslationHTML(
  488. "dialog.connectError");
  489. }
  490. messageHandler.openDialog(
  491. title, message, true, {}, function (e, v, m, f) { return false; }
  492. );
  493. };
  494. UI.notifyFirefoxExtensionRequired = function (url) {
  495. messageHandler.openMessageDialog(
  496. "dialog.extensionRequired",
  497. null,
  498. null,
  499. APP.translation.generateTranslationHTML(
  500. "dialog.firefoxExtensionPrompt", {url: url}
  501. )
  502. );
  503. };
  504. UI.notifyInitiallyMuted = function () {
  505. messageHandler.notify(
  506. null, "notify.mutedTitle", "connected", "notify.muted", null, {timeOut: 120000}
  507. );
  508. };
  509. UI.markDominantSpeaker = function (id) {
  510. VideoLayout.onDominantSpeakerChanged(id);
  511. };
  512. UI.handleLastNEndpoints = function (ids) {
  513. VideoLayout.onLastNEndpointsChanged(ids, []);
  514. };
  515. UI.setAudioLevel = function (id, lvl) {
  516. VideoLayout.setAudioLevel(id, lvl);
  517. };
  518. UI.updateDesktopSharingButtons = function (isSharingScreen) {
  519. Toolbar.changeDesktopSharingButtonState(isSharingScreen);
  520. };
  521. UI.hideStats = function () {
  522. VideoLayout.hideStats();
  523. };
  524. UI.updateLocalStats = function (percent, stats) {
  525. VideoLayout.updateLocalConnectionStats(percent, stats);
  526. };
  527. UI.updateRemoteStats = function (id, percent, stats) {
  528. VideoLayout.updateConnectionStats(id, percent, stats);
  529. };
  530. UI.markVideoInterrupted = function (interrupted) {
  531. if (interrupted) {
  532. VideoLayout.onVideoInterrupted();
  533. } else {
  534. VideoLayout.onVideoRestored();
  535. }
  536. };
  537. UI.markRoomLocked = function (locked) {
  538. if (locked) {
  539. Toolbar.lockLockButton();
  540. } else {
  541. Toolbar.unlockLockButton();
  542. }
  543. };
  544. UI.addMessage = function (from, displayName, message, stamp) {
  545. Chat.updateChatConversation(from, displayName, message, stamp);
  546. };
  547. UI.updateDTMFSupport = function (isDTMFSupported) {
  548. //TODO: enable when the UI is ready
  549. //Toolbar.showDialPadButton(dtmfSupport);
  550. };
  551. /**
  552. * Invite participants to conference.
  553. */
  554. UI.inviteParticipants = function (roomUrl, conferenceName, key, nick) {
  555. let keyText = "";
  556. if (key) {
  557. keyText = APP.translation.translateString(
  558. "email.sharedKey", {sharedKey: key}
  559. );
  560. }
  561. let and = APP.translation.translateString("email.and");
  562. let supportedBrowsers = `Chromium, Google Chrome ${and} Opera`;
  563. let subject = APP.translation.translateString(
  564. "email.subject", {appName:interfaceConfig.APP_NAME, conferenceName}
  565. );
  566. let body = APP.translation.translateString(
  567. "email.body", {
  568. appName:interfaceConfig.APP_NAME,
  569. sharedKeyText: keyText,
  570. roomUrl,
  571. supportedBrowsers
  572. }
  573. );
  574. body = body.replace(/\n/g, "%0D%0A");
  575. if (nick) {
  576. body += "%0D%0A%0D%0A" + nick;
  577. }
  578. if (interfaceConfig.INVITATION_POWERED_BY) {
  579. body += "%0D%0A%0D%0A--%0D%0Apowered by jitsi.org";
  580. }
  581. window.open(`mailto:?subject=${subject}&body=${body}`, '_blank');
  582. };
  583. UI.requestFeedback = function () {
  584. return new Promise(function (resolve, reject) {
  585. if (Feedback.isEnabled()) {
  586. // If the user has already entered feedback, we'll show the window and
  587. // immidiately start the conference dispose timeout.
  588. if (Feedback.feedbackScore > 0) {
  589. Feedback.openFeedbackWindow();
  590. resolve();
  591. } else { // Otherwise we'll wait for user's feedback.
  592. Feedback.openFeedbackWindow(resolve);
  593. }
  594. } else {
  595. // If the feedback functionality isn't enabled we show a thank you
  596. // dialog.
  597. messageHandler.openMessageDialog(
  598. null, null, null,
  599. APP.translation.translateString(
  600. "dialog.thankYou", {appName:interfaceConfig.APP_NAME}
  601. )
  602. );
  603. resolve();
  604. }
  605. });
  606. };
  607. UI.requestRecordingToken = function () {
  608. let msg = APP.translation.generateTranslationHTML("dialog.recordingToken");
  609. let token = APP.translation.translateString("dialog.token");
  610. return new Promise(function (resolve, reject) {
  611. messageHandler.openTwoButtonDialog(
  612. null, null, null,
  613. `<h2>${msg}</h2>
  614. <input name="recordingToken" type="text"
  615. data-i18n="[placeholder]dialog.token"
  616. placeholder="${token}" autofocus>`,
  617. false, "dialog.Save",
  618. function (e, v, m, f) {
  619. if (v && f.recordingToken) {
  620. resolve(UIUtil.escapeHtml(f.recordingToken));
  621. } else {
  622. reject();
  623. }
  624. },
  625. null,
  626. function () { },
  627. ':input:first'
  628. );
  629. });
  630. };
  631. UI.updateRecordingState = function (state) {
  632. Toolbar.updateRecordingState(state);
  633. };
  634. UI.notifyTokenAuthFailed = function () {
  635. messageHandler.showError("dialog.error", "dialog.tokenAuthFailed");
  636. };
  637. UI.updateAuthInfo = function (isAuthEnabled, login) {
  638. let loggedIn = !!login;
  639. Toolbar.showAuthenticateButton(isAuthEnabled);
  640. if (isAuthEnabled) {
  641. Toolbar.setAuthenticatedIdentity(login);
  642. Toolbar.showLoginButton(!loggedIn);
  643. Toolbar.showLogoutButton(loggedIn);
  644. }
  645. };
  646. UI.showPrezi = function (userId, url, slide) {
  647. preziManager.showPrezi(userId, url, slide);
  648. };
  649. UI.stopPrezi = function (userId) {
  650. if (preziManager.isSharing(userId)) {
  651. preziManager.removePrezi(userId);
  652. }
  653. };
  654. UI.onStartMutedChanged = function () {
  655. SettingsMenu.onStartMutedChanged();
  656. };
  657. module.exports = UI;