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

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