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

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