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

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