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

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