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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  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. import { reload } from '../util/helpers';
  20. var EventEmitter = require("events");
  21. UI.messageHandler = require("./util/MessageHandler");
  22. var messageHandler = UI.messageHandler;
  23. var JitsiPopover = require("./util/JitsiPopover");
  24. var Feedback = require("./Feedback");
  25. var eventEmitter = new EventEmitter();
  26. UI.eventEmitter = eventEmitter;
  27. let preziManager;
  28. let etherpadManager;
  29. /**
  30. * Prompt user for nickname.
  31. */
  32. function promptDisplayName() {
  33. let nickRequiredMsg = APP.translation.translateString("dialog.displayNameRequired");
  34. let defaultNickMsg = APP.translation.translateString(
  35. "defaultNickname", {name: "Jane Pink"}
  36. );
  37. let message = `
  38. <h2 data-i18n="dialog.displayNameRequired">${nickRequiredMsg}</h2>
  39. <input name="displayName" type="text"
  40. data-i18n="[placeholder]defaultNickname"
  41. placeholder="${defaultNickMsg}" autofocus>`;
  42. let buttonTxt = APP.translation.generateTranslationHTML("dialog.Ok");
  43. let buttons = [{title: buttonTxt, value: "ok"}];
  44. messageHandler.openDialog(
  45. null, message,
  46. true,
  47. buttons,
  48. function (e, v, m, f) {
  49. if (v == "ok") {
  50. let displayName = f.displayName;
  51. if (displayName) {
  52. UI.inputDisplayNameHandler(displayName);
  53. return true;
  54. }
  55. }
  56. e.preventDefault();
  57. },
  58. function () {
  59. let form = $.prompt.getPrompt();
  60. let input = form.find("input[name='displayName']");
  61. input.focus();
  62. let button = form.find("button");
  63. button.attr("disabled", "disabled");
  64. input.keyup(function () {
  65. if (input.val()) {
  66. button.removeAttr("disabled");
  67. } else {
  68. button.attr("disabled", "disabled");
  69. }
  70. });
  71. }
  72. );
  73. }
  74. /**
  75. * Initialize chat.
  76. */
  77. function setupChat() {
  78. Chat.init(eventEmitter);
  79. $("#toggle_smileys").click(function() {
  80. Chat.toggleSmileys();
  81. });
  82. }
  83. /**
  84. * Initialize toolbars.
  85. */
  86. function setupToolbars() {
  87. Toolbar.init(eventEmitter);
  88. Toolbar.setupButtonsFromConfig();
  89. BottomToolbar.setupListeners(eventEmitter);
  90. }
  91. /**
  92. * Toggles the application in and out of full screen mode
  93. * (a.k.a. presentation mode in Chrome).
  94. * @see https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API
  95. */
  96. function toggleFullScreen () {
  97. let isNotFullScreen = !document.fullscreenElement && // alternative standard method
  98. !document.mozFullScreenElement && // current working methods
  99. !document.webkitFullscreenElement &&
  100. !document.msFullscreenElement;
  101. if (isNotFullScreen) {
  102. if (document.documentElement.requestFullscreen) {
  103. document.documentElement.requestFullscreen();
  104. } else if (document.documentElement.msRequestFullscreen) {
  105. document.documentElement.msRequestFullscreen();
  106. } else if (document.documentElement.mozRequestFullScreen) {
  107. document.documentElement.mozRequestFullScreen();
  108. } else if (document.documentElement.webkitRequestFullscreen) {
  109. document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  110. }
  111. } else {
  112. if (document.exitFullscreen) {
  113. document.exitFullscreen();
  114. } else if (document.msExitFullscreen) {
  115. document.msExitFullscreen();
  116. } else if (document.mozCancelFullScreen) {
  117. document.mozCancelFullScreen();
  118. } else if (document.webkitExitFullscreen) {
  119. document.webkitExitFullscreen();
  120. }
  121. }
  122. }
  123. /**
  124. * Notify user that server has shut down.
  125. */
  126. UI.notifyGracefulShutdown = function () {
  127. messageHandler.openMessageDialog(
  128. 'dialog.serviceUnavailable',
  129. 'dialog.gracefulShutdown'
  130. );
  131. };
  132. /**
  133. * Notify user that reservation error happened.
  134. */
  135. UI.notifyReservationError = function (code, msg) {
  136. var title = APP.translation.generateTranslationHTML(
  137. "dialog.reservationError");
  138. var message = APP.translation.generateTranslationHTML(
  139. "dialog.reservationErrorMsg", {code: code, msg: msg});
  140. messageHandler.openDialog(
  141. title,
  142. message,
  143. true, {},
  144. function (event, value, message, formVals) {
  145. return false;
  146. }
  147. );
  148. };
  149. /**
  150. * Notify user that he has been kicked from the server.
  151. */
  152. UI.notifyKicked = function () {
  153. messageHandler.openMessageDialog("dialog.sessTerminated", "dialog.kickMessage");
  154. };
  155. /**
  156. * Notify user that conference was destroyed.
  157. * @param reason {string} the reason text
  158. */
  159. UI.notifyConferenceDestroyed = function (reason) {
  160. //FIXME: use Session Terminated from translation, but
  161. // 'reason' text comes from XMPP packet and is not translated
  162. var title = APP.translation.generateTranslationHTML("dialog.sessTerminated");
  163. messageHandler.openDialog(
  164. title, reason, true, {},
  165. function (event, value, message, formVals) {
  166. return false;
  167. }
  168. );
  169. };
  170. /**
  171. * Notify user that Jitsi Videobridge is not accessible.
  172. */
  173. UI.notifyBridgeDown = function () {
  174. messageHandler.showError("dialog.error", "dialog.bridgeUnavailable");
  175. };
  176. /**
  177. * Show chat error.
  178. * @param err the Error
  179. * @param msg
  180. */
  181. UI.showChatError = function (err, msg) {
  182. if (interfaceConfig.filmStripOnly) {
  183. return;
  184. }
  185. Chat.chatAddError(err, msg);
  186. };
  187. /**
  188. * Change nickname for the user.
  189. * @param {string} id user id
  190. * @param {string} displayName new nickname
  191. */
  192. UI.changeDisplayName = function (id, displayName) {
  193. ContactList.onDisplayNameChange(id, displayName);
  194. SettingsMenu.onDisplayNameChange(id, displayName);
  195. VideoLayout.onDisplayNameChanged(id, displayName);
  196. if (APP.conference.isLocalId(id)) {
  197. Chat.setChatConversationMode(!!displayName);
  198. }
  199. };
  200. /**
  201. * Intitialize conference UI.
  202. */
  203. UI.initConference = function () {
  204. let id = APP.conference.localId;
  205. Toolbar.updateRoomUrl(window.location.href);
  206. let meHTML = APP.translation.generateTranslationHTML("me");
  207. let email = Settings.getEmail();
  208. let uid = Settings.getUserId();
  209. $("#localNick").html(email || `${uid} (${meHTML})`);
  210. // Add myself to the contact list.
  211. ContactList.addContact(id);
  212. // Once we've joined the muc show the toolbar
  213. ToolbarToggler.showToolbar();
  214. let displayName = config.displayJids ? id : Settings.getDisplayName();
  215. if (displayName) {
  216. UI.changeDisplayName('localVideoContainer', displayName);
  217. }
  218. // Make sure we configure our avatar id, before creating avatar for us
  219. UI.setUserAvatar(id, email);
  220. Toolbar.checkAutoEnableDesktopSharing();
  221. if(!interfaceConfig.filmStripOnly) {
  222. Feedback.init();
  223. }
  224. };
  225. UI.mucJoined = function () {
  226. VideoLayout.mucJoined();
  227. };
  228. /**
  229. * Setup some UI event listeners.
  230. */
  231. function registerListeners() {
  232. UI.addListener(UIEvents.EMAIL_CHANGED, function (email) {
  233. UI.setUserAvatar(APP.conference.localId, email);
  234. });
  235. UI.addListener(UIEvents.PREZI_CLICKED, function () {
  236. preziManager.handlePreziButtonClicked();
  237. });
  238. UI.addListener(UIEvents.ETHERPAD_CLICKED, function () {
  239. if (etherpadManager) {
  240. etherpadManager.toggleEtherpad();
  241. }
  242. });
  243. UI.addListener(UIEvents.FULLSCREEN_TOGGLE, toggleFullScreen);
  244. UI.addListener(UIEvents.TOGGLE_CHAT, UI.toggleChat);
  245. UI.addListener(UIEvents.TOGGLE_SETTINGS, function () {
  246. PanelToggler.toggleSettingsMenu();
  247. });
  248. UI.addListener(UIEvents.TOGGLE_CONTACT_LIST, UI.toggleContactList);
  249. UI.addListener(UIEvents.TOGGLE_FILM_STRIP, UI.toggleFilmStrip);
  250. }
  251. /**
  252. * Setup some DOM event listeners.
  253. */
  254. function bindEvents() {
  255. function onResize() {
  256. PanelToggler.resizeChat();
  257. VideoLayout.resizeLargeVideoContainer(PanelToggler.isVisible());
  258. }
  259. // Resize and reposition videos in full screen mode.
  260. $(document).on(
  261. 'webkitfullscreenchange mozfullscreenchange fullscreenchange',
  262. onResize
  263. );
  264. $(window).resize(onResize);
  265. }
  266. /**
  267. * Starts the UI module and initializes all related components.
  268. *
  269. * @returns {boolean} true if the UI is ready and the conference should be
  270. * esablished, false - otherwise (for example in the case of welcome page)
  271. */
  272. UI.start = function () {
  273. document.title = interfaceConfig.APP_NAME;
  274. var setupWelcomePage = null;
  275. if(config.enableWelcomePage && window.location.pathname == "/" &&
  276. (!window.localStorage.welcomePageDisabled ||
  277. window.localStorage.welcomePageDisabled == "false")) {
  278. $("#videoconference_page").hide();
  279. if (!setupWelcomePage)
  280. setupWelcomePage = require("./welcome_page/WelcomePage");
  281. setupWelcomePage();
  282. // Return false to indicate that the UI hasn't been fully started and
  283. // conference ready. We're still waiting for input from the user.
  284. return false;
  285. }
  286. $("#welcome_page").hide();
  287. // Set the defaults for prompt dialogs.
  288. $.prompt.setDefaults({persistent: false});
  289. registerListeners();
  290. BottomToolbar.init();
  291. VideoLayout.init(eventEmitter);
  292. if (!interfaceConfig.filmStripOnly) {
  293. VideoLayout.initLargeVideo(PanelToggler.isVisible());
  294. }
  295. VideoLayout.resizeLargeVideoContainer(PanelToggler.isVisible(), true);
  296. ContactList.init(eventEmitter);
  297. bindEvents();
  298. preziManager = new PreziManager(eventEmitter);
  299. if (!interfaceConfig.filmStripOnly) {
  300. $("#videospace").mousemove(function () {
  301. return ToolbarToggler.showToolbar();
  302. });
  303. setupToolbars();
  304. setupChat();
  305. // Display notice message at the top of the toolbar
  306. if (config.noticeMessage) {
  307. $('#noticeText').text(config.noticeMessage);
  308. $('#notice').css({display: 'block'});
  309. }
  310. $("#downloadlog").click(function (event) {
  311. let logs = APP.conference.getLogs();
  312. let data = encodeURIComponent(JSON.stringify(logs, null, ' '));
  313. let elem = event.target.parentNode;
  314. elem.download = 'meetlog.json';
  315. elem.href = 'data:application/json;charset=utf-8,\n' + data;
  316. });
  317. } else {
  318. $("#header").css("display", "none");
  319. $("#bottomToolbar").css("display", "none");
  320. $("#downloadlog").css("display", "none");
  321. BottomToolbar.setupFilmStripOnly();
  322. messageHandler.disableNotifications();
  323. $('body').popover("disable");
  324. JitsiPopover.enabled = false;
  325. }
  326. document.title = interfaceConfig.APP_NAME;
  327. if(config.requireDisplayName) {
  328. if (!APP.settings.getDisplayName()) {
  329. promptDisplayName();
  330. }
  331. }
  332. if (!interfaceConfig.filmStripOnly) {
  333. toastr.options = {
  334. "closeButton": true,
  335. "debug": false,
  336. "positionClass": "notification-bottom-right",
  337. "onclick": null,
  338. "showDuration": "300",
  339. "hideDuration": "1000",
  340. "timeOut": "2000",
  341. "extendedTimeOut": "1000",
  342. "showEasing": "swing",
  343. "hideEasing": "linear",
  344. "showMethod": "fadeIn",
  345. "hideMethod": "fadeOut",
  346. "reposition": function () {
  347. if (PanelToggler.isVisible()) {
  348. $("#toast-container").addClass("notification-bottom-right-center");
  349. } else {
  350. $("#toast-container").removeClass("notification-bottom-right-center");
  351. }
  352. },
  353. "newestOnTop": false
  354. };
  355. SettingsMenu.init(eventEmitter);
  356. }
  357. // Return true to indicate that the UI has been fully started and
  358. // conference ready.
  359. return true;
  360. };
  361. /**
  362. * Show local stream on UI.
  363. * @param {JitsiTrack} track stream to show
  364. */
  365. UI.addLocalStream = function (track) {
  366. switch (track.getType()) {
  367. case 'audio':
  368. VideoLayout.changeLocalAudio(track);
  369. break;
  370. case 'video':
  371. VideoLayout.changeLocalVideo(track);
  372. break;
  373. default:
  374. console.error("Unknown stream type: " + track.getType());
  375. break;
  376. }
  377. };
  378. /**
  379. * Show remote stream on UI.
  380. * @param {JitsiTrack} track stream to show
  381. */
  382. UI.addRemoteStream = function (track) {
  383. VideoLayout.onRemoteStreamAdded(track);
  384. };
  385. function chatAddError(errorMessage, originalText) {
  386. return Chat.chatAddError(errorMessage, originalText);
  387. }
  388. /**
  389. * Update chat subject.
  390. * @param {string} subject new chat subject
  391. */
  392. UI.setSubject = function (subject) {
  393. Chat.setSubject(subject);
  394. };
  395. /**
  396. * Setup and show Etherpad.
  397. * @param {string} name etherpad id
  398. */
  399. UI.initEtherpad = function (name) {
  400. if (etherpadManager || !config.etherpad_base || !name) {
  401. return;
  402. }
  403. console.log('Etherpad is enabled');
  404. etherpadManager = new EtherpadManager(config.etherpad_base, name);
  405. Toolbar.showEtherpadButton();
  406. };
  407. /**
  408. * Show user on UI.
  409. * @param {string} id user id
  410. * @param {string} displayName user nickname
  411. */
  412. UI.addUser = function (id, displayName) {
  413. ContactList.addContact(id);
  414. messageHandler.notify(
  415. displayName,'notify.somebody', 'connected', 'notify.connected'
  416. );
  417. if (!config.startAudioMuted ||
  418. config.startAudioMuted > APP.conference.membersCount)
  419. UIUtil.playSoundNotification('userJoined');
  420. // Configure avatar
  421. UI.setUserAvatar(id);
  422. // Add Peer's container
  423. VideoLayout.addParticipantContainer(id);
  424. };
  425. /**
  426. * Remove user from UI.
  427. * @param {string} id user id
  428. * @param {string} displayName user nickname
  429. */
  430. UI.removeUser = function (id, displayName) {
  431. ContactList.removeContact(id);
  432. messageHandler.notify(
  433. displayName,'notify.somebody', 'disconnected', 'notify.disconnected'
  434. );
  435. if (!config.startAudioMuted
  436. || config.startAudioMuted > APP.conference.membersCount) {
  437. UIUtil.playSoundNotification('userLeft');
  438. }
  439. VideoLayout.removeParticipantContainer(id);
  440. };
  441. UI.updateUserStatus = function (id, status) {
  442. VideoLayout.setPresenceStatus(id, status);
  443. };
  444. /**
  445. * Update videotype for specified user.
  446. * @param {string} id user id
  447. * @param {string} newVideoType new videotype
  448. */
  449. UI.onPeerVideoTypeChanged = (id, newVideoType) => {
  450. VideoLayout.onVideoTypeChanged(id, newVideoType);
  451. };
  452. /**
  453. * Update local user role and show notification if user is moderator.
  454. * @param {boolean} isModerator if local user is moderator or not
  455. */
  456. UI.updateLocalRole = function (isModerator) {
  457. VideoLayout.showModeratorIndicator();
  458. Toolbar.showSipCallButton(isModerator);
  459. Toolbar.showRecordingButton(isModerator);
  460. SettingsMenu.onRoleChanged();
  461. if (isModerator) {
  462. messageHandler.notify(null, "notify.me", 'connected', "notify.moderator");
  463. Toolbar.checkAutoRecord();
  464. }
  465. };
  466. /**
  467. * Check the role for the user and reflect it in the UI, moderator ui indication
  468. * and notifies user who is the moderator
  469. * @param user to check for moderator
  470. */
  471. UI.updateUserRole = function (user) {
  472. VideoLayout.showModeratorIndicator();
  473. if (!user.isModerator()) {
  474. return;
  475. }
  476. var displayName = user.getDisplayName();
  477. if (displayName) {
  478. messageHandler.notify(
  479. displayName, 'notify.somebody',
  480. 'connected', 'notify.grantedTo', {
  481. to: displayName
  482. }
  483. );
  484. } else {
  485. messageHandler.notify(
  486. '', 'notify.somebody',
  487. 'connected', 'notify.grantedToUnknown', {}
  488. );
  489. }
  490. };
  491. /**
  492. * Toggles smileys in the chat.
  493. */
  494. UI.toggleSmileys = function () {
  495. Chat.toggleSmileys();
  496. };
  497. /**
  498. * Get current settings.
  499. * @returns {object} settings
  500. */
  501. UI.getSettings = function () {
  502. return Settings.getSettings();
  503. };
  504. /**
  505. * Toggles film strip.
  506. */
  507. UI.toggleFilmStrip = function () {
  508. BottomToolbar.toggleFilmStrip();
  509. };
  510. /**
  511. * Toggles chat panel.
  512. */
  513. UI.toggleChat = function () {
  514. PanelToggler.toggleChat();
  515. };
  516. /**
  517. * Toggles contact list panel.
  518. */
  519. UI.toggleContactList = function () {
  520. PanelToggler.toggleContactList();
  521. };
  522. /**
  523. * Handle new user display name.
  524. */
  525. UI.inputDisplayNameHandler = function (newDisplayName) {
  526. eventEmitter.emit(UIEvents.NICKNAME_CHANGED, newDisplayName);
  527. };
  528. /**
  529. * Return the type of the remote video.
  530. * @param jid the jid for the remote video
  531. * @returns the video type video or screen.
  532. */
  533. UI.getRemoteVideoType = function (jid) {
  534. return VideoLayout.getRemoteVideoType(jid);
  535. };
  536. UI.connectionIndicatorShowMore = function(id) {
  537. VideoLayout.showMore(id);
  538. };
  539. // FIXME check if someone user this
  540. UI.showLoginPopup = function(callback) {
  541. console.log('password is required');
  542. var message = '<h2 data-i18n="dialog.passwordRequired">';
  543. message += APP.translation.translateString(
  544. "dialog.passwordRequired");
  545. message += '</h2>' +
  546. '<input name="username" type="text" ' +
  547. 'placeholder="user@domain.net" autofocus>' +
  548. '<input name="password" ' +
  549. 'type="password" data-i18n="[placeholder]dialog.userPassword"' +
  550. ' placeholder="user password">';
  551. messageHandler.openTwoButtonDialog(null, null, null, message,
  552. true,
  553. "dialog.Ok",
  554. function (e, v, m, f) {
  555. if (v) {
  556. if (f.username && f.password) {
  557. callback(f.username, f.password);
  558. }
  559. }
  560. },
  561. null, null, ':input:first'
  562. );
  563. };
  564. UI.askForNickname = function () {
  565. return window.prompt('Your nickname (optional)');
  566. };
  567. /**
  568. * Sets muted audio state for participant
  569. */
  570. UI.setAudioMuted = function (id, muted) {
  571. VideoLayout.onAudioMute(id, muted);
  572. if (APP.conference.isLocalId(id)) {
  573. Toolbar.markAudioIconAsMuted(muted);
  574. }
  575. };
  576. /**
  577. * Sets muted video state for participant
  578. */
  579. UI.setVideoMuted = function (id, muted) {
  580. VideoLayout.onVideoMute(id, muted);
  581. if (APP.conference.isLocalId(id)) {
  582. Toolbar.markVideoIconAsMuted(muted);
  583. }
  584. };
  585. UI.addListener = function (type, listener) {
  586. eventEmitter.on(type, listener);
  587. };
  588. UI.clickOnVideo = function (videoNumber) {
  589. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  590. if (remoteVideos.length > videoNumber) {
  591. remoteVideos[videoNumber].click();
  592. }
  593. };
  594. //Used by torture
  595. UI.showToolbar = function () {
  596. return ToolbarToggler.showToolbar();
  597. };
  598. //Used by torture
  599. UI.dockToolbar = function (isDock) {
  600. ToolbarToggler.dockToolbar(isDock);
  601. };
  602. /**
  603. * Update user avatar.
  604. * @param {string} id user id
  605. * @param {stirng} email user email
  606. */
  607. UI.setUserAvatar = function (id, email) {
  608. // update avatar
  609. Avatar.setUserAvatar(id, email);
  610. var avatarUrl = Avatar.getAvatarUrl(id);
  611. VideoLayout.changeUserAvatar(id, avatarUrl);
  612. ContactList.changeUserAvatar(id, avatarUrl);
  613. if (APP.conference.isLocalId(id)) {
  614. SettingsMenu.changeAvatar(avatarUrl);
  615. }
  616. };
  617. /**
  618. * Notify user that connection failed.
  619. * @param {string} stropheErrorMsg raw Strophe error message
  620. */
  621. UI.notifyConnectionFailed = function (stropheErrorMsg) {
  622. var title = APP.translation.generateTranslationHTML(
  623. "dialog.error");
  624. var message;
  625. if (stropheErrorMsg) {
  626. message = APP.translation.generateTranslationHTML(
  627. "dialog.connectErrorWithMsg", {msg: stropheErrorMsg});
  628. } else {
  629. message = APP.translation.generateTranslationHTML(
  630. "dialog.connectError");
  631. }
  632. messageHandler.openDialog(
  633. title, message, true, {}, function (e, v, m, f) { return false; }
  634. );
  635. };
  636. /**
  637. * Notify user that he need to install Firefox extension to share screen.
  638. * @param {stirng} url extension url
  639. */
  640. UI.notifyFirefoxExtensionRequired = function (url) {
  641. messageHandler.openMessageDialog(
  642. "dialog.extensionRequired",
  643. null,
  644. null,
  645. APP.translation.generateTranslationHTML(
  646. "dialog.firefoxExtensionPrompt", {url}
  647. )
  648. );
  649. };
  650. /**
  651. * Notify user that he was automatically muted when joned the conference.
  652. */
  653. UI.notifyInitiallyMuted = function () {
  654. messageHandler.notify(
  655. null, "notify.mutedTitle", "connected", "notify.muted", null, {timeOut: 120000}
  656. );
  657. };
  658. /**
  659. * Mark user as dominant speaker.
  660. * @param {string} id user id
  661. */
  662. UI.markDominantSpeaker = function (id) {
  663. VideoLayout.onDominantSpeakerChanged(id);
  664. };
  665. UI.handleLastNEndpoints = function (ids, enteringIds) {
  666. VideoLayout.onLastNEndpointsChanged(ids, enteringIds);
  667. };
  668. /**
  669. * Update audio level visualization for specified user.
  670. * @param {string} id user id
  671. * @param {number} lvl audio level
  672. */
  673. UI.setAudioLevel = function (id, lvl) {
  674. VideoLayout.setAudioLevel(id, lvl);
  675. };
  676. /**
  677. * Update state of desktop sharing buttons.
  678. */
  679. UI.updateDesktopSharingButtons = function () {
  680. Toolbar.updateDesktopSharingButtonState();
  681. };
  682. /**
  683. * Hide connection quality statistics from UI.
  684. */
  685. UI.hideStats = function () {
  686. VideoLayout.hideStats();
  687. };
  688. /**
  689. * Update local connection quality statistics.
  690. * @param {number} percent
  691. * @param {object} stats
  692. */
  693. UI.updateLocalStats = function (percent, stats) {
  694. VideoLayout.updateLocalConnectionStats(percent, stats);
  695. };
  696. /**
  697. * Update connection quality statistics for remote user.
  698. * @param {string} id user id
  699. * @param {number} percent
  700. * @param {object} stats
  701. */
  702. UI.updateRemoteStats = function (id, percent, stats) {
  703. VideoLayout.updateConnectionStats(id, percent, stats);
  704. };
  705. /**
  706. * Mark video as interrupted or not.
  707. * @param {boolean} interrupted if video is interrupted
  708. */
  709. UI.markVideoInterrupted = function (interrupted) {
  710. if (interrupted) {
  711. VideoLayout.onVideoInterrupted();
  712. } else {
  713. VideoLayout.onVideoRestored();
  714. }
  715. };
  716. /**
  717. * Mark room as locked or not.
  718. * @param {boolean} locked if room is locked.
  719. */
  720. UI.markRoomLocked = function (locked) {
  721. if (locked) {
  722. Toolbar.lockLockButton();
  723. } else {
  724. Toolbar.unlockLockButton();
  725. }
  726. };
  727. /**
  728. * Add chat message.
  729. * @param {string} from user id
  730. * @param {string} displayName user nickname
  731. * @param {string} message message text
  732. * @param {number} stamp timestamp when message was created
  733. */
  734. UI.addMessage = function (from, displayName, message, stamp) {
  735. Chat.updateChatConversation(from, displayName, message, stamp);
  736. };
  737. UI.updateDTMFSupport = function (isDTMFSupported) {
  738. //TODO: enable when the UI is ready
  739. //Toolbar.showDialPadButton(dtmfSupport);
  740. };
  741. /**
  742. * Invite participants to conference.
  743. * @param {string} roomUrl
  744. * @param {string} conferenceName
  745. * @param {string} key
  746. * @param {string} nick
  747. */
  748. UI.inviteParticipants = function (roomUrl, conferenceName, key, nick) {
  749. let keyText = "";
  750. if (key) {
  751. keyText = APP.translation.translateString(
  752. "email.sharedKey", {sharedKey: key}
  753. );
  754. }
  755. let and = APP.translation.translateString("email.and");
  756. let supportedBrowsers = `Chromium, Google Chrome ${and} Opera`;
  757. let subject = APP.translation.translateString(
  758. "email.subject", {appName:interfaceConfig.APP_NAME, conferenceName}
  759. );
  760. let body = APP.translation.translateString(
  761. "email.body", {
  762. appName:interfaceConfig.APP_NAME,
  763. sharedKeyText: keyText,
  764. roomUrl,
  765. supportedBrowsers
  766. }
  767. );
  768. body = body.replace(/\n/g, "%0D%0A");
  769. if (nick) {
  770. body += "%0D%0A%0D%0A" + UIUtil.escapeHtml(nick);
  771. }
  772. if (interfaceConfig.INVITATION_POWERED_BY) {
  773. body += "%0D%0A%0D%0A--%0D%0Apowered by jitsi.org";
  774. }
  775. window.open(`mailto:?subject=${subject}&body=${body}`, '_blank');
  776. };
  777. /**
  778. * Show user feedback dialog if its required or just show "thank you" dialog.
  779. * @returns {Promise} when dialog is closed.
  780. */
  781. UI.requestFeedback = function () {
  782. return new Promise(function (resolve, reject) {
  783. if (Feedback.isEnabled()) {
  784. // If the user has already entered feedback, we'll show the window and
  785. // immidiately start the conference dispose timeout.
  786. if (Feedback.feedbackScore > 0) {
  787. Feedback.openFeedbackWindow();
  788. resolve();
  789. } else { // Otherwise we'll wait for user's feedback.
  790. Feedback.openFeedbackWindow(resolve);
  791. }
  792. } else {
  793. // If the feedback functionality isn't enabled we show a thank you
  794. // dialog.
  795. messageHandler.openMessageDialog(
  796. null, null, null,
  797. APP.translation.translateString(
  798. "dialog.thankYou", {appName:interfaceConfig.APP_NAME}
  799. )
  800. );
  801. resolve();
  802. }
  803. });
  804. };
  805. /**
  806. * Request recording token from the user.
  807. * @returns {Promise}
  808. */
  809. UI.requestRecordingToken = function () {
  810. let msg = APP.translation.generateTranslationHTML("dialog.recordingToken");
  811. let token = APP.translation.translateString("dialog.token");
  812. return new Promise(function (resolve, reject) {
  813. messageHandler.openTwoButtonDialog(
  814. null, null, null,
  815. `<h2>${msg}</h2>
  816. <input name="recordingToken" type="text"
  817. data-i18n="[placeholder]dialog.token"
  818. placeholder="${token}" autofocus>`,
  819. false, "dialog.Save",
  820. function (e, v, m, f) {
  821. if (v && f.recordingToken) {
  822. resolve(UIUtil.escapeHtml(f.recordingToken));
  823. } else {
  824. reject();
  825. }
  826. },
  827. null,
  828. function () { },
  829. ':input:first'
  830. );
  831. });
  832. };
  833. UI.updateRecordingState = function (state) {
  834. Toolbar.updateRecordingState(state);
  835. };
  836. UI.notifyTokenAuthFailed = function () {
  837. messageHandler.showError("dialog.error", "dialog.tokenAuthFailed");
  838. };
  839. UI.notifyInternalError = function () {
  840. messageHandler.showError("dialog.sorry", "dialog.internalError");
  841. };
  842. UI.notifyFocusDisconnected = function (focus, retrySec) {
  843. messageHandler.notify(
  844. null, "notify.focus",
  845. 'disconnected', "notify.focusFail",
  846. {component: focus, ms: retrySec}
  847. );
  848. };
  849. /**
  850. * Notify user that focus left the conference so page should be reloaded.
  851. */
  852. UI.notifyFocusLeft = function () {
  853. let title = APP.translation.generateTranslationHTML(
  854. 'dialog.serviceUnavailable'
  855. );
  856. let msg = APP.translation.generateTranslationHTML(
  857. 'dialog.jicofoUnavailable'
  858. );
  859. messageHandler.openDialog(
  860. title,
  861. msg,
  862. true, // persistent
  863. [{title: 'retry'}],
  864. function () {
  865. reload();
  866. return false;
  867. }
  868. );
  869. };
  870. /**
  871. * Updates auth info on the UI.
  872. * @param {boolean} isAuthEnabled if authentication is enabled
  873. * @param {string} [login] current login
  874. */
  875. UI.updateAuthInfo = function (isAuthEnabled, login) {
  876. let loggedIn = !!login;
  877. Toolbar.showAuthenticateButton(isAuthEnabled);
  878. if (isAuthEnabled) {
  879. Toolbar.setAuthenticatedIdentity(login);
  880. Toolbar.showLoginButton(!loggedIn);
  881. Toolbar.showLogoutButton(loggedIn);
  882. }
  883. };
  884. /**
  885. * Show Prezi from the user.
  886. * @param {string} userId user id
  887. * @param {string} url Prezi url
  888. * @param {number} slide slide to show
  889. */
  890. UI.showPrezi = function (userId, url, slide) {
  891. preziManager.showPrezi(userId, url, slide);
  892. };
  893. /**
  894. * Stop showing Prezi from the user.
  895. * @param {string} userId user id
  896. */
  897. UI.stopPrezi = function (userId) {
  898. if (preziManager.isSharing(userId)) {
  899. preziManager.removePrezi(userId);
  900. }
  901. };
  902. UI.onStartMutedChanged = function () {
  903. SettingsMenu.onStartMutedChanged();
  904. };
  905. /**
  906. * Update list of available physical devices.
  907. * @param {object[]} devices new list of available devices
  908. */
  909. UI.onAvailableDevicesChanged = function (devices) {
  910. SettingsMenu.onAvailableDevicesChanged(devices);
  911. };
  912. /**
  913. * Returns the id of the current video shown on large.
  914. * Currently used by tests (torture).
  915. */
  916. UI.getLargeVideoID = function () {
  917. return VideoLayout.getLargeVideoID();
  918. };
  919. /**
  920. * Shows dialog with a link to FF extension.
  921. */
  922. UI.showExtensionRequiredDialog = function (url) {
  923. messageHandler.openMessageDialog(
  924. "dialog.extensionRequired",
  925. null,
  926. null,
  927. APP.translation.generateTranslationHTML(
  928. "dialog.firefoxExtensionPrompt", {url: url}));
  929. };
  930. UI.updateDevicesAvailability = function (id, devices) {
  931. VideoLayout.setDeviceAvailabilityIcons(id, devices);
  932. };
  933. module.exports = UI;