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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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. VideoLayout.mucJoined();
  152. // Make sure we configure our avatar id, before creating avatar for us
  153. UI.setUserAvatar(id, settings.email || settings.uid);
  154. Toolbar.checkAutoEnableDesktopSharing();
  155. };
  156. function registerListeners() {
  157. UI.addListener(UIEvents.EMAIL_CHANGED, function (email) {
  158. UI.setUserAvatar(APP.conference.localId, email);
  159. });
  160. UI.addListener(UIEvents.PREZI_CLICKED, function () {
  161. preziManager.handlePreziButtonClicked();
  162. });
  163. UI.addListener(UIEvents.ETHERPAD_CLICKED, function () {
  164. if (etherpadManager) {
  165. etherpadManager.toggleEtherpad();
  166. }
  167. });
  168. UI.addListener(UIEvents.FULLSCREEN_TOGGLE, toggleFullScreen);
  169. UI.addListener(UIEvents.TOGGLE_CHAT, UI.toggleChat);
  170. UI.addListener(UIEvents.TOGGLE_SETTINGS, function () {
  171. PanelToggler.toggleSettingsMenu();
  172. });
  173. UI.addListener(UIEvents.TOGGLE_CONTACT_LIST, UI.toggleContactList);
  174. UI.addListener(UIEvents.TOGGLE_FILM_STRIP, UI.toggleFilmStrip);
  175. }
  176. function bindEvents() {
  177. function onResize() {
  178. PanelToggler.resizeChat();
  179. VideoLayout.resizeLargeVideoContainer(PanelToggler.isVisible());
  180. }
  181. // Resize and reposition videos in full screen mode.
  182. $(document).on(
  183. 'webkitfullscreenchange mozfullscreenchange fullscreenchange', onResize
  184. );
  185. $(window).resize(onResize);
  186. }
  187. /**
  188. * Starts the UI module and initializes all related components.
  189. *
  190. * @returns {boolean} true if the UI is ready and the conference should be
  191. * esablished, false - otherwise (for example in the case of welcome page)
  192. */
  193. UI.start = function () {
  194. document.title = interfaceConfig.APP_NAME;
  195. var setupWelcomePage = null;
  196. if(config.enableWelcomePage && window.location.pathname == "/" &&
  197. (!window.localStorage.welcomePageDisabled ||
  198. window.localStorage.welcomePageDisabled == "false")) {
  199. $("#videoconference_page").hide();
  200. if (!setupWelcomePage)
  201. setupWelcomePage = require("./welcome_page/WelcomePage");
  202. setupWelcomePage();
  203. // Return false to indicate that the UI hasn't been fully started and
  204. // conference ready. We're still waiting for input from the user.
  205. return false;
  206. }
  207. $("#welcome_page").hide();
  208. // Set the defaults for prompt dialogs.
  209. $.prompt.setDefaults({persistent: false});
  210. registerListeners();
  211. BottomToolbar.init();
  212. VideoLayout.init(eventEmitter);
  213. if (!interfaceConfig.filmStripOnly) {
  214. VideoLayout.initLargeVideo(PanelToggler.isVisible());
  215. }
  216. VideoLayout.resizeLargeVideoContainer(PanelToggler.isVisible());
  217. ContactList.init(eventEmitter);
  218. bindEvents();
  219. preziManager = new PreziManager(eventEmitter);
  220. if (!interfaceConfig.filmStripOnly) {
  221. $("#videospace").mousemove(function () {
  222. return ToolbarToggler.showToolbar();
  223. });
  224. setupToolbars();
  225. setupChat();
  226. // Display notice message at the top of the toolbar
  227. if (config.noticeMessage) {
  228. $('#noticeText').text(config.noticeMessage);
  229. $('#notice').css({display: 'block'});
  230. }
  231. $("#downloadlog").click(function (event) {
  232. // dump(event.target);
  233. // FIXME integrate logs
  234. });
  235. Feedback.init();
  236. } else {
  237. $("#header").css("display", "none");
  238. $("#bottomToolbar").css("display", "none");
  239. $("#downloadlog").css("display", "none");
  240. BottomToolbar.setupFilmStripOnly();
  241. messageHandler.disableNotifications();
  242. $('body').popover("disable");
  243. JitsiPopover.enabled = false;
  244. }
  245. document.title = interfaceConfig.APP_NAME;
  246. if(config.requireDisplayName) {
  247. if (APP.settings.getDisplayName()) {
  248. promptDisplayName();
  249. }
  250. }
  251. if (!interfaceConfig.filmStripOnly) {
  252. toastr.options = {
  253. "closeButton": true,
  254. "debug": false,
  255. "positionClass": "notification-bottom-right",
  256. "onclick": null,
  257. "showDuration": "300",
  258. "hideDuration": "1000",
  259. "timeOut": "2000",
  260. "extendedTimeOut": "1000",
  261. "showEasing": "swing",
  262. "hideEasing": "linear",
  263. "showMethod": "fadeIn",
  264. "hideMethod": "fadeOut",
  265. "reposition": function () {
  266. if (PanelToggler.isVisible()) {
  267. $("#toast-container").addClass("notification-bottom-right-center");
  268. } else {
  269. $("#toast-container").removeClass("notification-bottom-right-center");
  270. }
  271. },
  272. "newestOnTop": false
  273. };
  274. SettingsMenu.init(eventEmitter);
  275. }
  276. // Return true to indicate that the UI has been fully started and
  277. // conference ready.
  278. return true;
  279. };
  280. UI.addLocalStream = function (track) {
  281. switch (track.getType()) {
  282. case 'audio':
  283. VideoLayout.changeLocalAudio(track);
  284. break;
  285. case 'video':
  286. VideoLayout.changeLocalVideo(track);
  287. break;
  288. default:
  289. console.error("Unknown stream type: " + track.getType());
  290. break;
  291. }
  292. };
  293. UI.addRemoteStream = function (stream) {
  294. VideoLayout.onRemoteStreamAdded(stream);
  295. };
  296. function chatAddError(errorMessage, originalText) {
  297. return Chat.chatAddError(errorMessage, originalText);
  298. }
  299. UI.setSubject = function (subject) {
  300. Chat.setSubject(subject);
  301. };
  302. UI.initEtherpad = function (name) {
  303. if (etherpadManager || !config.etherpad_base || !name) {
  304. return;
  305. }
  306. console.log('Etherpad is enabled');
  307. etherpadManager = new EtherpadManager(config.etherpad_base, name);
  308. Toolbar.showEtherpadButton();
  309. };
  310. UI.addUser = function (id, displayName) {
  311. ContactList.addContact(id);
  312. messageHandler.notify(
  313. displayName,'notify.somebody', 'connected', 'notify.connected'
  314. );
  315. if (!config.startAudioMuted ||
  316. config.startAudioMuted > APP.conference.membersCount)
  317. UIUtil.playSoundNotification('userJoined');
  318. // Configure avatar
  319. UI.setUserAvatar(id, displayName);
  320. // Add Peer's container
  321. VideoLayout.addParticipantContainer(id);
  322. };
  323. UI.removeUser = function (id, displayName) {
  324. ContactList.removeContact(id);
  325. messageHandler.notify(
  326. displayName,'notify.somebody', 'disconnected', 'notify.disconnected'
  327. );
  328. if (!config.startAudioMuted
  329. || config.startAudioMuted > APP.conference.membersCount) {
  330. UIUtil.playSoundNotification('userLeft');
  331. }
  332. VideoLayout.removeParticipantContainer(id);
  333. };
  334. //FIXME: NOT USED. Should start using the lib
  335. // function onMucPresenceStatus(jid, info) {
  336. // VideoLayout.setPresenceStatus(Strophe.getResourceFromJid(jid), info.status);
  337. // }
  338. UI.onPeerVideoTypeChanged = (id, newVideoType) => {
  339. VideoLayout.onVideoTypeChanged(id, newVideoType);
  340. };
  341. UI.updateLocalRole = function (isModerator) {
  342. VideoLayout.showModeratorIndicator();
  343. Toolbar.showSipCallButton(isModerator);
  344. Toolbar.showRecordingButton(isModerator);
  345. SettingsMenu.onRoleChanged();
  346. if (isModerator) {
  347. messageHandler.notify(null, "notify.me", 'connected', "notify.moderator");
  348. Toolbar.checkAutoRecord();
  349. }
  350. };
  351. UI.updateUserRole = function (user) {
  352. VideoLayout.showModeratorIndicator();
  353. if (!user.isModerator()) {
  354. return;
  355. }
  356. var displayName = user.getDisplayName();
  357. if (displayName) {
  358. messageHandler.notify(
  359. displayName, 'notify.somebody',
  360. 'connected', 'notify.grantedTo', {
  361. to: displayName
  362. }
  363. );
  364. } else {
  365. messageHandler.notify(
  366. '', 'notify.somebody',
  367. 'connected', 'notify.grantedToUnknown', {}
  368. );
  369. }
  370. };
  371. UI.toggleSmileys = function () {
  372. Chat.toggleSmileys();
  373. };
  374. UI.getSettings = function () {
  375. return Settings.getSettings();
  376. };
  377. UI.toggleFilmStrip = function () {
  378. BottomToolbar.toggleFilmStrip();
  379. };
  380. UI.toggleChat = function () {
  381. PanelToggler.toggleChat();
  382. };
  383. UI.toggleContactList = function () {
  384. PanelToggler.toggleContactList();
  385. };
  386. UI.inputDisplayNameHandler = function (value) {
  387. VideoLayout.inputDisplayNameHandler(value);
  388. };
  389. /**
  390. * Return the type of the remote video.
  391. * @param jid the jid for the remote video
  392. * @returns the video type video or screen.
  393. */
  394. UI.getRemoteVideoType = function (jid) {
  395. return VideoLayout.getRemoteVideoType(jid);
  396. };
  397. UI.connectionIndicatorShowMore = function(jid) {
  398. return VideoLayout.showMore(jid);
  399. };
  400. UI.showLoginPopup = function(callback) {
  401. console.log('password is required');
  402. var message = '<h2 data-i18n="dialog.passwordRequired">';
  403. message += APP.translation.translateString(
  404. "dialog.passwordRequired");
  405. message += '</h2>' +
  406. '<input name="username" type="text" ' +
  407. 'placeholder="user@domain.net" autofocus>' +
  408. '<input name="password" ' +
  409. 'type="password" data-i18n="[placeholder]dialog.userPassword"' +
  410. ' placeholder="user password">';
  411. UI.messageHandler.openTwoButtonDialog(null, null, null, message,
  412. true,
  413. "dialog.Ok",
  414. function (e, v, m, f) {
  415. if (v) {
  416. if (f.username && f.password) {
  417. callback(f.username, f.password);
  418. }
  419. }
  420. },
  421. null, null, ':input:first'
  422. );
  423. };
  424. UI.askForNickname = function () {
  425. return window.prompt('Your nickname (optional)');
  426. };
  427. /**
  428. * Sets muted audio state for participant
  429. */
  430. UI.setAudioMuted = function (id, muted) {
  431. VideoLayout.onAudioMute(id, muted);
  432. if(APP.conference.isLocalId(id))
  433. UIUtil.buttonClick("#toolbar_button_mute",
  434. "icon-microphone icon-mic-disabled");
  435. };
  436. /**
  437. * Sets muted video state for participant
  438. */
  439. UI.setVideoMuted = function (id, muted) {
  440. VideoLayout.onVideoMute(id, muted);
  441. if(APP.conference.isLocalId(id))
  442. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  443. };
  444. UI.addListener = function (type, listener) {
  445. eventEmitter.on(type, listener);
  446. };
  447. UI.clickOnVideo = function (videoNumber) {
  448. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  449. if (remoteVideos.length > videoNumber) {
  450. remoteVideos[videoNumber].click();
  451. }
  452. };
  453. //Used by torture
  454. UI.showToolbar = function () {
  455. return ToolbarToggler.showToolbar();
  456. };
  457. //Used by torture
  458. UI.dockToolbar = function (isDock) {
  459. ToolbarToggler.dockToolbar(isDock);
  460. };
  461. UI.setUserAvatar = function (id, email) {
  462. // update avatar
  463. Avatar.setUserAvatar(id, email);
  464. var thumbUrl = Avatar.getThumbUrl(id);
  465. var contactListUrl = Avatar.getContactListUrl(id);
  466. VideoLayout.changeUserAvatar(id, thumbUrl);
  467. ContactList.changeUserAvatar(id, contactListUrl);
  468. if (APP.conference.isLocalId(id)) {
  469. SettingsMenu.changeAvatar(thumbUrl);
  470. }
  471. };
  472. UI.notifyConnectionFailed = function (stropheErrorMsg) {
  473. var title = APP.translation.generateTranslationHTML(
  474. "dialog.error");
  475. var message;
  476. if (stropheErrorMsg) {
  477. message = APP.translation.generateTranslationHTML(
  478. "dialog.connectErrorWithMsg", {msg: stropheErrorMsg});
  479. } else {
  480. message = APP.translation.generateTranslationHTML(
  481. "dialog.connectError");
  482. }
  483. messageHandler.openDialog(
  484. title, message, true, {}, function (e, v, m, f) { return false; }
  485. );
  486. };
  487. UI.notifyFirefoxExtensionRequired = function (url) {
  488. messageHandler.openMessageDialog(
  489. "dialog.extensionRequired",
  490. null,
  491. null,
  492. APP.translation.generateTranslationHTML(
  493. "dialog.firefoxExtensionPrompt", {url: url}
  494. )
  495. );
  496. };
  497. UI.notifyInitiallyMuted = function () {
  498. messageHandler.notify(
  499. null, "notify.mutedTitle", "connected", "notify.muted", null, {timeOut: 120000}
  500. );
  501. };
  502. UI.markDominantSpiker = function (id) {
  503. VideoLayout.onDominantSpeakerChanged(id);
  504. };
  505. UI.handleLastNEndpoints = function (ids) {
  506. VideoLayout.onLastNEndpointsChanged(ids, []);
  507. };
  508. UI.setAudioLevel = function (id, lvl) {
  509. VideoLayout.setAudioLevel(id, lvl);
  510. };
  511. UI.updateDesktopSharingButtons = function (isSharingScreen) {
  512. Toolbar.changeDesktopSharingButtonState(isSharingScreen);
  513. };
  514. UI.hideStats = function () {
  515. VideoLayout.hideStats();
  516. };
  517. UI.updateLocalStats = function (percent, stats) {
  518. VideoLayout.updateLocalConnectionStats(percent, stats);
  519. };
  520. UI.updateRemoteStats = function (id, percent, stats) {
  521. VideoLayout.updateConnectionStats(id, percent, stats);
  522. };
  523. UI.markVideoInterrupted = function (interrupted) {
  524. if (interrupted) {
  525. VideoLayout.onVideoInterrupted();
  526. } else {
  527. VideoLayout.onVideoRestored();
  528. }
  529. };
  530. UI.markRoomLocked = function (locked) {
  531. if (locked) {
  532. Toolbar.lockLockButton();
  533. } else {
  534. Toolbar.unlockLockButton();
  535. }
  536. };
  537. UI.addMessage = function (from, displayName, message, stamp) {
  538. Chat.updateChatConversation(from, displayName, message, stamp);
  539. };
  540. UI.updateDTMFSupport = function (isDTMFSupported) {
  541. //TODO: enable when the UI is ready
  542. //Toolbar.showDialPadButton(dtmfSupport);
  543. };
  544. /**
  545. * Invite participants to conference.
  546. */
  547. UI.inviteParticipants = function (roomUrl, conferenceName, key, nick) {
  548. let keyText = "";
  549. if (key) {
  550. keyText = APP.translation.translateString(
  551. "email.sharedKey", {sharedKey: key}
  552. );
  553. }
  554. let and = APP.translation.translateString("email.and");
  555. let supportedBrowsers = `Chromium, Google Chrome ${and} Opera`;
  556. let subject = APP.translation.translateString(
  557. "email.subject", {appName:interfaceConfig.APP_NAME, conferenceName}
  558. );
  559. let body = APP.translation.translateString(
  560. "email.body", {
  561. appName:interfaceConfig.APP_NAME,
  562. sharedKeyText: keyText,
  563. roomUrl,
  564. supportedBrowsers
  565. }
  566. );
  567. body = body.replace(/\n/g, "%0D%0A");
  568. if (nick) {
  569. body += "%0D%0A%0D%0A" + nick;
  570. }
  571. if (interfaceConfig.INVITATION_POWERED_BY) {
  572. body += "%0D%0A%0D%0A--%0D%0Apowered by jitsi.org";
  573. }
  574. window.open(`mailto:?subject=${subject}&body=${body}`, '_blank');
  575. };
  576. UI.requestFeedback = function () {
  577. return new Promise(function (resolve, reject) {
  578. if (Feedback.isEnabled()) {
  579. // If the user has already entered feedback, we'll show the window and
  580. // immidiately start the conference dispose timeout.
  581. if (Feedback.feedbackScore > 0) {
  582. Feedback.openFeedbackWindow();
  583. resolve();
  584. } else { // Otherwise we'll wait for user's feedback.
  585. Feedback.openFeedbackWindow(resolve);
  586. }
  587. } else {
  588. // If the feedback functionality isn't enabled we show a thank you
  589. // dialog.
  590. messageHandler.openMessageDialog(
  591. null, null, null,
  592. APP.translation.translateString(
  593. "dialog.thankYou", {appName:interfaceConfig.APP_NAME}
  594. )
  595. );
  596. resolve();
  597. }
  598. });
  599. };
  600. UI.requestRecordingToken = function () {
  601. let msg = APP.translation.generateTranslationHTML("dialog.recordingToken");
  602. let token = APP.translation.translateString("dialog.token");
  603. return new Promise(function (resolve, reject) {
  604. messageHandler.openTwoButtonDialog(
  605. null, null, null,
  606. `<h2>${msg}</h2>
  607. <input name="recordingToken" type="text"
  608. data-i18n="[placeholder]dialog.token"
  609. placeholder="${token}" autofocus>`,
  610. false, "dialog.Save",
  611. function (e, v, m, f) {
  612. if (v && f.recordingToken) {
  613. resolve(UIUtil.escapeHtml(f.recordingToken));
  614. } else {
  615. reject();
  616. }
  617. },
  618. null,
  619. function () { },
  620. ':input:first'
  621. );
  622. });
  623. };
  624. UI.updateRecordingState = function (state) {
  625. Toolbar.updateRecordingState(state);
  626. };
  627. UI.notifyTokenAuthFailed = function () {
  628. messageHandler.showError("dialog.error", "dialog.tokenAuthFailed");
  629. };
  630. UI.updateAuthInfo = function (isAuthEnabled, login) {
  631. let loggedIn = !!login;
  632. Toolbar.showAuthenticateButton(isAuthEnabled);
  633. if (isAuthEnabled) {
  634. Toolbar.setAuthenticatedIdentity(login);
  635. Toolbar.showLoginButton(!loggedIn);
  636. Toolbar.showLogoutButton(loggedIn);
  637. }
  638. };
  639. UI.showPrezi = function (userId, url, slide) {
  640. preziManager.showPrezi(userId, url, slide);
  641. };
  642. UI.stopPrezi = function (userId) {
  643. if (preziManager.isSharing(userId)) {
  644. preziManager.removePrezi(userId);
  645. }
  646. };
  647. module.exports = UI;