You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UI.js 43KB

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