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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534
  1. /* global APP, JitsiMeetJS, $, config, interfaceConfig, toastr */
  2. var UI = {};
  3. import Chat from "./side_pannels/chat/Chat";
  4. import Toolbar from "./toolbars/Toolbar";
  5. import ToolbarToggler from "./toolbars/ToolbarToggler";
  6. import Avatar from "./avatar/Avatar";
  7. import SideContainerToggler from "./side_pannels/SideContainerToggler";
  8. import UIUtil from "./util/UIUtil";
  9. import UIEvents from "../../service/UI/UIEvents";
  10. import EtherpadManager from './etherpad/Etherpad';
  11. import SharedVideoManager from './shared_video/SharedVideo';
  12. import Recording from "./recording/Recording";
  13. import GumPermissionsOverlay
  14. from './gum_overlay/UserMediaPermissionsGuidanceOverlay';
  15. import VideoLayout from "./videolayout/VideoLayout";
  16. import FilmStrip from "./videolayout/FilmStrip";
  17. import SettingsMenu from "./side_pannels/settings/SettingsMenu";
  18. import Profile from "./side_pannels/profile/Profile";
  19. import Settings from "./../settings/Settings";
  20. import { reload } from '../util/helpers';
  21. import RingOverlay from "./ring_overlay/RingOverlay";
  22. import UIErrors from './UIErrors';
  23. var EventEmitter = require("events");
  24. UI.messageHandler = require("./util/MessageHandler");
  25. var messageHandler = UI.messageHandler;
  26. var JitsiPopover = require("./util/JitsiPopover");
  27. var Feedback = require("./feedback/Feedback");
  28. import FollowMe from "../FollowMe";
  29. var eventEmitter = new EventEmitter();
  30. UI.eventEmitter = eventEmitter;
  31. let etherpadManager;
  32. let sharedVideoManager;
  33. let followMeHandler;
  34. let deviceErrorDialog;
  35. const TrackErrors = JitsiMeetJS.errors.track;
  36. const JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP = {
  37. microphone: {},
  38. camera: {}
  39. };
  40. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.UNSUPPORTED_RESOLUTION]
  41. = "dialog.cameraUnsupportedResolutionError";
  42. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.GENERAL]
  43. = "dialog.cameraUnknownError";
  44. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.PERMISSION_DENIED]
  45. = "dialog.cameraPermissionDeniedError";
  46. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.NOT_FOUND]
  47. = "dialog.cameraNotFoundError";
  48. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.CONSTRAINT_FAILED]
  49. = "dialog.cameraConstraintFailedError";
  50. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.NO_DATA_FROM_SOURCE]
  51. = "dialog.cameraNotSendingData";
  52. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.GENERAL]
  53. = "dialog.micUnknownError";
  54. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.PERMISSION_DENIED]
  55. = "dialog.micPermissionDeniedError";
  56. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.NOT_FOUND]
  57. = "dialog.micNotFoundError";
  58. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.CONSTRAINT_FAILED]
  59. = "dialog.micConstraintFailedError";
  60. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.NO_DATA_FROM_SOURCE]
  61. = "dialog.micNotSendingData";
  62. /**
  63. * Prompt user for nickname.
  64. */
  65. function promptDisplayName() {
  66. let nickRequiredMsg
  67. = APP.translation.translateString("dialog.displayNameRequired");
  68. let defaultNickMsg = APP.translation.translateString("defaultNickname");
  69. let message = `
  70. <h2 data-i18n="dialog.displayNameRequired">${nickRequiredMsg}</h2>
  71. <input name="displayName" type="text"
  72. data-i18n="[placeholder]defaultNickname"
  73. placeholder="${defaultNickMsg}" autofocus>`;
  74. // Don't use a translation string, because we're too early in the call and
  75. // the translation may not be initialised.
  76. let buttons = {Ok:true};
  77. let dialog = messageHandler.openDialog(
  78. null,
  79. message,
  80. true,
  81. buttons,
  82. function (e, v, m, f) {
  83. e.preventDefault();
  84. if (v) {
  85. let displayName = f.displayName;
  86. if (displayName) {
  87. UI.inputDisplayNameHandler(displayName);
  88. dialog.close();
  89. return;
  90. }
  91. }
  92. },
  93. function () {
  94. let form = $.prompt.getPrompt();
  95. let input = form.find("input[name='displayName']");
  96. input.focus();
  97. let button = form.find("button");
  98. button.attr("disabled", "disabled");
  99. input.keyup(function () {
  100. if (input.val()) {
  101. button.removeAttr("disabled");
  102. } else {
  103. button.attr("disabled", "disabled");
  104. }
  105. });
  106. }
  107. );
  108. }
  109. /**
  110. * Initialize chat.
  111. */
  112. function setupChat() {
  113. Chat.init(eventEmitter);
  114. $("#toggle_smileys").click(function() {
  115. Chat.toggleSmileys();
  116. });
  117. }
  118. /**
  119. * Initialize toolbars.
  120. */
  121. function setupToolbars() {
  122. Toolbar.init(eventEmitter);
  123. }
  124. /**
  125. * Toggles the application in and out of full screen mode
  126. * (a.k.a. presentation mode in Chrome).
  127. * @see https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API
  128. */
  129. UI.toggleFullScreen = function() {
  130. // alternative standard method
  131. let isNotFullScreen = !document.fullscreenElement &&
  132. !document.mozFullScreenElement && // current working methods
  133. !document.webkitFullscreenElement &&
  134. !document.msFullscreenElement;
  135. if (isNotFullScreen) {
  136. if (document.documentElement.requestFullscreen) {
  137. document.documentElement.requestFullscreen();
  138. } else if (document.documentElement.msRequestFullscreen) {
  139. document.documentElement.msRequestFullscreen();
  140. } else if (document.documentElement.mozRequestFullScreen) {
  141. document.documentElement.mozRequestFullScreen();
  142. } else if (document.documentElement.webkitRequestFullscreen) {
  143. document.documentElement
  144. .webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  145. }
  146. } else {
  147. if (document.exitFullscreen) {
  148. document.exitFullscreen();
  149. } else if (document.msExitFullscreen) {
  150. document.msExitFullscreen();
  151. } else if (document.mozCancelFullScreen) {
  152. document.mozCancelFullScreen();
  153. } else if (document.webkitExitFullscreen) {
  154. document.webkitExitFullscreen();
  155. }
  156. }
  157. };
  158. /**
  159. * Notify user that server has shut down.
  160. */
  161. UI.notifyGracefulShutdown = function () {
  162. messageHandler.openMessageDialog(
  163. 'dialog.serviceUnavailable',
  164. 'dialog.gracefulShutdown'
  165. );
  166. };
  167. /**
  168. * Notify user that reservation error happened.
  169. */
  170. UI.notifyReservationError = function (code, msg) {
  171. var title = APP.translation.generateTranslationHTML(
  172. "dialog.reservationError");
  173. var message = APP.translation.generateTranslationHTML(
  174. "dialog.reservationErrorMsg", {code: code, msg: msg});
  175. messageHandler.openDialog(title, message, true, {}, () => false);
  176. };
  177. /**
  178. * Notify user that he has been kicked from the server.
  179. */
  180. UI.notifyKicked = function () {
  181. messageHandler.openMessageDialog(
  182. "dialog.sessTerminated",
  183. "dialog.kickMessage");
  184. };
  185. /**
  186. * Notify user that conference was destroyed.
  187. * @param reason {string} the reason text
  188. */
  189. UI.notifyConferenceDestroyed = function (reason) {
  190. //FIXME: use Session Terminated from translation, but
  191. // 'reason' text comes from XMPP packet and is not translated
  192. const title
  193. = APP.translation.generateTranslationHTML("dialog.sessTerminated");
  194. messageHandler.openDialog(title, reason, true, {}, () => false);
  195. };
  196. /**
  197. * Notify user that Jitsi Videobridge is not accessible.
  198. */
  199. UI.notifyBridgeDown = function () {
  200. messageHandler.showError("dialog.error", "dialog.bridgeUnavailable");
  201. };
  202. /**
  203. * Show chat error.
  204. * @param err the Error
  205. * @param msg
  206. */
  207. UI.showChatError = function (err, msg) {
  208. if (interfaceConfig.filmStripOnly) {
  209. return;
  210. }
  211. Chat.chatAddError(err, msg);
  212. };
  213. /**
  214. * Change nickname for the user.
  215. * @param {string} id user id
  216. * @param {string} displayName new nickname
  217. */
  218. UI.changeDisplayName = function (id, displayName) {
  219. UI.ContactList.onDisplayNameChange(id, displayName);
  220. VideoLayout.onDisplayNameChanged(id, displayName);
  221. if (APP.conference.isLocalId(id) || id === 'localVideoContainer') {
  222. Profile.changeDisplayName(displayName);
  223. Chat.setChatConversationMode(!!displayName);
  224. }
  225. };
  226. /**
  227. * Shows/hides the indication about local connection being interrupted.
  228. *
  229. * @param {boolean} isInterrupted <tt>true</tt> if local connection is
  230. * currently in the interrupted state or <tt>false</tt> if the connection
  231. * is fine.
  232. */
  233. UI.showLocalConnectionInterrupted = function (isInterrupted) {
  234. VideoLayout.showLocalConnectionInterrupted(isInterrupted);
  235. };
  236. /**
  237. * Sets the "raised hand" status for a participant.
  238. */
  239. UI.setRaisedHandStatus = (participant, raisedHandStatus) => {
  240. VideoLayout.setRaisedHandStatus(participant.getId(), raisedHandStatus);
  241. if (raisedHandStatus) {
  242. messageHandler.notify(participant.getDisplayName(), 'notify.somebody',
  243. 'connected', 'notify.raisedHand');
  244. }
  245. };
  246. /**
  247. * Sets the local "raised hand" status.
  248. */
  249. UI.setLocalRaisedHandStatus = (raisedHandStatus) => {
  250. VideoLayout.setRaisedHandStatus(
  251. APP.conference.getMyUserId(),
  252. raisedHandStatus);
  253. };
  254. /**
  255. * Initialize conference UI.
  256. */
  257. UI.initConference = function () {
  258. let id = APP.conference.getMyUserId();
  259. // Do not include query parameters in the invite URL
  260. // "https:" + "//" + "example.com:8888" + "/SomeConference1245"
  261. var inviteURL = window.location.protocol + "//" +
  262. window.location.host + window.location.pathname;
  263. this.emitEvent(UIEvents.INVITE_URL_INITIALISED, inviteURL);
  264. // Clean up the URL displayed by the browser
  265. if (window.history && typeof window.history.replaceState === 'function') {
  266. window.history.replaceState({}, document.title, inviteURL);
  267. }
  268. // Add myself to the contact list.
  269. UI.ContactList.addContact(id, true);
  270. // Update default button states before showing the toolbar
  271. // if local role changes buttons state will be again updated.
  272. UI.updateLocalRole(APP.conference.isModerator);
  273. UI.showToolbar();
  274. let displayName = config.displayJids ? id : Settings.getDisplayName();
  275. if (displayName) {
  276. UI.changeDisplayName('localVideoContainer', displayName);
  277. }
  278. // Make sure we configure our avatar id, before creating avatar for us
  279. let email = Settings.getEmail();
  280. if (email) {
  281. UI.setUserEmail(id, email);
  282. } else {
  283. UI.setUserAvatarID(id, Settings.getAvatarId());
  284. }
  285. Toolbar.checkAutoEnableDesktopSharing();
  286. if(!interfaceConfig.filmStripOnly) {
  287. Feedback.init(eventEmitter);
  288. }
  289. // FollowMe attempts to copy certain aspects of the moderator's UI into the
  290. // other participants' UI. Consequently, it needs (1) read and write access
  291. // to the UI (depending on the moderator role of the local participant) and
  292. // (2) APP.conference as means of communication between the participants.
  293. followMeHandler = new FollowMe(APP.conference, UI);
  294. UIUtil.activateTooltips();
  295. };
  296. UI.mucJoined = function () {
  297. VideoLayout.mucJoined();
  298. };
  299. /***
  300. * Handler for toggling filmstrip
  301. */
  302. UI.handleToggleFilmStrip = () => {
  303. UI.toggleFilmStrip();
  304. };
  305. /**
  306. * Sets tooltip defaults.
  307. *
  308. * @private
  309. */
  310. function _setTooltipDefaults() {
  311. $.fn.tooltip.defaults = {
  312. opacity: 1, //defaults to 1
  313. offset: 1,
  314. delayIn: 0, //defaults to 500
  315. hoverable: true,
  316. hideOnClick: true,
  317. aria: true
  318. };
  319. }
  320. /**
  321. * Setup some UI event listeners.
  322. */
  323. function registerListeners() {
  324. UI.addListener(UIEvents.ETHERPAD_CLICKED, function () {
  325. if (etherpadManager) {
  326. etherpadManager.toggleEtherpad();
  327. }
  328. });
  329. UI.addListener(UIEvents.SHARED_VIDEO_CLICKED, function () {
  330. if (sharedVideoManager) {
  331. sharedVideoManager.toggleSharedVideo();
  332. }
  333. });
  334. UI.addListener(UIEvents.FULLSCREEN_TOGGLE, UI.toggleFullScreen);
  335. UI.addListener(UIEvents.TOGGLE_CHAT, UI.toggleChat);
  336. UI.addListener(UIEvents.TOGGLE_SETTINGS, function () {
  337. UI.toggleSidePanel("settings_container");
  338. });
  339. UI.addListener(UIEvents.TOGGLE_CONTACT_LIST, UI.toggleContactList);
  340. UI.addListener( UIEvents.TOGGLE_PROFILE, function() {
  341. if(APP.tokenData.isGuest)
  342. UI.toggleSidePanel("profile_container");
  343. });
  344. UI.addListener(UIEvents.TOGGLE_FILM_STRIP, UI.handleToggleFilmStrip);
  345. UI.addListener(UIEvents.FOLLOW_ME_ENABLED, function (isEnabled) {
  346. if (followMeHandler)
  347. followMeHandler.enableFollowMe(isEnabled);
  348. });
  349. }
  350. /**
  351. * Setup some DOM event listeners.
  352. */
  353. function bindEvents() {
  354. function onResize() {
  355. SideContainerToggler.resize();
  356. VideoLayout.resizeVideoArea();
  357. }
  358. // Resize and reposition videos in full screen mode.
  359. $(document).on(
  360. 'webkitfullscreenchange mozfullscreenchange fullscreenchange',
  361. onResize
  362. );
  363. $(window).resize(onResize);
  364. }
  365. /**
  366. * Returns the shared document manager object.
  367. * @return {EtherpadManager} the shared document manager object
  368. */
  369. UI.getSharedVideoManager = function () {
  370. return sharedVideoManager;
  371. };
  372. /**
  373. * Starts the UI module and initializes all related components.
  374. *
  375. * @returns {boolean} true if the UI is ready and the conference should be
  376. * esablished, false - otherwise (for example in the case of welcome page)
  377. */
  378. UI.start = function () {
  379. document.title = interfaceConfig.APP_NAME;
  380. var setupWelcomePage = null;
  381. if(config.enableWelcomePage && window.location.pathname == "/" &&
  382. Settings.isWelcomePageEnabled()) {
  383. $("#videoconference_page").hide();
  384. if (!setupWelcomePage)
  385. setupWelcomePage = require("./welcome_page/WelcomePage");
  386. setupWelcomePage();
  387. // Return false to indicate that the UI hasn't been fully started and
  388. // conference ready. We're still waiting for input from the user.
  389. return false;
  390. }
  391. $("#welcome_page").hide();
  392. // Set the defaults for prompt dialogs.
  393. $.prompt.setDefaults({persistent: false});
  394. // Set the defaults for tooltips.
  395. _setTooltipDefaults();
  396. registerListeners();
  397. ToolbarToggler.init();
  398. SideContainerToggler.init(eventEmitter);
  399. FilmStrip.init(eventEmitter);
  400. VideoLayout.init(eventEmitter);
  401. if (!interfaceConfig.filmStripOnly) {
  402. VideoLayout.initLargeVideo();
  403. }
  404. VideoLayout.resizeVideoArea(true, true);
  405. bindEvents();
  406. sharedVideoManager = new SharedVideoManager(eventEmitter);
  407. if (!interfaceConfig.filmStripOnly) {
  408. $("#videoconference_page").mousemove(function () {
  409. return UI.showToolbar();
  410. });
  411. setupToolbars();
  412. setupChat();
  413. // Initialise the recording module.
  414. if (config.enableRecording)
  415. Recording.init(eventEmitter, config.recordingType);
  416. // Display notice message at the top of the toolbar
  417. if (config.noticeMessage) {
  418. $('#noticeText').text(config.noticeMessage);
  419. $('#notice').css({display: 'block'});
  420. }
  421. } else {
  422. $("#mainToolbarContainer").css("display", "none");
  423. FilmStrip.setupFilmStripOnly();
  424. messageHandler.enableNotifications(false);
  425. JitsiPopover.enabled = false;
  426. }
  427. document.title = interfaceConfig.APP_NAME;
  428. if(config.requireDisplayName) {
  429. if (!APP.settings.getDisplayName()) {
  430. promptDisplayName();
  431. }
  432. }
  433. if (!interfaceConfig.filmStripOnly) {
  434. toastr.options = {
  435. "closeButton": true,
  436. "debug": false,
  437. "positionClass": "notification-bottom-right",
  438. "onclick": null,
  439. "showDuration": "300",
  440. "hideDuration": "1000",
  441. "timeOut": "2000",
  442. "extendedTimeOut": "1000",
  443. "showEasing": "swing",
  444. "hideEasing": "linear",
  445. "showMethod": "fadeIn",
  446. "hideMethod": "fadeOut",
  447. "newestOnTop": false
  448. };
  449. SettingsMenu.init(eventEmitter);
  450. Profile.init(eventEmitter);
  451. }
  452. if(APP.tokenData.callee) {
  453. UI.showRingOverlay();
  454. }
  455. // Return true to indicate that the UI has been fully started and
  456. // conference ready.
  457. return true;
  458. };
  459. /**
  460. * Show local stream on UI.
  461. * @param {JitsiTrack} track stream to show
  462. */
  463. UI.addLocalStream = function (track) {
  464. switch (track.getType()) {
  465. case 'audio':
  466. VideoLayout.changeLocalAudio(track);
  467. break;
  468. case 'video':
  469. VideoLayout.changeLocalVideo(track);
  470. break;
  471. default:
  472. console.error("Unknown stream type: " + track.getType());
  473. break;
  474. }
  475. };
  476. /**
  477. * Show remote stream on UI.
  478. * @param {JitsiTrack} track stream to show
  479. */
  480. UI.addRemoteStream = function (track) {
  481. VideoLayout.onRemoteStreamAdded(track);
  482. };
  483. /**
  484. * Removed remote stream from UI.
  485. * @param {JitsiTrack} track stream to remove
  486. */
  487. UI.removeRemoteStream = function (track) {
  488. VideoLayout.onRemoteStreamRemoved(track);
  489. };
  490. /**
  491. * Update chat subject.
  492. * @param {string} subject new chat subject
  493. */
  494. UI.setSubject = function (subject) {
  495. Chat.setSubject(subject);
  496. };
  497. /**
  498. * Setup and show Etherpad.
  499. * @param {string} name etherpad id
  500. */
  501. UI.initEtherpad = function (name) {
  502. if (etherpadManager || !config.etherpad_base || !name) {
  503. return;
  504. }
  505. console.log('Etherpad is enabled');
  506. etherpadManager
  507. = new EtherpadManager(config.etherpad_base, name, eventEmitter);
  508. Toolbar.showEtherpadButton();
  509. };
  510. /**
  511. * Returns the shared document manager object.
  512. * @return {EtherpadManager} the shared document manager object
  513. */
  514. UI.getSharedDocumentManager = function () {
  515. return etherpadManager;
  516. };
  517. /**
  518. * Show user on UI.
  519. * @param {JitsiParticipant} user
  520. */
  521. UI.addUser = function (user) {
  522. var id = user.getId();
  523. var displayName = user.getDisplayName();
  524. UI.hideRingOverLay();
  525. UI.ContactList.addContact(id);
  526. messageHandler.notify(
  527. displayName,'notify.somebody', 'connected', 'notify.connected'
  528. );
  529. if (!config.startAudioMuted ||
  530. config.startAudioMuted > APP.conference.membersCount)
  531. UIUtil.playSoundNotification('userJoined');
  532. // Add Peer's container
  533. VideoLayout.addParticipantContainer(user);
  534. // Configure avatar
  535. UI.setUserEmail(id);
  536. // set initial display name
  537. if(displayName)
  538. UI.changeDisplayName(id, displayName);
  539. };
  540. /**
  541. * Remove user from UI.
  542. * @param {string} id user id
  543. * @param {string} displayName user nickname
  544. */
  545. UI.removeUser = function (id, displayName) {
  546. UI.ContactList.removeContact(id);
  547. messageHandler.notify(
  548. displayName,'notify.somebody', 'disconnected', 'notify.disconnected'
  549. );
  550. if (!config.startAudioMuted
  551. || config.startAudioMuted > APP.conference.membersCount) {
  552. UIUtil.playSoundNotification('userLeft');
  553. }
  554. VideoLayout.removeParticipantContainer(id);
  555. };
  556. UI.updateUserStatus = function (id, status) {
  557. VideoLayout.setPresenceStatus(id, status);
  558. };
  559. /**
  560. * Update videotype for specified user.
  561. * @param {string} id user id
  562. * @param {string} newVideoType new videotype
  563. */
  564. UI.onPeerVideoTypeChanged = (id, newVideoType) => {
  565. VideoLayout.onVideoTypeChanged(id, newVideoType);
  566. };
  567. /**
  568. * Update local user role and show notification if user is moderator.
  569. * @param {boolean} isModerator if local user is moderator or not
  570. */
  571. UI.updateLocalRole = function (isModerator) {
  572. VideoLayout.showModeratorIndicator();
  573. Toolbar.showSipCallButton(isModerator);
  574. Toolbar.showSharedVideoButton(isModerator);
  575. Recording.showRecordingButton(isModerator);
  576. SettingsMenu.showStartMutedOptions(isModerator);
  577. SettingsMenu.showFollowMeOptions(isModerator);
  578. if (isModerator) {
  579. if (!interfaceConfig.DISABLE_FOCUS_INDICATOR)
  580. messageHandler
  581. .notify(null, "notify.me", 'connected', "notify.moderator");
  582. Recording.checkAutoRecord();
  583. }
  584. };
  585. /**
  586. * Check the role for the user and reflect it in the UI, moderator ui indication
  587. * and notifies user who is the moderator
  588. * @param user to check for moderator
  589. */
  590. UI.updateUserRole = function (user) {
  591. VideoLayout.showModeratorIndicator();
  592. // We don't need to show moderator notifications when the focus (moderator)
  593. // indicator is disabled.
  594. if (!user.isModerator() || interfaceConfig.DISABLE_FOCUS_INDICATOR) {
  595. return;
  596. }
  597. var displayName = user.getDisplayName();
  598. if (displayName) {
  599. messageHandler.notify(
  600. displayName, 'notify.somebody',
  601. 'connected', 'notify.grantedTo', {
  602. to: UIUtil.escapeHtml(displayName)
  603. }
  604. );
  605. } else {
  606. messageHandler.notify(
  607. '', 'notify.somebody',
  608. 'connected', 'notify.grantedToUnknown', {}
  609. );
  610. }
  611. };
  612. /**
  613. * Toggles smileys in the chat.
  614. */
  615. UI.toggleSmileys = function () {
  616. Chat.toggleSmileys();
  617. };
  618. /**
  619. * Toggles film strip.
  620. */
  621. UI.toggleFilmStrip = function () {
  622. var self = FilmStrip;
  623. self.toggleFilmStrip.apply(self, arguments);
  624. VideoLayout.resizeVideoArea(true, false);
  625. };
  626. /**
  627. * Indicates if the film strip is currently visible or not.
  628. * @returns {true} if the film strip is currently visible, otherwise
  629. */
  630. UI.isFilmStripVisible = function () {
  631. return FilmStrip.isFilmStripVisible();
  632. };
  633. /**
  634. * Toggles chat panel.
  635. */
  636. UI.toggleChat = function () {
  637. UI.toggleSidePanel("chat_container");
  638. };
  639. /**
  640. * Toggles contact list panel.
  641. */
  642. UI.toggleContactList = function () {
  643. UI.toggleSidePanel("contacts_container");
  644. };
  645. /**
  646. * Toggles the given side panel.
  647. *
  648. * @param {String} sidePanelId the identifier of the side panel to toggle
  649. */
  650. UI.toggleSidePanel = function (sidePanelId) {
  651. SideContainerToggler.toggle(sidePanelId);
  652. };
  653. /**
  654. * Handle new user display name.
  655. */
  656. UI.inputDisplayNameHandler = function (newDisplayName) {
  657. eventEmitter.emit(UIEvents.NICKNAME_CHANGED, newDisplayName);
  658. };
  659. /**
  660. * Return the type of the remote video.
  661. * @param jid the jid for the remote video
  662. * @returns the video type video or screen.
  663. */
  664. UI.getRemoteVideoType = function (jid) {
  665. return VideoLayout.getRemoteVideoType(jid);
  666. };
  667. UI.connectionIndicatorShowMore = function(id) {
  668. VideoLayout.showMore(id);
  669. };
  670. // FIXME check if someone user this
  671. UI.showLoginPopup = function(callback) {
  672. console.log('password is required');
  673. let titleKey = "dialog.passwordRequired";
  674. let titleString = APP.translation.translateString(titleKey);
  675. let message = (
  676. `<input name="username" type="text"
  677. placeholder="user@domain.net" autofocus>
  678. <input name="password" type="password"
  679. data-i18n="[placeholder]dialog.userPassword"
  680. placeholder="user password">`
  681. );
  682. let submitFunction = (e, v, m, f) => {
  683. if (v) {
  684. if (f.username && f.password) {
  685. callback(f.username, f.password);
  686. }
  687. }
  688. };
  689. messageHandler.openTwoButtonDialog({
  690. titleKey,
  691. titleString,
  692. msgString: message,
  693. leftButtonKey: 'dialog.Ok',
  694. submitFunction,
  695. focus: ':input:first'
  696. });
  697. };
  698. UI.askForNickname = function () {
  699. return window.prompt('Your nickname (optional)');
  700. };
  701. /**
  702. * Sets muted audio state for participant
  703. */
  704. UI.setAudioMuted = function (id, muted) {
  705. VideoLayout.onAudioMute(id, muted);
  706. if (APP.conference.isLocalId(id)) {
  707. Toolbar.toggleAudioIcon(muted);
  708. }
  709. };
  710. /**
  711. * Sets muted video state for participant
  712. */
  713. UI.setVideoMuted = function (id, muted) {
  714. VideoLayout.onVideoMute(id, muted);
  715. if (APP.conference.isLocalId(id)) {
  716. Toolbar.toggleVideoIcon(muted);
  717. }
  718. };
  719. /**
  720. * Adds a listener that would be notified on the given type of event.
  721. *
  722. * @param type the type of the event we're listening for
  723. * @param listener a function that would be called when notified
  724. */
  725. UI.addListener = function (type, listener) {
  726. eventEmitter.on(type, listener);
  727. };
  728. /**
  729. * Removes the given listener for the given type of event.
  730. *
  731. * @param type the type of the event we're listening for
  732. * @param listener the listener we want to remove
  733. */
  734. UI.removeListener = function (type, listener) {
  735. eventEmitter.removeListener(type, listener);
  736. };
  737. /**
  738. * Emits the event of given type by specifying the parameters in options.
  739. *
  740. * @param type the type of the event we're emitting
  741. * @param options the parameters for the event
  742. */
  743. UI.emitEvent = function (type, options) {
  744. eventEmitter.emit(type, options);
  745. };
  746. UI.clickOnVideo = function (videoNumber) {
  747. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  748. if (remoteVideos.length > videoNumber) {
  749. remoteVideos[videoNumber].click();
  750. }
  751. };
  752. //Used by torture
  753. UI.showToolbar = function (timeout) {
  754. return ToolbarToggler.showToolbar(timeout);
  755. };
  756. //Used by torture
  757. UI.dockToolbar = function (isDock) {
  758. ToolbarToggler.dockToolbar(isDock);
  759. };
  760. /**
  761. * Updates the avatar for participant.
  762. * @param {string} id user id
  763. * @param {string} avatarUrl the URL for the avatar
  764. */
  765. function changeAvatar(id, avatarUrl) {
  766. VideoLayout.changeUserAvatar(id, avatarUrl);
  767. UI.ContactList.changeUserAvatar(id, avatarUrl);
  768. if (APP.conference.isLocalId(id)) {
  769. Profile.changeAvatar(avatarUrl);
  770. }
  771. }
  772. /**
  773. * Update user email.
  774. * @param {string} id user id
  775. * @param {string} email user email
  776. */
  777. UI.setUserEmail = function (id, email) {
  778. // update avatar
  779. Avatar.setUserEmail(id, email);
  780. changeAvatar(id, Avatar.getAvatarUrl(id));
  781. };
  782. /**
  783. * Update user avtar id.
  784. * @param {string} id user id
  785. * @param {string} avatarId user's avatar id
  786. */
  787. UI.setUserAvatarID = function (id, avatarId) {
  788. // update avatar
  789. Avatar.setUserAvatarID(id, avatarId);
  790. changeAvatar(id, Avatar.getAvatarUrl(id));
  791. };
  792. /**
  793. * Update user avatar URL.
  794. * @param {string} id user id
  795. * @param {string} url user avatar url
  796. */
  797. UI.setUserAvatarUrl = function (id, url) {
  798. // update avatar
  799. Avatar.setUserAvatarUrl(id, url);
  800. changeAvatar(id, Avatar.getAvatarUrl(id));
  801. };
  802. /**
  803. * Notify user that connection failed.
  804. * @param {string} stropheErrorMsg raw Strophe error message
  805. */
  806. UI.notifyConnectionFailed = function (stropheErrorMsg) {
  807. var title = APP.translation.generateTranslationHTML(
  808. "dialog.error");
  809. var message;
  810. if (stropheErrorMsg) {
  811. message = APP.translation.generateTranslationHTML(
  812. "dialog.connectErrorWithMsg", {msg: stropheErrorMsg});
  813. } else {
  814. message = APP.translation.generateTranslationHTML(
  815. "dialog.connectError");
  816. }
  817. messageHandler.openDialog(title, message, true, {}, () => false);
  818. };
  819. /**
  820. * Notify user that maximum users limit has been reached.
  821. */
  822. UI.notifyMaxUsersLimitReached = function () {
  823. var title = APP.translation.generateTranslationHTML(
  824. "dialog.error");
  825. var message = APP.translation.generateTranslationHTML(
  826. "dialog.maxUsersLimitReached");
  827. messageHandler.openDialog(title, message, true, {}, () => false);
  828. };
  829. /**
  830. * Notify user that he was automatically muted when joned the conference.
  831. */
  832. UI.notifyInitiallyMuted = function () {
  833. messageHandler.notify(
  834. null,
  835. "notify.mutedTitle",
  836. "connected",
  837. "notify.muted",
  838. null,
  839. { timeOut: 120000 });
  840. };
  841. /**
  842. * Mark user as dominant speaker.
  843. * @param {string} id user id
  844. */
  845. UI.markDominantSpeaker = function (id) {
  846. VideoLayout.onDominantSpeakerChanged(id);
  847. };
  848. UI.handleLastNEndpoints = function (ids, enteringIds) {
  849. VideoLayout.onLastNEndpointsChanged(ids, enteringIds);
  850. };
  851. /**
  852. * Will handle notification about participant's connectivity status change.
  853. *
  854. * @param {string} id the id of remote participant(MUC jid)
  855. * @param {boolean} isActive true if the connection is ok or false if the user
  856. * is having connectivity issues.
  857. */
  858. UI.participantConnectionStatusChanged = function (id, isActive) {
  859. VideoLayout.onParticipantConnectionStatusChanged(id, isActive);
  860. };
  861. /**
  862. * Update audio level visualization for specified user.
  863. * @param {string} id user id
  864. * @param {number} lvl audio level
  865. */
  866. UI.setAudioLevel = function (id, lvl) {
  867. VideoLayout.setAudioLevel(id, lvl);
  868. };
  869. /**
  870. * Update state of desktop sharing buttons.
  871. */
  872. UI.updateDesktopSharingButtons = function () {
  873. Toolbar.updateDesktopSharingButtonState();
  874. };
  875. /**
  876. * Hide connection quality statistics from UI.
  877. */
  878. UI.hideStats = function () {
  879. VideoLayout.hideStats();
  880. };
  881. /**
  882. * Update local connection quality statistics.
  883. * @param {number} percent
  884. * @param {object} stats
  885. */
  886. UI.updateLocalStats = function (percent, stats) {
  887. VideoLayout.updateLocalConnectionStats(percent, stats);
  888. };
  889. /**
  890. * Update connection quality statistics for remote user.
  891. * @param {string} id user id
  892. * @param {number} percent
  893. * @param {object} stats
  894. */
  895. UI.updateRemoteStats = function (id, percent, stats) {
  896. VideoLayout.updateConnectionStats(id, percent, stats);
  897. };
  898. /**
  899. * Mark video as interrupted or not.
  900. * @param {boolean} interrupted if video is interrupted
  901. */
  902. UI.markVideoInterrupted = function (interrupted) {
  903. if (interrupted) {
  904. VideoLayout.onVideoInterrupted();
  905. } else {
  906. VideoLayout.onVideoRestored();
  907. }
  908. };
  909. /**
  910. * Add chat message.
  911. * @param {string} from user id
  912. * @param {string} displayName user nickname
  913. * @param {string} message message text
  914. * @param {number} stamp timestamp when message was created
  915. */
  916. UI.addMessage = function (from, displayName, message, stamp) {
  917. Chat.updateChatConversation(from, displayName, message, stamp);
  918. };
  919. // eslint-disable-next-line no-unused-vars
  920. UI.updateDTMFSupport = function (isDTMFSupported) {
  921. //TODO: enable when the UI is ready
  922. //Toolbar.showDialPadButton(dtmfSupport);
  923. };
  924. /**
  925. * Show user feedback dialog if its required or just show "thank you" dialog.
  926. * @returns {Promise} when dialog is closed.
  927. */
  928. UI.requestFeedback = function () {
  929. if (Feedback.isVisible())
  930. return Promise.reject(UIErrors.FEEDBACK_REQUEST_IN_PROGRESS);
  931. // Feedback has been submitted already.
  932. else if (Feedback.isEnabled() && Feedback.isSubmitted())
  933. return Promise.resolve();
  934. else
  935. return new Promise(function (resolve) {
  936. if (Feedback.isEnabled()) {
  937. // If the user has already entered feedback, we'll show the
  938. // window and immidiately start the conference dispose timeout.
  939. if (Feedback.getFeedbackScore() > 0) {
  940. Feedback.openFeedbackWindow();
  941. resolve();
  942. } else { // Otherwise we'll wait for user's feedback.
  943. Feedback.openFeedbackWindow(resolve);
  944. }
  945. } else {
  946. // If the feedback functionality isn't enabled we show a thank
  947. // you dialog. Signaling it (true), so the caller
  948. // of requestFeedback can act on it
  949. resolve(true);
  950. }
  951. });
  952. };
  953. UI.updateRecordingState = function (state) {
  954. Recording.updateRecordingState(state);
  955. };
  956. UI.notifyTokenAuthFailed = function () {
  957. messageHandler.showError( "dialog.tokenAuthFailedTitle",
  958. "dialog.tokenAuthFailed");
  959. };
  960. UI.notifyInternalError = function () {
  961. messageHandler.showError( "dialog.internalErrorTitle",
  962. "dialog.internalError");
  963. };
  964. UI.notifyFocusDisconnected = function (focus, retrySec) {
  965. messageHandler.notify(
  966. null, "notify.focus",
  967. 'disconnected', "notify.focusFail",
  968. {component: focus, ms: retrySec}
  969. );
  970. };
  971. /**
  972. * Notify user that focus left the conference so page should be reloaded.
  973. */
  974. UI.notifyFocusLeft = function () {
  975. let title = APP.translation.generateTranslationHTML(
  976. 'dialog.serviceUnavailable'
  977. );
  978. let msg = APP.translation.generateTranslationHTML(
  979. 'dialog.jicofoUnavailable'
  980. );
  981. messageHandler.openDialog(
  982. title,
  983. msg,
  984. true, // persistent
  985. [{title: 'retry'}],
  986. function () {
  987. reload();
  988. return false;
  989. }
  990. );
  991. };
  992. /**
  993. * Updates auth info on the UI.
  994. * @param {boolean} isAuthEnabled if authentication is enabled
  995. * @param {string} [login] current login
  996. */
  997. UI.updateAuthInfo = function (isAuthEnabled, login) {
  998. let loggedIn = !!login;
  999. Toolbar.showAuthenticateButton(isAuthEnabled);
  1000. if (isAuthEnabled) {
  1001. Toolbar.setAuthenticatedIdentity(login);
  1002. Toolbar.showLoginButton(!loggedIn);
  1003. Toolbar.showLogoutButton(loggedIn);
  1004. }
  1005. };
  1006. UI.onStartMutedChanged = function (startAudioMuted, startVideoMuted) {
  1007. SettingsMenu.updateStartMutedBox(startAudioMuted, startVideoMuted);
  1008. };
  1009. /**
  1010. * Notifies interested listeners that the raise hand property has changed.
  1011. *
  1012. * @param {boolean} isRaisedHand indicates the current state of the
  1013. * "raised hand"
  1014. */
  1015. UI.onLocalRaiseHandChanged = function (isRaisedHand) {
  1016. eventEmitter.emit(UIEvents.LOCAL_RAISE_HAND_CHANGED, isRaisedHand);
  1017. };
  1018. /**
  1019. * Update list of available physical devices.
  1020. * @param {object[]} devices new list of available devices
  1021. */
  1022. UI.onAvailableDevicesChanged = function (devices) {
  1023. SettingsMenu.changeDevicesList(devices);
  1024. };
  1025. /**
  1026. * Sets microphone's <select> element to select microphone ID from settings.
  1027. */
  1028. UI.setSelectedMicFromSettings = function () {
  1029. SettingsMenu.setSelectedMicFromSettings();
  1030. };
  1031. /**
  1032. * Sets camera's <select> element to select camera ID from settings.
  1033. */
  1034. UI.setSelectedCameraFromSettings = function () {
  1035. SettingsMenu.setSelectedCameraFromSettings();
  1036. };
  1037. /**
  1038. * Sets audio outputs's <select> element to select audio output ID from
  1039. * settings.
  1040. */
  1041. UI.setSelectedAudioOutputFromSettings = function () {
  1042. SettingsMenu.setSelectedAudioOutputFromSettings();
  1043. };
  1044. /**
  1045. * Returns the id of the current video shown on large.
  1046. * Currently used by tests (torture).
  1047. */
  1048. UI.getLargeVideoID = function () {
  1049. return VideoLayout.getLargeVideoID();
  1050. };
  1051. /**
  1052. * Returns the current video shown on large.
  1053. * Currently used by tests (torture).
  1054. */
  1055. UI.getLargeVideo = function () {
  1056. return VideoLayout.getLargeVideo();
  1057. };
  1058. /**
  1059. * Shows dialog with a link to FF extension.
  1060. */
  1061. UI.showExtensionRequiredDialog = function (url) {
  1062. messageHandler.openMessageDialog(
  1063. "dialog.extensionRequired",
  1064. null,
  1065. null,
  1066. APP.translation.generateTranslationHTML(
  1067. "dialog.firefoxExtensionPrompt", {url: url}));
  1068. };
  1069. /**
  1070. * Shows "Please go to chrome webstore to install the desktop sharing extension"
  1071. * 2 button dialog with buttons - cancel and go to web store.
  1072. * @param url {string} the url of the extension.
  1073. */
  1074. UI.showExtensionExternalInstallationDialog = function (url) {
  1075. let submitFunction = function(e,v){
  1076. if (v) {
  1077. e.preventDefault();
  1078. eventEmitter.emit(UIEvents.OPEN_EXTENSION_STORE, url);
  1079. }
  1080. };
  1081. let closeFunction = function () {
  1082. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  1083. };
  1084. messageHandler.openTwoButtonDialog({
  1085. titleKey: 'dialog.externalInstallationTitle',
  1086. titleString: '',
  1087. msgKey: 'dialog.externalInstallationMsg',
  1088. msgString: '',
  1089. leftButtonKey: 'dialog.goToStore',
  1090. submitFunction,
  1091. loadedFunction: $.noop,
  1092. closeFunction
  1093. });
  1094. };
  1095. /**
  1096. * Shows dialog with combined information about camera and microphone errors.
  1097. * @param {JitsiTrackError} micError
  1098. * @param {JitsiTrackError} cameraError
  1099. */
  1100. UI.showDeviceErrorDialog = function (micError, cameraError) {
  1101. let localStoragePropName = "doNotShowErrorAgain";
  1102. let isMicJitsiTrackErrorAndHasName = micError && micError.name &&
  1103. micError instanceof JitsiMeetJS.errorTypes.JitsiTrackError;
  1104. let isCameraJitsiTrackErrorAndHasName = cameraError && cameraError.name &&
  1105. cameraError instanceof JitsiMeetJS.errorTypes.JitsiTrackError;
  1106. let showDoNotShowWarning = false;
  1107. if (micError && cameraError && isMicJitsiTrackErrorAndHasName &&
  1108. isCameraJitsiTrackErrorAndHasName) {
  1109. showDoNotShowWarning = true;
  1110. } else if (micError && isMicJitsiTrackErrorAndHasName && !cameraError) {
  1111. showDoNotShowWarning = true;
  1112. } else if (cameraError && isCameraJitsiTrackErrorAndHasName && !micError) {
  1113. showDoNotShowWarning = true;
  1114. }
  1115. if (micError) {
  1116. localStoragePropName += "-mic-" + micError.name;
  1117. }
  1118. if (cameraError) {
  1119. localStoragePropName += "-camera-" + cameraError.name;
  1120. }
  1121. if (showDoNotShowWarning) {
  1122. if (window.localStorage[localStoragePropName] === "true") {
  1123. return;
  1124. }
  1125. }
  1126. let title = getTitleKey();
  1127. let titleMsg = `<span data-i18n="${title}"></span>`;
  1128. let cameraJitsiTrackErrorMsg = cameraError
  1129. ? JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[cameraError.name]
  1130. : undefined;
  1131. let micJitsiTrackErrorMsg = micError
  1132. ? JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[micError.name]
  1133. : undefined;
  1134. let cameraErrorMsg = cameraError
  1135. ? cameraJitsiTrackErrorMsg ||
  1136. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.GENERAL]
  1137. : "";
  1138. let micErrorMsg = micError
  1139. ? micJitsiTrackErrorMsg ||
  1140. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.GENERAL]
  1141. : "";
  1142. let additionalCameraErrorMsg = !cameraJitsiTrackErrorMsg && cameraError &&
  1143. cameraError.message
  1144. ? `<div>${cameraError.message}</div>`
  1145. : ``;
  1146. let additionalMicErrorMsg = !micJitsiTrackErrorMsg && micError &&
  1147. micError.message
  1148. ? `<div>${micError.message}</div>`
  1149. : ``;
  1150. let doNotShowWarningAgainSection = showDoNotShowWarning
  1151. ? `<label>
  1152. <input type='checkbox' id='doNotShowWarningAgain'>
  1153. <span data-i18n='dialog.doNotShowWarningAgain'></span>
  1154. </label>`
  1155. : ``;
  1156. let message = '';
  1157. if (micError) {
  1158. message = `
  1159. ${message}
  1160. <h3 data-i18n='dialog.micErrorPresent'></h3>
  1161. <h4 data-i18n='${micErrorMsg}'></h4>
  1162. ${additionalMicErrorMsg}`;
  1163. }
  1164. if (cameraError) {
  1165. message = `
  1166. ${message}
  1167. <h3 data-i18n='dialog.cameraErrorPresent'></h3>
  1168. <h4 data-i18n='${cameraErrorMsg}'></h4>
  1169. ${additionalCameraErrorMsg}`;
  1170. }
  1171. message = `${message}${doNotShowWarningAgainSection}`;
  1172. // To make sure we don't have multiple error dialogs open at the same time,
  1173. // we will just close the previous one if we are going to show a new one.
  1174. deviceErrorDialog && deviceErrorDialog.close();
  1175. deviceErrorDialog = messageHandler.openDialog(
  1176. titleMsg,
  1177. message,
  1178. false,
  1179. {Ok: true},
  1180. function () {
  1181. let form = $.prompt.getPrompt();
  1182. if (form) {
  1183. let input = form.find("#doNotShowWarningAgain");
  1184. if (input.length) {
  1185. window.localStorage[localStoragePropName] =
  1186. input.prop("checked");
  1187. }
  1188. }
  1189. },
  1190. null,
  1191. function () {
  1192. // Reset dialog reference to null to avoid memory leaks when
  1193. // user closed the dialog manually.
  1194. deviceErrorDialog = null;
  1195. }
  1196. );
  1197. APP.translation.translateElement($(".jqibox"));
  1198. function getTitleKey() {
  1199. let title = "dialog.error";
  1200. if (micError && micError.name === TrackErrors.PERMISSION_DENIED) {
  1201. if (!cameraError
  1202. || cameraError.name === TrackErrors.PERMISSION_DENIED) {
  1203. title = "dialog.permissionDenied";
  1204. }
  1205. } else if (cameraError
  1206. && cameraError.name === TrackErrors.PERMISSION_DENIED) {
  1207. title = "dialog.permissionDenied";
  1208. }
  1209. return title;
  1210. }
  1211. };
  1212. /**
  1213. * Shows error dialog that informs the user that no data is received from the
  1214. * device.
  1215. */
  1216. UI.showTrackNotWorkingDialog = function (stream) {
  1217. messageHandler.openMessageDialog(
  1218. "dialog.error",
  1219. stream.isAudioTrack()? "dialog.micNotSendingData" :
  1220. "dialog.cameraNotSendingData",
  1221. null,
  1222. null);
  1223. };
  1224. UI.updateDevicesAvailability = function (id, devices) {
  1225. VideoLayout.setDeviceAvailabilityIcons(id, devices);
  1226. };
  1227. /**
  1228. * Show shared video.
  1229. * @param {string} id the id of the sender of the command
  1230. * @param {string} url video url
  1231. * @param {string} attributes
  1232. */
  1233. UI.onSharedVideoStart = function (id, url, attributes) {
  1234. if (sharedVideoManager)
  1235. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  1236. };
  1237. /**
  1238. * Update shared video.
  1239. * @param {string} id the id of the sender of the command
  1240. * @param {string} url video url
  1241. * @param {string} attributes
  1242. */
  1243. UI.onSharedVideoUpdate = function (id, url, attributes) {
  1244. if (sharedVideoManager)
  1245. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  1246. };
  1247. /**
  1248. * Stop showing shared video.
  1249. * @param {string} id the id of the sender of the command
  1250. * @param {string} attributes
  1251. */
  1252. UI.onSharedVideoStop = function (id, attributes) {
  1253. if (sharedVideoManager)
  1254. sharedVideoManager.onSharedVideoStop(id, attributes);
  1255. };
  1256. /**
  1257. * Enables / disables camera toolbar button.
  1258. *
  1259. * @param {boolean} enabled indicates if the camera button should be enabled
  1260. * or disabled
  1261. */
  1262. UI.setCameraButtonEnabled = function (enabled) {
  1263. Toolbar.setVideoIconEnabled(enabled);
  1264. };
  1265. /**
  1266. * Enables / disables microphone toolbar button.
  1267. *
  1268. * @param {boolean} enabled indicates if the microphone button should be
  1269. * enabled or disabled
  1270. */
  1271. UI.setMicrophoneButtonEnabled = function (enabled) {
  1272. Toolbar.setAudioIconEnabled(enabled);
  1273. };
  1274. UI.showRingOverlay = function () {
  1275. RingOverlay.show(APP.tokenData.callee, interfaceConfig.DISABLE_RINGING);
  1276. FilmStrip.toggleFilmStrip(false);
  1277. };
  1278. UI.hideRingOverLay = function () {
  1279. if (!RingOverlay.hide())
  1280. return;
  1281. FilmStrip.toggleFilmStrip(true);
  1282. };
  1283. /**
  1284. * Indicates if the ring overlay is currently visible.
  1285. *
  1286. * @returns {*|boolean} {true} if the ring overlay is visible, {false} otherwise
  1287. */
  1288. UI.isRingOverlayVisible = function () {
  1289. return RingOverlay.isVisible();
  1290. };
  1291. /**
  1292. * Shows browser-specific overlay with guidance how to proceed with gUM prompt.
  1293. * @param {string} browser - name of browser for which to show the guidance
  1294. * overlay.
  1295. */
  1296. UI.showUserMediaPermissionsGuidanceOverlay = function (browser) {
  1297. GumPermissionsOverlay.show(browser);
  1298. };
  1299. /**
  1300. * Hides browser-specific overlay with guidance how to proceed with gUM prompt.
  1301. */
  1302. UI.hideUserMediaPermissionsGuidanceOverlay = function () {
  1303. GumPermissionsOverlay.hide();
  1304. };
  1305. /**
  1306. * Shows or hides the keyboard shortcuts panel, depending on the current state.'
  1307. */
  1308. UI.toggleKeyboardShortcutsPanel = function() {
  1309. let titleKey = 'keyboardShortcuts.keyboardShortcuts';
  1310. let title = APP.translation.translateString(titleKey);
  1311. let msg = $('#keyboard-shortcuts').html();
  1312. let buttons = { Close: true };
  1313. messageHandler.openDialog(title, msg, true, buttons);
  1314. };
  1315. /**
  1316. * Shows or hides the keyboard shortcuts panel.'
  1317. */
  1318. UI.showKeyboardShortcutsPanel = function(show) {
  1319. if (show) {
  1320. $('#keyboard-shortcuts').show();
  1321. } else {
  1322. $('#keyboard-shortcuts').hide();
  1323. }
  1324. };
  1325. module.exports = UI;