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

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