Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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