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

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