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.

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