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

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