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.

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