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

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