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

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