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.

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