Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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