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

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