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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  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 message = (
  68. `<div class="input-control">
  69. <label data-i18n="${labelKey}" class="input-control__label"></label>
  70. <input name="displayName" type="text"
  71. data-i18n="[placeholder]defaultNickname"
  72. class="input-control__input"
  73. autofocus>
  74. </div>`
  75. );
  76. // Don't use a translation string, because we're too early in the call and
  77. // the translation may not be initialised.
  78. let buttons = {Ok:true};
  79. let dialog = messageHandler.openDialog(
  80. 'dialog.displayNameRequired',
  81. message,
  82. true,
  83. buttons,
  84. function (e, v, m, f) {
  85. e.preventDefault();
  86. if (v) {
  87. let displayName = f.displayName;
  88. if (displayName) {
  89. UI.inputDisplayNameHandler(displayName);
  90. dialog.close();
  91. return;
  92. }
  93. }
  94. },
  95. function () {
  96. let form = $.prompt.getPrompt();
  97. let input = form.find("input[name='displayName']");
  98. input.focus();
  99. let button = form.find("button");
  100. button.attr("disabled", "disabled");
  101. input.keyup(function () {
  102. if (input.val()) {
  103. button.removeAttr("disabled");
  104. } else {
  105. button.attr("disabled", "disabled");
  106. }
  107. });
  108. }
  109. );
  110. }
  111. /**
  112. * Initialize chat.
  113. */
  114. function setupChat() {
  115. Chat.init(eventEmitter);
  116. $("#toggle_smileys").click(function() {
  117. Chat.toggleSmileys();
  118. });
  119. }
  120. /**
  121. * Initialize toolbars.
  122. */
  123. function setupToolbars() {
  124. Toolbar.init(eventEmitter);
  125. }
  126. /**
  127. * Toggles the application in and out of full screen mode
  128. * (a.k.a. presentation mode in Chrome).
  129. */
  130. UI.toggleFullScreen = function() {
  131. (UIUtil.isFullScreen())
  132. ? UIUtil.exitFullScreen()
  133. : UIUtil.enterFullScreen();
  134. };
  135. /**
  136. * Notify user that server has shut down.
  137. */
  138. UI.notifyGracefulShutdown = function () {
  139. messageHandler.openMessageDialog(
  140. 'dialog.serviceUnavailable',
  141. 'dialog.gracefulShutdown'
  142. );
  143. };
  144. /**
  145. * Notify user that reservation error happened.
  146. */
  147. UI.notifyReservationError = function (code, msg) {
  148. var message = APP.translation.generateTranslationHTML(
  149. "dialog.reservationErrorMsg", {code: code, msg: msg});
  150. messageHandler.openDialog(
  151. "dialog.reservationError", message, true, {}, () => false);
  152. };
  153. /**
  154. * Notify user that he has been kicked from the server.
  155. */
  156. UI.notifyKicked = function () {
  157. messageHandler.openMessageDialog(
  158. "dialog.sessTerminated",
  159. "dialog.kickMessage");
  160. };
  161. /**
  162. * Notify user that conference was destroyed.
  163. * @param reason {string} the reason text
  164. */
  165. UI.notifyConferenceDestroyed = function (reason) {
  166. //FIXME: use Session Terminated from translation, but
  167. // 'reason' text comes from XMPP packet and is not translated
  168. messageHandler.openDialog(
  169. "dialog.sessTerminated", reason, true, {}, () => false);
  170. };
  171. /**
  172. * Notify user that Jitsi Videobridge is not accessible.
  173. */
  174. UI.notifyBridgeDown = function () {
  175. messageHandler.showError("dialog.error", "dialog.bridgeUnavailable");
  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 message = (
  654. `<input name="username" type="text"
  655. placeholder="user@domain.net" autofocus>
  656. <input name="password" type="password"
  657. data-i18n="[placeholder]dialog.userPassword"
  658. placeholder="user password">`
  659. );
  660. let submitFunction = (e, v, m, f) => {
  661. if (v) {
  662. if (f.username && f.password) {
  663. callback(f.username, f.password);
  664. }
  665. }
  666. };
  667. messageHandler.openTwoButtonDialog({
  668. titleKey : "dialog.passwordRequired",
  669. msgString: message,
  670. leftButtonKey: 'dialog.Ok',
  671. submitFunction,
  672. focus: ':input:first'
  673. });
  674. };
  675. UI.askForNickname = function () {
  676. return window.prompt('Your nickname (optional)');
  677. };
  678. /**
  679. * Sets muted audio state for participant
  680. */
  681. UI.setAudioMuted = function (id, muted) {
  682. VideoLayout.onAudioMute(id, muted);
  683. if (APP.conference.isLocalId(id)) {
  684. Toolbar.toggleAudioIcon(muted);
  685. }
  686. };
  687. /**
  688. * Sets muted video state for participant
  689. */
  690. UI.setVideoMuted = function (id, muted) {
  691. VideoLayout.onVideoMute(id, muted);
  692. if (APP.conference.isLocalId(id)) {
  693. Toolbar.toggleVideoIcon(muted);
  694. }
  695. };
  696. /**
  697. * Adds a listener that would be notified on the given type of event.
  698. *
  699. * @param type the type of the event we're listening for
  700. * @param listener a function that would be called when notified
  701. */
  702. UI.addListener = function (type, listener) {
  703. eventEmitter.on(type, listener);
  704. };
  705. /**
  706. * Removes the given listener for the given type of event.
  707. *
  708. * @param type the type of the event we're listening for
  709. * @param listener the listener we want to remove
  710. */
  711. UI.removeListener = function (type, listener) {
  712. eventEmitter.removeListener(type, listener);
  713. };
  714. /**
  715. * Emits the event of given type by specifying the parameters in options.
  716. *
  717. * @param type the type of the event we're emitting
  718. * @param options the parameters for the event
  719. */
  720. UI.emitEvent = function (type, options) {
  721. eventEmitter.emit(type, options);
  722. };
  723. UI.clickOnVideo = function (videoNumber) {
  724. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  725. if (remoteVideos.length > videoNumber) {
  726. remoteVideos[videoNumber].click();
  727. }
  728. };
  729. //Used by torture
  730. UI.showToolbar = function (timeout) {
  731. return ToolbarToggler.showToolbar(timeout);
  732. };
  733. //Used by torture
  734. UI.dockToolbar = function (isDock) {
  735. ToolbarToggler.dockToolbar(isDock);
  736. };
  737. /**
  738. * Updates the avatar for participant.
  739. * @param {string} id user id
  740. * @param {string} avatarUrl the URL for the avatar
  741. */
  742. function changeAvatar(id, avatarUrl) {
  743. VideoLayout.changeUserAvatar(id, avatarUrl);
  744. UI.ContactList.changeUserAvatar(id, avatarUrl);
  745. if (APP.conference.isLocalId(id)) {
  746. Profile.changeAvatar(avatarUrl);
  747. }
  748. }
  749. /**
  750. * Update user email.
  751. * @param {string} id user id
  752. * @param {string} email user email
  753. */
  754. UI.setUserEmail = function (id, email) {
  755. // update avatar
  756. Avatar.setUserEmail(id, email);
  757. changeAvatar(id, Avatar.getAvatarUrl(id));
  758. };
  759. /**
  760. * Update user avtar id.
  761. * @param {string} id user id
  762. * @param {string} avatarId user's avatar id
  763. */
  764. UI.setUserAvatarID = function (id, avatarId) {
  765. // update avatar
  766. Avatar.setUserAvatarID(id, avatarId);
  767. changeAvatar(id, Avatar.getAvatarUrl(id));
  768. };
  769. /**
  770. * Update user avatar URL.
  771. * @param {string} id user id
  772. * @param {string} url user avatar url
  773. */
  774. UI.setUserAvatarUrl = function (id, url) {
  775. // update avatar
  776. Avatar.setUserAvatarUrl(id, url);
  777. changeAvatar(id, Avatar.getAvatarUrl(id));
  778. };
  779. /**
  780. * Notify user that connection failed.
  781. * @param {string} stropheErrorMsg raw Strophe error message
  782. */
  783. UI.notifyConnectionFailed = function (stropheErrorMsg) {
  784. var message;
  785. if (stropheErrorMsg) {
  786. message = APP.translation.generateTranslationHTML(
  787. "dialog.connectErrorWithMsg", {msg: stropheErrorMsg});
  788. } else {
  789. message = APP.translation.generateTranslationHTML(
  790. "dialog.connectError");
  791. }
  792. messageHandler.openDialog("dialog.error", message, true, {}, () => false);
  793. };
  794. /**
  795. * Notify user that maximum users limit has been reached.
  796. */
  797. UI.notifyMaxUsersLimitReached = function () {
  798. var message = APP.translation.generateTranslationHTML(
  799. "dialog.maxUsersLimitReached");
  800. messageHandler.openDialog("dialog.error", message, true, {}, () => false);
  801. };
  802. /**
  803. * Notify user that he was automatically muted when joned the conference.
  804. */
  805. UI.notifyInitiallyMuted = function () {
  806. messageHandler.notify(
  807. null,
  808. "notify.mutedTitle",
  809. "connected",
  810. "notify.muted",
  811. null,
  812. { timeOut: 120000 });
  813. };
  814. /**
  815. * Mark user as dominant speaker.
  816. * @param {string} id user id
  817. */
  818. UI.markDominantSpeaker = function (id) {
  819. VideoLayout.onDominantSpeakerChanged(id);
  820. };
  821. UI.handleLastNEndpoints = function (ids, enteringIds) {
  822. VideoLayout.onLastNEndpointsChanged(ids, enteringIds);
  823. };
  824. /**
  825. * Will handle notification about participant's connectivity status change.
  826. *
  827. * @param {string} id the id of remote participant(MUC jid)
  828. * @param {boolean} isActive true if the connection is ok or false if the user
  829. * is having connectivity issues.
  830. */
  831. UI.participantConnectionStatusChanged = function (id, isActive) {
  832. VideoLayout.onParticipantConnectionStatusChanged(id, isActive);
  833. };
  834. /**
  835. * Update audio level visualization for specified user.
  836. * @param {string} id user id
  837. * @param {number} lvl audio level
  838. */
  839. UI.setAudioLevel = function (id, lvl) {
  840. VideoLayout.setAudioLevel(id, lvl);
  841. };
  842. /**
  843. * Update state of desktop sharing buttons.
  844. */
  845. UI.updateDesktopSharingButtons = function () {
  846. Toolbar.updateDesktopSharingButtonState();
  847. };
  848. /**
  849. * Hide connection quality statistics from UI.
  850. */
  851. UI.hideStats = function () {
  852. VideoLayout.hideStats();
  853. };
  854. /**
  855. * Update local connection quality statistics.
  856. * @param {number} percent
  857. * @param {object} stats
  858. */
  859. UI.updateLocalStats = function (percent, stats) {
  860. VideoLayout.updateLocalConnectionStats(percent, stats);
  861. };
  862. /**
  863. * Update connection quality statistics for remote user.
  864. * @param {string} id user id
  865. * @param {number} percent
  866. * @param {object} stats
  867. */
  868. UI.updateRemoteStats = function (id, percent, stats) {
  869. VideoLayout.updateConnectionStats(id, percent, stats);
  870. };
  871. /**
  872. * Mark video as interrupted or not.
  873. * @param {boolean} interrupted if video is interrupted
  874. */
  875. UI.markVideoInterrupted = function (interrupted) {
  876. if (interrupted) {
  877. VideoLayout.onVideoInterrupted();
  878. } else {
  879. VideoLayout.onVideoRestored();
  880. }
  881. };
  882. /**
  883. * Add chat message.
  884. * @param {string} from user id
  885. * @param {string} displayName user nickname
  886. * @param {string} message message text
  887. * @param {number} stamp timestamp when message was created
  888. */
  889. UI.addMessage = function (from, displayName, message, stamp) {
  890. Chat.updateChatConversation(from, displayName, message, stamp);
  891. };
  892. // eslint-disable-next-line no-unused-vars
  893. UI.updateDTMFSupport = function (isDTMFSupported) {
  894. //TODO: enable when the UI is ready
  895. //Toolbar.showDialPadButton(dtmfSupport);
  896. };
  897. /**
  898. * Show user feedback dialog if its required and enabled after pressing the
  899. * hangup button.
  900. * @returns {Promise} Resolved with value - false if the dialog is enabled and
  901. * resolved with true if the dialog is disabled or the feedback was already
  902. * submitted. Rejected if another dialog is already displayed. This values are
  903. * used to display or not display the thank you dialog from
  904. * conference.maybeRedirectToWelcomePage method.
  905. */
  906. UI.requestFeedbackOnHangup = function () {
  907. if (Feedback.isVisible())
  908. return Promise.reject(UIErrors.FEEDBACK_REQUEST_IN_PROGRESS);
  909. // Feedback has been submitted already.
  910. else if (Feedback.isEnabled() && Feedback.isSubmitted())
  911. return Promise.resolve(true);
  912. else
  913. return new Promise(function (resolve) {
  914. if (Feedback.isEnabled()) {
  915. // If the user has already entered feedback, we'll show the
  916. // window and immidiately start the conference dispose timeout.
  917. if (Feedback.getFeedbackScore() > 0) {
  918. Feedback.openFeedbackWindow();
  919. resolve(false);
  920. } else { // Otherwise we'll wait for user's feedback.
  921. Feedback.openFeedbackWindow(() => resolve(false));
  922. }
  923. } else {
  924. // If the feedback functionality isn't enabled we show a thank
  925. // you dialog. Signaling it (true), so the caller
  926. // of requestFeedback can act on it
  927. resolve(true);
  928. }
  929. });
  930. };
  931. UI.updateRecordingState = function (state) {
  932. Recording.updateRecordingState(state);
  933. };
  934. UI.notifyTokenAuthFailed = function () {
  935. messageHandler.showError( "dialog.tokenAuthFailedTitle",
  936. "dialog.tokenAuthFailed");
  937. };
  938. UI.notifyInternalError = function () {
  939. messageHandler.showError( "dialog.internalErrorTitle",
  940. "dialog.internalError");
  941. };
  942. UI.notifyFocusDisconnected = function (focus, retrySec) {
  943. messageHandler.notify(
  944. null, "notify.focus",
  945. 'disconnected', "notify.focusFail",
  946. {component: focus, ms: retrySec}
  947. );
  948. };
  949. /**
  950. * Notify user that focus left the conference so page should be reloaded.
  951. */
  952. UI.notifyFocusLeft = function () {
  953. let msg = APP.translation.generateTranslationHTML(
  954. 'dialog.jicofoUnavailable'
  955. );
  956. messageHandler.openDialog(
  957. 'dialog.serviceUnavailable',
  958. msg,
  959. true, // persistent
  960. [{title: 'retry'}],
  961. function () {
  962. reload();
  963. return false;
  964. }
  965. );
  966. };
  967. /**
  968. * Updates auth info on the UI.
  969. * @param {boolean} isAuthEnabled if authentication is enabled
  970. * @param {string} [login] current login
  971. */
  972. UI.updateAuthInfo = function (isAuthEnabled, login) {
  973. let showAuth = isAuthEnabled && UIUtil.isAuthenticationEnabled();
  974. let loggedIn = !!login;
  975. Toolbar.showAuthenticateButton(showAuth);
  976. if (showAuth) {
  977. Toolbar.setAuthenticatedIdentity(login);
  978. Toolbar.showLoginButton(!loggedIn);
  979. Toolbar.showLogoutButton(loggedIn);
  980. }
  981. };
  982. UI.onStartMutedChanged = function (startAudioMuted, startVideoMuted) {
  983. SettingsMenu.updateStartMutedBox(startAudioMuted, startVideoMuted);
  984. };
  985. /**
  986. * Notifies interested listeners that the raise hand property has changed.
  987. *
  988. * @param {boolean} isRaisedHand indicates the current state of the
  989. * "raised hand"
  990. */
  991. UI.onLocalRaiseHandChanged = function (isRaisedHand) {
  992. eventEmitter.emit(UIEvents.LOCAL_RAISE_HAND_CHANGED, isRaisedHand);
  993. };
  994. /**
  995. * Update list of available physical devices.
  996. * @param {object[]} devices new list of available devices
  997. */
  998. UI.onAvailableDevicesChanged = function (devices) {
  999. SettingsMenu.changeDevicesList(devices);
  1000. };
  1001. /**
  1002. * Sets microphone's <select> element to select microphone ID from settings.
  1003. */
  1004. UI.setSelectedMicFromSettings = function () {
  1005. SettingsMenu.setSelectedMicFromSettings();
  1006. };
  1007. /**
  1008. * Sets camera's <select> element to select camera ID from settings.
  1009. */
  1010. UI.setSelectedCameraFromSettings = function () {
  1011. SettingsMenu.setSelectedCameraFromSettings();
  1012. };
  1013. /**
  1014. * Sets audio outputs's <select> element to select audio output ID from
  1015. * settings.
  1016. */
  1017. UI.setSelectedAudioOutputFromSettings = function () {
  1018. SettingsMenu.setSelectedAudioOutputFromSettings();
  1019. };
  1020. /**
  1021. * Returns the id of the current video shown on large.
  1022. * Currently used by tests (torture).
  1023. */
  1024. UI.getLargeVideoID = function () {
  1025. return VideoLayout.getLargeVideoID();
  1026. };
  1027. /**
  1028. * Returns the current video shown on large.
  1029. * Currently used by tests (torture).
  1030. */
  1031. UI.getLargeVideo = function () {
  1032. return VideoLayout.getLargeVideo();
  1033. };
  1034. /**
  1035. * Shows dialog with a link to FF extension.
  1036. */
  1037. UI.showExtensionRequiredDialog = function (url) {
  1038. messageHandler.openMessageDialog(
  1039. "dialog.extensionRequired",
  1040. null,
  1041. APP.translation.generateTranslationHTML(
  1042. "dialog.firefoxExtensionPrompt", {url: url}));
  1043. };
  1044. /**
  1045. * Shows "Please go to chrome webstore to install the desktop sharing extension"
  1046. * 2 button dialog with buttons - cancel and go to web store.
  1047. * @param url {string} the url of the extension.
  1048. */
  1049. UI.showExtensionExternalInstallationDialog = function (url) {
  1050. let submitFunction = function(e,v){
  1051. if (v) {
  1052. e.preventDefault();
  1053. eventEmitter.emit(UIEvents.OPEN_EXTENSION_STORE, url);
  1054. }
  1055. };
  1056. let closeFunction = function () {
  1057. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  1058. };
  1059. messageHandler.openTwoButtonDialog({
  1060. titleKey: 'dialog.externalInstallationTitle',
  1061. msgKey: 'dialog.externalInstallationMsg',
  1062. msgString: '',
  1063. leftButtonKey: 'dialog.goToStore',
  1064. submitFunction,
  1065. loadedFunction: $.noop,
  1066. closeFunction
  1067. });
  1068. };
  1069. /**
  1070. * Shows dialog with combined information about camera and microphone errors.
  1071. * @param {JitsiTrackError} micError
  1072. * @param {JitsiTrackError} cameraError
  1073. */
  1074. UI.showDeviceErrorDialog = function (micError, cameraError) {
  1075. let localStoragePropName = "doNotShowErrorAgain";
  1076. let isMicJitsiTrackErrorAndHasName = micError && micError.name &&
  1077. micError instanceof JitsiMeetJS.errorTypes.JitsiTrackError;
  1078. let isCameraJitsiTrackErrorAndHasName = cameraError && cameraError.name &&
  1079. cameraError instanceof JitsiMeetJS.errorTypes.JitsiTrackError;
  1080. let showDoNotShowWarning = false;
  1081. if (micError && cameraError && isMicJitsiTrackErrorAndHasName &&
  1082. isCameraJitsiTrackErrorAndHasName) {
  1083. showDoNotShowWarning = true;
  1084. } else if (micError && isMicJitsiTrackErrorAndHasName && !cameraError) {
  1085. showDoNotShowWarning = true;
  1086. } else if (cameraError && isCameraJitsiTrackErrorAndHasName && !micError) {
  1087. showDoNotShowWarning = true;
  1088. }
  1089. if (micError) {
  1090. localStoragePropName += "-mic-" + micError.name;
  1091. }
  1092. if (cameraError) {
  1093. localStoragePropName += "-camera-" + cameraError.name;
  1094. }
  1095. if (showDoNotShowWarning) {
  1096. if (window.localStorage[localStoragePropName] === "true") {
  1097. return;
  1098. }
  1099. }
  1100. let cameraJitsiTrackErrorMsg = cameraError
  1101. ? JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[cameraError.name]
  1102. : undefined;
  1103. let micJitsiTrackErrorMsg = micError
  1104. ? JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[micError.name]
  1105. : undefined;
  1106. let cameraErrorMsg = cameraError
  1107. ? cameraJitsiTrackErrorMsg ||
  1108. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.GENERAL]
  1109. : "";
  1110. let micErrorMsg = micError
  1111. ? micJitsiTrackErrorMsg ||
  1112. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.GENERAL]
  1113. : "";
  1114. let additionalCameraErrorMsg = !cameraJitsiTrackErrorMsg && cameraError &&
  1115. cameraError.message
  1116. ? `<div>${cameraError.message}</div>`
  1117. : ``;
  1118. let additionalMicErrorMsg = !micJitsiTrackErrorMsg && micError &&
  1119. micError.message
  1120. ? `<div>${micError.message}</div>`
  1121. : ``;
  1122. let doNotShowWarningAgainSection = showDoNotShowWarning
  1123. ? `<label>
  1124. <input type='checkbox' id='doNotShowWarningAgain'>
  1125. <span data-i18n='dialog.doNotShowWarningAgain'></span>
  1126. </label>`
  1127. : ``;
  1128. let message = '';
  1129. if (micError) {
  1130. message = `
  1131. ${message}
  1132. <h3 data-i18n='dialog.micErrorPresent'></h3>
  1133. <h4 data-i18n='${micErrorMsg}'></h4>
  1134. ${additionalMicErrorMsg}`;
  1135. }
  1136. if (cameraError) {
  1137. message = `
  1138. ${message}
  1139. <h3 data-i18n='dialog.cameraErrorPresent'></h3>
  1140. <h4 data-i18n='${cameraErrorMsg}'></h4>
  1141. ${additionalCameraErrorMsg}`;
  1142. }
  1143. message = `${message}${doNotShowWarningAgainSection}`;
  1144. // To make sure we don't have multiple error dialogs open at the same time,
  1145. // we will just close the previous one if we are going to show a new one.
  1146. deviceErrorDialog && deviceErrorDialog.close();
  1147. deviceErrorDialog = messageHandler.openDialog(
  1148. getTitleKey(),
  1149. message,
  1150. false,
  1151. {Ok: true},
  1152. function () {
  1153. let form = $.prompt.getPrompt();
  1154. if (form) {
  1155. let input = form.find("#doNotShowWarningAgain");
  1156. if (input.length) {
  1157. window.localStorage[localStoragePropName] =
  1158. input.prop("checked");
  1159. }
  1160. }
  1161. },
  1162. null,
  1163. function () {
  1164. // Reset dialog reference to null to avoid memory leaks when
  1165. // user closed the dialog manually.
  1166. deviceErrorDialog = null;
  1167. }
  1168. );
  1169. function getTitleKey() {
  1170. let title = "dialog.error";
  1171. if (micError && micError.name === TrackErrors.PERMISSION_DENIED) {
  1172. if (!cameraError
  1173. || cameraError.name === TrackErrors.PERMISSION_DENIED) {
  1174. title = "dialog.permissionDenied";
  1175. }
  1176. } else if (cameraError
  1177. && cameraError.name === TrackErrors.PERMISSION_DENIED) {
  1178. title = "dialog.permissionDenied";
  1179. }
  1180. return title;
  1181. }
  1182. };
  1183. /**
  1184. * Shows error dialog that informs the user that no data is received from the
  1185. * device.
  1186. */
  1187. UI.showTrackNotWorkingDialog = function (stream) {
  1188. messageHandler.openMessageDialog(
  1189. "dialog.error",
  1190. stream.isAudioTrack()? "dialog.micNotSendingData" :
  1191. "dialog.cameraNotSendingData",
  1192. null);
  1193. };
  1194. UI.updateDevicesAvailability = function (id, devices) {
  1195. VideoLayout.setDeviceAvailabilityIcons(id, devices);
  1196. };
  1197. /**
  1198. * Show shared video.
  1199. * @param {string} id the id of the sender of the command
  1200. * @param {string} url video url
  1201. * @param {string} attributes
  1202. */
  1203. UI.onSharedVideoStart = function (id, url, attributes) {
  1204. if (sharedVideoManager)
  1205. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  1206. };
  1207. /**
  1208. * Update shared video.
  1209. * @param {string} id the id of the sender of the command
  1210. * @param {string} url video url
  1211. * @param {string} attributes
  1212. */
  1213. UI.onSharedVideoUpdate = function (id, url, attributes) {
  1214. if (sharedVideoManager)
  1215. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  1216. };
  1217. /**
  1218. * Stop showing shared video.
  1219. * @param {string} id the id of the sender of the command
  1220. * @param {string} attributes
  1221. */
  1222. UI.onSharedVideoStop = function (id, attributes) {
  1223. if (sharedVideoManager)
  1224. sharedVideoManager.onSharedVideoStop(id, attributes);
  1225. };
  1226. /**
  1227. * Enables / disables camera toolbar button.
  1228. *
  1229. * @param {boolean} enabled indicates if the camera button should be enabled
  1230. * or disabled
  1231. */
  1232. UI.setCameraButtonEnabled = function (enabled) {
  1233. Toolbar.setVideoIconEnabled(enabled);
  1234. };
  1235. /**
  1236. * Enables / disables microphone toolbar button.
  1237. *
  1238. * @param {boolean} enabled indicates if the microphone button should be
  1239. * enabled or disabled
  1240. */
  1241. UI.setMicrophoneButtonEnabled = function (enabled) {
  1242. Toolbar.setAudioIconEnabled(enabled);
  1243. };
  1244. UI.showRingOverlay = function () {
  1245. RingOverlay.show(APP.tokenData.callee, interfaceConfig.DISABLE_RINGING);
  1246. FilmStrip.toggleFilmStrip(false);
  1247. };
  1248. UI.hideRingOverLay = function () {
  1249. if (!RingOverlay.hide())
  1250. return;
  1251. FilmStrip.toggleFilmStrip(true);
  1252. };
  1253. /**
  1254. * Indicates if the ring overlay is currently visible.
  1255. *
  1256. * @returns {*|boolean} {true} if the ring overlay is visible, {false} otherwise
  1257. */
  1258. UI.isRingOverlayVisible = function () {
  1259. return RingOverlay.isVisible();
  1260. };
  1261. /**
  1262. * Shows browser-specific overlay with guidance how to proceed with gUM prompt.
  1263. * @param {string} browser - name of browser for which to show the guidance
  1264. * overlay.
  1265. */
  1266. UI.showUserMediaPermissionsGuidanceOverlay = function (browser) {
  1267. GumPermissionsOverlay.show(browser);
  1268. };
  1269. /**
  1270. * Hides browser-specific overlay with guidance how to proceed with gUM prompt.
  1271. */
  1272. UI.hideUserMediaPermissionsGuidanceOverlay = function () {
  1273. GumPermissionsOverlay.hide();
  1274. };
  1275. /**
  1276. * Shows or hides the keyboard shortcuts panel, depending on the current state.'
  1277. */
  1278. UI.toggleKeyboardShortcutsPanel = function() {
  1279. if (!messageHandler.isDialogOpened()) {
  1280. let msg = $('#keyboard-shortcuts').html();
  1281. let buttons = { Close: true };
  1282. messageHandler.openDialog(
  1283. 'keyboardShortcuts.keyboardShortcuts', msg, true, buttons);
  1284. } else {
  1285. messageHandler.closeDialog();
  1286. }
  1287. };
  1288. /**
  1289. * Shows or hides the keyboard shortcuts panel.'
  1290. */
  1291. UI.showKeyboardShortcutsPanel = function(show) {
  1292. if (show) {
  1293. $('#keyboard-shortcuts').show();
  1294. } else {
  1295. $('#keyboard-shortcuts').hide();
  1296. }
  1297. };
  1298. module.exports = UI;