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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096
  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 EtherpadManager from './etherpad/Etherpad';
  15. import SharedVideoManager from './shared_video/SharedVideo';
  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 etherpadManager;
  29. let sharedVideoManager;
  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. 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. VideoLayout.onDisplayNameChanged(id, displayName);
  195. if (APP.conference.isLocalId(id) || id === 'localVideoContainer') {
  196. SettingsMenu.changeDisplayName(displayName);
  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. // Add myself to the contact list.
  207. ContactList.addContact(id);
  208. // Once we've joined the muc show the toolbar
  209. ToolbarToggler.showToolbar();
  210. let displayName = config.displayJids ? id : Settings.getDisplayName();
  211. if (displayName) {
  212. UI.changeDisplayName('localVideoContainer', displayName);
  213. }
  214. // Make sure we configure our avatar id, before creating avatar for us
  215. UI.setUserAvatar(id, Settings.getEmail());
  216. Toolbar.checkAutoEnableDesktopSharing();
  217. if(!interfaceConfig.filmStripOnly) {
  218. Feedback.init();
  219. }
  220. };
  221. UI.mucJoined = function () {
  222. VideoLayout.mucJoined();
  223. };
  224. /**
  225. * Setup some UI event listeners.
  226. */
  227. function registerListeners() {
  228. UI.addListener(UIEvents.ETHERPAD_CLICKED, function () {
  229. if (etherpadManager) {
  230. etherpadManager.toggleEtherpad();
  231. }
  232. });
  233. UI.addListener(UIEvents.SHARED_VIDEO_CLICKED, function () {
  234. if (sharedVideoManager) {
  235. sharedVideoManager.toggleSharedVideo();
  236. }
  237. });
  238. UI.addListener(UIEvents.FULLSCREEN_TOGGLE, toggleFullScreen);
  239. UI.addListener(UIEvents.TOGGLE_CHAT, UI.toggleChat);
  240. UI.addListener(UIEvents.TOGGLE_SETTINGS, function () {
  241. PanelToggler.toggleSettingsMenu();
  242. });
  243. UI.addListener(UIEvents.TOGGLE_CONTACT_LIST, UI.toggleContactList);
  244. UI.addListener(UIEvents.TOGGLE_FILM_STRIP, function () {
  245. UI.toggleFilmStrip();
  246. VideoLayout.resizeVideoArea(PanelToggler.isVisible(), true, false);
  247. });
  248. }
  249. /**
  250. * Setup some DOM event listeners.
  251. */
  252. function bindEvents() {
  253. function onResize() {
  254. PanelToggler.resizeChat();
  255. VideoLayout.resizeVideoArea(PanelToggler.isVisible());
  256. }
  257. // Resize and reposition videos in full screen mode.
  258. $(document).on(
  259. 'webkitfullscreenchange mozfullscreenchange fullscreenchange',
  260. onResize
  261. );
  262. $(window).resize(onResize);
  263. }
  264. /**
  265. * Starts the UI module and initializes all related components.
  266. *
  267. * @returns {boolean} true if the UI is ready and the conference should be
  268. * esablished, false - otherwise (for example in the case of welcome page)
  269. */
  270. UI.start = function () {
  271. document.title = interfaceConfig.APP_NAME;
  272. var setupWelcomePage = null;
  273. if(config.enableWelcomePage && window.location.pathname == "/" &&
  274. Settings.isWelcomePageEnabled()) {
  275. $("#videoconference_page").hide();
  276. if (!setupWelcomePage)
  277. setupWelcomePage = require("./welcome_page/WelcomePage");
  278. setupWelcomePage();
  279. // Return false to indicate that the UI hasn't been fully started and
  280. // conference ready. We're still waiting for input from the user.
  281. return false;
  282. }
  283. $("#welcome_page").hide();
  284. // Set the defaults for prompt dialogs.
  285. $.prompt.setDefaults({persistent: false});
  286. registerListeners();
  287. BottomToolbar.init();
  288. FilmStrip.init();
  289. VideoLayout.init(eventEmitter);
  290. if (!interfaceConfig.filmStripOnly) {
  291. VideoLayout.initLargeVideo(PanelToggler.isVisible());
  292. }
  293. VideoLayout.resizeVideoArea(PanelToggler.isVisible(), true, true);
  294. ContactList.init(eventEmitter);
  295. bindEvents();
  296. sharedVideoManager = new SharedVideoManager(eventEmitter);
  297. if (!interfaceConfig.filmStripOnly) {
  298. $("#videospace").mousemove(function () {
  299. return ToolbarToggler.showToolbar();
  300. });
  301. setupToolbars();
  302. setupChat();
  303. // Display notice message at the top of the toolbar
  304. if (config.noticeMessage) {
  305. $('#noticeText').text(config.noticeMessage);
  306. $('#notice').css({display: 'block'});
  307. }
  308. $("#downloadlog").click(function (event) {
  309. let logs = APP.conference.getLogs();
  310. let data = encodeURIComponent(JSON.stringify(logs, null, ' '));
  311. let elem = event.target.parentNode;
  312. elem.download = 'meetlog.json';
  313. elem.href = 'data:application/json;charset=utf-8,\n' + data;
  314. });
  315. } else {
  316. $("#header").css("display", "none");
  317. $("#downloadlog").css("display", "none");
  318. BottomToolbar.hide();
  319. FilmStrip.setupFilmStripOnly();
  320. messageHandler.disableNotifications();
  321. $('body').popover("disable");
  322. JitsiPopover.enabled = false;
  323. }
  324. document.title = interfaceConfig.APP_NAME;
  325. if(config.requireDisplayName) {
  326. if (!APP.settings.getDisplayName()) {
  327. promptDisplayName();
  328. }
  329. }
  330. if (!interfaceConfig.filmStripOnly) {
  331. toastr.options = {
  332. "closeButton": true,
  333. "debug": false,
  334. "positionClass": "notification-bottom-right",
  335. "onclick": null,
  336. "showDuration": "300",
  337. "hideDuration": "1000",
  338. "timeOut": "2000",
  339. "extendedTimeOut": "1000",
  340. "showEasing": "swing",
  341. "hideEasing": "linear",
  342. "showMethod": "fadeIn",
  343. "hideMethod": "fadeOut",
  344. "reposition": function () {
  345. if (PanelToggler.isVisible()) {
  346. $("#toast-container").addClass("notification-bottom-right-center");
  347. } else {
  348. $("#toast-container").removeClass("notification-bottom-right-center");
  349. }
  350. },
  351. "newestOnTop": false
  352. };
  353. SettingsMenu.init(eventEmitter);
  354. }
  355. // Return true to indicate that the UI has been fully started and
  356. // conference ready.
  357. return true;
  358. };
  359. /**
  360. * Show local stream on UI.
  361. * @param {JitsiTrack} track stream to show
  362. */
  363. UI.addLocalStream = function (track) {
  364. switch (track.getType()) {
  365. case 'audio':
  366. VideoLayout.changeLocalAudio(track);
  367. break;
  368. case 'video':
  369. VideoLayout.changeLocalVideo(track);
  370. break;
  371. default:
  372. console.error("Unknown stream type: " + track.getType());
  373. break;
  374. }
  375. };
  376. /**
  377. * Show remote stream on UI.
  378. * @param {JitsiTrack} track stream to show
  379. */
  380. UI.addRemoteStream = function (track) {
  381. VideoLayout.onRemoteStreamAdded(track);
  382. };
  383. /**
  384. * Removed remote stream from UI.
  385. * @param {JitsiTrack} track stream to remove
  386. */
  387. UI.removeRemoteStream = function (track) {
  388. VideoLayout.onRemoteStreamRemoved(track);
  389. };
  390. function chatAddError(errorMessage, originalText) {
  391. return Chat.chatAddError(errorMessage, originalText);
  392. }
  393. /**
  394. * Update chat subject.
  395. * @param {string} subject new chat subject
  396. */
  397. UI.setSubject = function (subject) {
  398. Chat.setSubject(subject);
  399. };
  400. /**
  401. * Setup and show Etherpad.
  402. * @param {string} name etherpad id
  403. */
  404. UI.initEtherpad = function (name) {
  405. if (etherpadManager || !config.etherpad_base || !name) {
  406. return;
  407. }
  408. console.log('Etherpad is enabled');
  409. etherpadManager = new EtherpadManager(config.etherpad_base, name);
  410. Toolbar.showEtherpadButton();
  411. };
  412. /**
  413. * Show user on UI.
  414. * @param {string} id user id
  415. * @param {string} displayName user nickname
  416. */
  417. UI.addUser = function (id, displayName) {
  418. ContactList.addContact(id);
  419. messageHandler.notify(
  420. displayName,'notify.somebody', 'connected', 'notify.connected'
  421. );
  422. if (!config.startAudioMuted ||
  423. config.startAudioMuted > APP.conference.membersCount)
  424. UIUtil.playSoundNotification('userJoined');
  425. // Add Peer's container
  426. VideoLayout.addParticipantContainer(id);
  427. // Configure avatar
  428. UI.setUserAvatar(id);
  429. };
  430. /**
  431. * Remove user from UI.
  432. * @param {string} id user id
  433. * @param {string} displayName user nickname
  434. */
  435. UI.removeUser = function (id, displayName) {
  436. ContactList.removeContact(id);
  437. messageHandler.notify(
  438. displayName,'notify.somebody', 'disconnected', 'notify.disconnected'
  439. );
  440. if (!config.startAudioMuted
  441. || config.startAudioMuted > APP.conference.membersCount) {
  442. UIUtil.playSoundNotification('userLeft');
  443. }
  444. VideoLayout.removeParticipantContainer(id);
  445. };
  446. UI.updateUserStatus = function (id, status) {
  447. VideoLayout.setPresenceStatus(id, status);
  448. };
  449. /**
  450. * Update videotype for specified user.
  451. * @param {string} id user id
  452. * @param {string} newVideoType new videotype
  453. */
  454. UI.onPeerVideoTypeChanged = (id, newVideoType) => {
  455. VideoLayout.onVideoTypeChanged(id, newVideoType);
  456. };
  457. /**
  458. * Update local user role and show notification if user is moderator.
  459. * @param {boolean} isModerator if local user is moderator or not
  460. */
  461. UI.updateLocalRole = function (isModerator) {
  462. VideoLayout.showModeratorIndicator();
  463. Toolbar.showSipCallButton(isModerator);
  464. Toolbar.showRecordingButton(isModerator);
  465. Toolbar.showSharedVideoButton(isModerator);
  466. SettingsMenu.showStartMutedOptions(isModerator);
  467. if (isModerator) {
  468. messageHandler.notify(null, "notify.me", 'connected', "notify.moderator");
  469. Toolbar.checkAutoRecord();
  470. }
  471. };
  472. /**
  473. * Check the role for the user and reflect it in the UI, moderator ui indication
  474. * and notifies user who is the moderator
  475. * @param user to check for moderator
  476. */
  477. UI.updateUserRole = function (user) {
  478. VideoLayout.showModeratorIndicator();
  479. if (!user.isModerator()) {
  480. return;
  481. }
  482. var displayName = user.getDisplayName();
  483. if (displayName) {
  484. messageHandler.notify(
  485. displayName, 'notify.somebody',
  486. 'connected', 'notify.grantedTo', {
  487. to: UIUtil.escapeHtml(displayName)
  488. }
  489. );
  490. } else {
  491. messageHandler.notify(
  492. '', 'notify.somebody',
  493. 'connected', 'notify.grantedToUnknown', {}
  494. );
  495. }
  496. };
  497. /**
  498. * Toggles smileys in the chat.
  499. */
  500. UI.toggleSmileys = function () {
  501. Chat.toggleSmileys();
  502. };
  503. /**
  504. * Toggles film strip.
  505. */
  506. UI.toggleFilmStrip = function () {
  507. FilmStrip.toggleFilmStrip();
  508. };
  509. /**
  510. * Toggles chat panel.
  511. */
  512. UI.toggleChat = function () {
  513. PanelToggler.toggleChat();
  514. };
  515. /**
  516. * Toggles contact list panel.
  517. */
  518. UI.toggleContactList = function () {
  519. PanelToggler.toggleContactList();
  520. };
  521. /**
  522. * Handle new user display name.
  523. */
  524. UI.inputDisplayNameHandler = function (newDisplayName) {
  525. eventEmitter.emit(UIEvents.NICKNAME_CHANGED, newDisplayName);
  526. };
  527. /**
  528. * Return the type of the remote video.
  529. * @param jid the jid for the remote video
  530. * @returns the video type video or screen.
  531. */
  532. UI.getRemoteVideoType = function (jid) {
  533. return VideoLayout.getRemoteVideoType(jid);
  534. };
  535. UI.connectionIndicatorShowMore = function(id) {
  536. VideoLayout.showMore(id);
  537. };
  538. // FIXME check if someone user this
  539. UI.showLoginPopup = function(callback) {
  540. console.log('password is required');
  541. var message = '<h2 data-i18n="dialog.passwordRequired">';
  542. message += APP.translation.translateString(
  543. "dialog.passwordRequired");
  544. message += '</h2>' +
  545. '<input name="username" type="text" ' +
  546. 'placeholder="user@domain.net" autofocus>' +
  547. '<input name="password" ' +
  548. 'type="password" data-i18n="[placeholder]dialog.userPassword"' +
  549. ' placeholder="user password">';
  550. messageHandler.openTwoButtonDialog(null, null, null, message,
  551. true,
  552. "dialog.Ok",
  553. function (e, v, m, f) {
  554. if (v) {
  555. if (f.username && f.password) {
  556. callback(f.username, f.password);
  557. }
  558. }
  559. },
  560. null, null, ':input:first'
  561. );
  562. };
  563. UI.askForNickname = function () {
  564. return window.prompt('Your nickname (optional)');
  565. };
  566. /**
  567. * Sets muted audio state for participant
  568. */
  569. UI.setAudioMuted = function (id, muted) {
  570. VideoLayout.onAudioMute(id, muted);
  571. if (APP.conference.isLocalId(id)) {
  572. Toolbar.markAudioIconAsMuted(muted);
  573. }
  574. };
  575. /**
  576. * Sets muted video state for participant
  577. */
  578. UI.setVideoMuted = function (id, muted) {
  579. VideoLayout.onVideoMute(id, muted);
  580. if (APP.conference.isLocalId(id)) {
  581. Toolbar.markVideoIconAsMuted(muted);
  582. }
  583. };
  584. UI.addListener = function (type, listener) {
  585. eventEmitter.on(type, listener);
  586. };
  587. UI.clickOnVideo = function (videoNumber) {
  588. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  589. if (remoteVideos.length > videoNumber) {
  590. remoteVideos[videoNumber].click();
  591. }
  592. };
  593. //Used by torture
  594. UI.showToolbar = function () {
  595. return ToolbarToggler.showToolbar();
  596. };
  597. //Used by torture
  598. UI.dockToolbar = function (isDock) {
  599. ToolbarToggler.dockToolbar(isDock);
  600. };
  601. /**
  602. * Update user avatar.
  603. * @param {string} id user id
  604. * @param {stirng} email user email
  605. */
  606. UI.setUserAvatar = function (id, email) {
  607. // update avatar
  608. Avatar.setUserAvatar(id, email);
  609. var avatarUrl = Avatar.getAvatarUrl(id);
  610. VideoLayout.changeUserAvatar(id, avatarUrl);
  611. ContactList.changeUserAvatar(id, avatarUrl);
  612. if (APP.conference.isLocalId(id)) {
  613. SettingsMenu.changeAvatar(avatarUrl);
  614. }
  615. };
  616. /**
  617. * Notify user that connection failed.
  618. * @param {string} stropheErrorMsg raw Strophe error message
  619. */
  620. UI.notifyConnectionFailed = function (stropheErrorMsg) {
  621. var title = APP.translation.generateTranslationHTML(
  622. "dialog.error");
  623. var message;
  624. if (stropheErrorMsg) {
  625. message = APP.translation.generateTranslationHTML(
  626. "dialog.connectErrorWithMsg", {msg: stropheErrorMsg});
  627. } else {
  628. message = APP.translation.generateTranslationHTML(
  629. "dialog.connectError");
  630. }
  631. messageHandler.openDialog(
  632. title, message, true, {}, function (e, v, m, f) { return false; }
  633. );
  634. };
  635. /**
  636. * Notify user that maximum users limit has been reached.
  637. */
  638. UI.notifyMaxUsersLimitReached = function () {
  639. var title = APP.translation.generateTranslationHTML(
  640. "dialog.error");
  641. var message = APP.translation.generateTranslationHTML(
  642. "dialog.maxUsersLimitReached");
  643. messageHandler.openDialog(
  644. title, message, true, {}, function (e, v, m, f) { return false; }
  645. );
  646. };
  647. /**
  648. * Notify user that he was automatically muted when joned the conference.
  649. */
  650. UI.notifyInitiallyMuted = function () {
  651. messageHandler.notify(
  652. null, "notify.mutedTitle", "connected", "notify.muted", null, {timeOut: 120000}
  653. );
  654. };
  655. /**
  656. * Mark user as dominant speaker.
  657. * @param {string} id user id
  658. */
  659. UI.markDominantSpeaker = function (id) {
  660. VideoLayout.onDominantSpeakerChanged(id);
  661. };
  662. UI.handleLastNEndpoints = function (ids, enteringIds) {
  663. VideoLayout.onLastNEndpointsChanged(ids, enteringIds);
  664. };
  665. /**
  666. * Update audio level visualization for specified user.
  667. * @param {string} id user id
  668. * @param {number} lvl audio level
  669. */
  670. UI.setAudioLevel = function (id, lvl) {
  671. VideoLayout.setAudioLevel(id, lvl);
  672. };
  673. /**
  674. * Update state of desktop sharing buttons.
  675. */
  676. UI.updateDesktopSharingButtons = function () {
  677. Toolbar.updateDesktopSharingButtonState();
  678. };
  679. /**
  680. * Hide connection quality statistics from UI.
  681. */
  682. UI.hideStats = function () {
  683. VideoLayout.hideStats();
  684. };
  685. /**
  686. * Update local connection quality statistics.
  687. * @param {number} percent
  688. * @param {object} stats
  689. */
  690. UI.updateLocalStats = function (percent, stats) {
  691. VideoLayout.updateLocalConnectionStats(percent, stats);
  692. };
  693. /**
  694. * Update connection quality statistics for remote user.
  695. * @param {string} id user id
  696. * @param {number} percent
  697. * @param {object} stats
  698. */
  699. UI.updateRemoteStats = function (id, percent, stats) {
  700. VideoLayout.updateConnectionStats(id, percent, stats);
  701. };
  702. /**
  703. * Mark video as interrupted or not.
  704. * @param {boolean} interrupted if video is interrupted
  705. */
  706. UI.markVideoInterrupted = function (interrupted) {
  707. if (interrupted) {
  708. VideoLayout.onVideoInterrupted();
  709. } else {
  710. VideoLayout.onVideoRestored();
  711. }
  712. };
  713. /**
  714. * Mark room as locked or not.
  715. * @param {boolean} locked if room is locked.
  716. */
  717. UI.markRoomLocked = function (locked) {
  718. if (locked) {
  719. Toolbar.lockLockButton();
  720. } else {
  721. Toolbar.unlockLockButton();
  722. }
  723. };
  724. /**
  725. * Add chat message.
  726. * @param {string} from user id
  727. * @param {string} displayName user nickname
  728. * @param {string} message message text
  729. * @param {number} stamp timestamp when message was created
  730. */
  731. UI.addMessage = function (from, displayName, message, stamp) {
  732. Chat.updateChatConversation(from, displayName, message, stamp);
  733. };
  734. UI.updateDTMFSupport = function (isDTMFSupported) {
  735. //TODO: enable when the UI is ready
  736. //Toolbar.showDialPadButton(dtmfSupport);
  737. };
  738. /**
  739. * Invite participants to conference.
  740. * @param {string} roomUrl
  741. * @param {string} conferenceName
  742. * @param {string} key
  743. * @param {string} nick
  744. */
  745. UI.inviteParticipants = function (roomUrl, conferenceName, key, nick) {
  746. let keyText = "";
  747. if (key) {
  748. keyText = APP.translation.translateString(
  749. "email.sharedKey", {sharedKey: key}
  750. );
  751. }
  752. let and = APP.translation.translateString("email.and");
  753. let supportedBrowsers = `Chromium, Google Chrome ${and} Opera`;
  754. let subject = APP.translation.translateString(
  755. "email.subject", {appName:interfaceConfig.APP_NAME, conferenceName}
  756. );
  757. let body = APP.translation.translateString(
  758. "email.body", {
  759. appName:interfaceConfig.APP_NAME,
  760. sharedKeyText: keyText,
  761. roomUrl,
  762. supportedBrowsers
  763. }
  764. );
  765. body = body.replace(/\n/g, "%0D%0A");
  766. if (nick) {
  767. body += "%0D%0A%0D%0A" + UIUtil.escapeHtml(nick);
  768. }
  769. if (interfaceConfig.INVITATION_POWERED_BY) {
  770. body += "%0D%0A%0D%0A--%0D%0Apowered by jitsi.org";
  771. }
  772. window.open(`mailto:?subject=${subject}&body=${body}`, '_blank');
  773. };
  774. /**
  775. * Show user feedback dialog if its required or just show "thank you" dialog.
  776. * @returns {Promise} when dialog is closed.
  777. */
  778. UI.requestFeedback = function () {
  779. return new Promise(function (resolve, reject) {
  780. if (Feedback.isEnabled()) {
  781. // If the user has already entered feedback, we'll show the window and
  782. // immidiately start the conference dispose timeout.
  783. if (Feedback.feedbackScore > 0) {
  784. Feedback.openFeedbackWindow();
  785. resolve();
  786. } else { // Otherwise we'll wait for user's feedback.
  787. Feedback.openFeedbackWindow(resolve);
  788. }
  789. } else {
  790. // If the feedback functionality isn't enabled we show a thank you
  791. // dialog.
  792. messageHandler.openMessageDialog(
  793. null, null, null,
  794. APP.translation.translateString(
  795. "dialog.thankYou", {appName:interfaceConfig.APP_NAME}
  796. )
  797. );
  798. resolve();
  799. }
  800. });
  801. };
  802. /**
  803. * Request recording token from the user.
  804. * @returns {Promise}
  805. */
  806. UI.requestRecordingToken = function () {
  807. let msg = APP.translation.generateTranslationHTML("dialog.recordingToken");
  808. let token = APP.translation.translateString("dialog.token");
  809. return new Promise(function (resolve, reject) {
  810. messageHandler.openTwoButtonDialog(
  811. null, null, null,
  812. `<h2>${msg}</h2>
  813. <input name="recordingToken" type="text"
  814. data-i18n="[placeholder]dialog.token"
  815. placeholder="${token}" autofocus>`,
  816. false, "dialog.Save",
  817. function (e, v, m, f) {
  818. if (v && f.recordingToken) {
  819. resolve(UIUtil.escapeHtml(f.recordingToken));
  820. } else {
  821. reject();
  822. }
  823. },
  824. null,
  825. function () { },
  826. ':input:first'
  827. );
  828. });
  829. };
  830. UI.updateRecordingState = function (state) {
  831. Toolbar.updateRecordingState(state);
  832. };
  833. UI.notifyTokenAuthFailed = function () {
  834. messageHandler.showError("dialog.error", "dialog.tokenAuthFailed");
  835. };
  836. UI.notifyInternalError = function () {
  837. messageHandler.showError("dialog.sorry", "dialog.internalError");
  838. };
  839. UI.notifyFocusDisconnected = function (focus, retrySec) {
  840. messageHandler.notify(
  841. null, "notify.focus",
  842. 'disconnected', "notify.focusFail",
  843. {component: focus, ms: retrySec}
  844. );
  845. };
  846. /**
  847. * Notify user that focus left the conference so page should be reloaded.
  848. */
  849. UI.notifyFocusLeft = function () {
  850. let title = APP.translation.generateTranslationHTML(
  851. 'dialog.serviceUnavailable'
  852. );
  853. let msg = APP.translation.generateTranslationHTML(
  854. 'dialog.jicofoUnavailable'
  855. );
  856. messageHandler.openDialog(
  857. title,
  858. msg,
  859. true, // persistent
  860. [{title: 'retry'}],
  861. function () {
  862. reload();
  863. return false;
  864. }
  865. );
  866. };
  867. /**
  868. * Updates auth info on the UI.
  869. * @param {boolean} isAuthEnabled if authentication is enabled
  870. * @param {string} [login] current login
  871. */
  872. UI.updateAuthInfo = function (isAuthEnabled, login) {
  873. let loggedIn = !!login;
  874. Toolbar.showAuthenticateButton(isAuthEnabled);
  875. if (isAuthEnabled) {
  876. Toolbar.setAuthenticatedIdentity(login);
  877. Toolbar.showLoginButton(!loggedIn);
  878. Toolbar.showLogoutButton(loggedIn);
  879. }
  880. };
  881. UI.onStartMutedChanged = function (startAudioMuted, startVideoMuted) {
  882. SettingsMenu.updateStartMutedBox(startAudioMuted, startVideoMuted);
  883. };
  884. /**
  885. * Update list of available physical devices.
  886. * @param {object[]} devices new list of available devices
  887. */
  888. UI.onAvailableDevicesChanged = function (devices) {
  889. SettingsMenu.changeDevicesList(devices);
  890. };
  891. /**
  892. * Returns the id of the current video shown on large.
  893. * Currently used by tests (torture).
  894. */
  895. UI.getLargeVideoID = function () {
  896. return VideoLayout.getLargeVideoID();
  897. };
  898. /**
  899. * Returns the current video shown on large.
  900. * Currently used by tests (torture).
  901. */
  902. UI.getLargeVideo = function () {
  903. return VideoLayout.getLargeVideo();
  904. };
  905. /**
  906. * Shows dialog with a link to FF extension.
  907. */
  908. UI.showExtensionRequiredDialog = function (url) {
  909. messageHandler.openMessageDialog(
  910. "dialog.extensionRequired",
  911. null,
  912. null,
  913. APP.translation.generateTranslationHTML(
  914. "dialog.firefoxExtensionPrompt", {url: url}));
  915. };
  916. UI.updateDevicesAvailability = function (id, devices) {
  917. VideoLayout.setDeviceAvailabilityIcons(id, devices);
  918. };
  919. /**
  920. * Show shared video.
  921. * @param {string} url video url
  922. * @param {string} attributes
  923. */
  924. UI.showSharedVideo = function (url, attributes) {
  925. if (sharedVideoManager)
  926. sharedVideoManager.showSharedVideo(url, attributes);
  927. };
  928. /**
  929. * Update shared video.
  930. * @param {string} url video url
  931. * @param {string} attributes
  932. */
  933. UI.updateSharedVideo = function (url, attributes) {
  934. if (sharedVideoManager)
  935. sharedVideoManager.updateSharedVideo(url, attributes);
  936. };
  937. /**
  938. * Stop showing shared video.
  939. * @param {string} attributes
  940. */
  941. UI.stopSharedVideo = function (attributes) {
  942. if (sharedVideoManager)
  943. sharedVideoManager.stopSharedVideo(attributes);
  944. };
  945. module.exports = UI;