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

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