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

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