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

UI.js 42KB

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