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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  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. VideoLayout.onDisplayNameChanged(id, displayName);
  196. if (APP.conference.isLocalId(id) || id === 'localVideoContainer') {
  197. SettingsMenu.changeDisplayName(displayName);
  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.PREZI_CLICKED, function () {
  230. preziManager.handlePreziButtonClicked();
  231. });
  232. UI.addListener(UIEvents.ETHERPAD_CLICKED, function () {
  233. if (etherpadManager) {
  234. etherpadManager.toggleEtherpad();
  235. }
  236. });
  237. UI.addListener(UIEvents.FULLSCREEN_TOGGLE, toggleFullScreen);
  238. UI.addListener(UIEvents.TOGGLE_CHAT, UI.toggleChat);
  239. UI.addListener(UIEvents.TOGGLE_SETTINGS, function () {
  240. PanelToggler.toggleSettingsMenu();
  241. });
  242. UI.addListener(UIEvents.TOGGLE_CONTACT_LIST, UI.toggleContactList);
  243. UI.addListener(UIEvents.TOGGLE_FILM_STRIP, UI.toggleFilmStrip);
  244. }
  245. /**
  246. * Setup some DOM event listeners.
  247. */
  248. function bindEvents() {
  249. function onResize() {
  250. PanelToggler.resizeChat();
  251. VideoLayout.resizeVideoArea(PanelToggler.isVisible());
  252. }
  253. // Resize and reposition videos in full screen mode.
  254. $(document).on(
  255. 'webkitfullscreenchange mozfullscreenchange fullscreenchange',
  256. onResize
  257. );
  258. $(window).resize(onResize);
  259. }
  260. /**
  261. * Starts the UI module and initializes all related components.
  262. *
  263. * @returns {boolean} true if the UI is ready and the conference should be
  264. * esablished, false - otherwise (for example in the case of welcome page)
  265. */
  266. UI.start = function () {
  267. document.title = interfaceConfig.APP_NAME;
  268. var setupWelcomePage = null;
  269. if(config.enableWelcomePage && window.location.pathname == "/" &&
  270. Settings.isWelcomePageEnabled()) {
  271. $("#videoconference_page").hide();
  272. if (!setupWelcomePage)
  273. setupWelcomePage = require("./welcome_page/WelcomePage");
  274. setupWelcomePage();
  275. // Return false to indicate that the UI hasn't been fully started and
  276. // conference ready. We're still waiting for input from the user.
  277. return false;
  278. }
  279. $("#welcome_page").hide();
  280. // Set the defaults for prompt dialogs.
  281. $.prompt.setDefaults({persistent: false});
  282. registerListeners();
  283. BottomToolbar.init();
  284. FilmStrip.init();
  285. VideoLayout.init(eventEmitter);
  286. if (!interfaceConfig.filmStripOnly) {
  287. VideoLayout.initLargeVideo(PanelToggler.isVisible());
  288. }
  289. VideoLayout.resizeVideoArea(PanelToggler.isVisible(), true, true);
  290. ContactList.init(eventEmitter);
  291. bindEvents();
  292. preziManager = new PreziManager(eventEmitter);
  293. if (!interfaceConfig.filmStripOnly) {
  294. $("#videospace").mousemove(function () {
  295. return ToolbarToggler.showToolbar();
  296. });
  297. setupToolbars();
  298. setupChat();
  299. // Display notice message at the top of the toolbar
  300. if (config.noticeMessage) {
  301. $('#noticeText').text(config.noticeMessage);
  302. $('#notice').css({display: 'block'});
  303. }
  304. $("#downloadlog").click(function (event) {
  305. let logs = APP.conference.getLogs();
  306. let data = encodeURIComponent(JSON.stringify(logs, null, ' '));
  307. let elem = event.target.parentNode;
  308. elem.download = 'meetlog.json';
  309. elem.href = 'data:application/json;charset=utf-8,\n' + data;
  310. });
  311. } else {
  312. $("#header").css("display", "none");
  313. $("#downloadlog").css("display", "none");
  314. BottomToolbar.hide();
  315. FilmStrip.setupFilmStripOnly();
  316. messageHandler.disableNotifications();
  317. $('body').popover("disable");
  318. JitsiPopover.enabled = false;
  319. }
  320. document.title = interfaceConfig.APP_NAME;
  321. if(config.requireDisplayName) {
  322. if (!APP.settings.getDisplayName()) {
  323. promptDisplayName();
  324. }
  325. }
  326. if (!interfaceConfig.filmStripOnly) {
  327. toastr.options = {
  328. "closeButton": true,
  329. "debug": false,
  330. "positionClass": "notification-bottom-right",
  331. "onclick": null,
  332. "showDuration": "300",
  333. "hideDuration": "1000",
  334. "timeOut": "2000",
  335. "extendedTimeOut": "1000",
  336. "showEasing": "swing",
  337. "hideEasing": "linear",
  338. "showMethod": "fadeIn",
  339. "hideMethod": "fadeOut",
  340. "reposition": function () {
  341. if (PanelToggler.isVisible()) {
  342. $("#toast-container").addClass("notification-bottom-right-center");
  343. } else {
  344. $("#toast-container").removeClass("notification-bottom-right-center");
  345. }
  346. },
  347. "newestOnTop": false
  348. };
  349. SettingsMenu.init(eventEmitter);
  350. }
  351. // Return true to indicate that the UI has been fully started and
  352. // conference ready.
  353. return true;
  354. };
  355. /**
  356. * Show local stream on UI.
  357. * @param {JitsiTrack} track stream to show
  358. */
  359. UI.addLocalStream = function (track) {
  360. switch (track.getType()) {
  361. case 'audio':
  362. VideoLayout.changeLocalAudio(track);
  363. break;
  364. case 'video':
  365. VideoLayout.changeLocalVideo(track);
  366. break;
  367. default:
  368. console.error("Unknown stream type: " + track.getType());
  369. break;
  370. }
  371. };
  372. /**
  373. * Show remote stream on UI.
  374. * @param {JitsiTrack} track stream to show
  375. */
  376. UI.addRemoteStream = function (track) {
  377. VideoLayout.onRemoteStreamAdded(track);
  378. };
  379. /**
  380. * Removed remote stream from UI.
  381. * @param {JitsiTrack} track stream to remove
  382. */
  383. UI.removeRemoteStream = function (track) {
  384. VideoLayout.onRemoteStreamRemoved(track);
  385. };
  386. function chatAddError(errorMessage, originalText) {
  387. return Chat.chatAddError(errorMessage, originalText);
  388. }
  389. /**
  390. * Update chat subject.
  391. * @param {string} subject new chat subject
  392. */
  393. UI.setSubject = function (subject) {
  394. Chat.setSubject(subject);
  395. };
  396. /**
  397. * Setup and show Etherpad.
  398. * @param {string} name etherpad id
  399. */
  400. UI.initEtherpad = function (name) {
  401. if (etherpadManager || !config.etherpad_base || !name) {
  402. return;
  403. }
  404. console.log('Etherpad is enabled');
  405. etherpadManager = new EtherpadManager(config.etherpad_base, name);
  406. Toolbar.showEtherpadButton();
  407. };
  408. /**
  409. * Show user on UI.
  410. * @param {string} id user id
  411. * @param {string} displayName user nickname
  412. */
  413. UI.addUser = function (id, displayName) {
  414. ContactList.addContact(id);
  415. messageHandler.notify(
  416. displayName,'notify.somebody', 'connected', 'notify.connected'
  417. );
  418. if (!config.startAudioMuted ||
  419. config.startAudioMuted > APP.conference.membersCount)
  420. UIUtil.playSoundNotification('userJoined');
  421. // Configure avatar
  422. UI.setUserAvatar(id);
  423. // Add Peer's container
  424. VideoLayout.addParticipantContainer(id);
  425. };
  426. /**
  427. * Remove user from UI.
  428. * @param {string} id user id
  429. * @param {string} displayName user nickname
  430. */
  431. UI.removeUser = function (id, displayName) {
  432. ContactList.removeContact(id);
  433. messageHandler.notify(
  434. displayName,'notify.somebody', 'disconnected', 'notify.disconnected'
  435. );
  436. if (!config.startAudioMuted
  437. || config.startAudioMuted > APP.conference.membersCount) {
  438. UIUtil.playSoundNotification('userLeft');
  439. }
  440. VideoLayout.removeParticipantContainer(id);
  441. };
  442. UI.updateUserStatus = function (id, status) {
  443. VideoLayout.setPresenceStatus(id, status);
  444. };
  445. /**
  446. * Update videotype for specified user.
  447. * @param {string} id user id
  448. * @param {string} newVideoType new videotype
  449. */
  450. UI.onPeerVideoTypeChanged = (id, newVideoType) => {
  451. VideoLayout.onVideoTypeChanged(id, newVideoType);
  452. };
  453. /**
  454. * Update local user role and show notification if user is moderator.
  455. * @param {boolean} isModerator if local user is moderator or not
  456. */
  457. UI.updateLocalRole = function (isModerator) {
  458. VideoLayout.showModeratorIndicator();
  459. Toolbar.showSipCallButton(isModerator);
  460. Toolbar.showRecordingButton(isModerator);
  461. SettingsMenu.showStartMutedOptions(isModerator);
  462. if (isModerator) {
  463. messageHandler.notify(null, "notify.me", 'connected', "notify.moderator");
  464. Toolbar.checkAutoRecord();
  465. }
  466. };
  467. /**
  468. * Check the role for the user and reflect it in the UI, moderator ui indication
  469. * and notifies user who is the moderator
  470. * @param user to check for moderator
  471. */
  472. UI.updateUserRole = function (user) {
  473. VideoLayout.showModeratorIndicator();
  474. if (!user.isModerator()) {
  475. return;
  476. }
  477. var displayName = user.getDisplayName();
  478. if (displayName) {
  479. messageHandler.notify(
  480. displayName, 'notify.somebody',
  481. 'connected', 'notify.grantedTo', {
  482. to: UIUtil.escapeHtml(displayName)
  483. }
  484. );
  485. } else {
  486. messageHandler.notify(
  487. '', 'notify.somebody',
  488. 'connected', 'notify.grantedToUnknown', {}
  489. );
  490. }
  491. };
  492. /**
  493. * Toggles smileys in the chat.
  494. */
  495. UI.toggleSmileys = function () {
  496. Chat.toggleSmileys();
  497. };
  498. /**
  499. * Toggles film strip.
  500. */
  501. UI.toggleFilmStrip = function () {
  502. var self = FilmStrip;
  503. self.toggleFilmStrip.apply(self, arguments);
  504. };
  505. /**
  506. * Toggles chat panel.
  507. */
  508. UI.toggleChat = function () {
  509. PanelToggler.toggleChat();
  510. };
  511. /**
  512. * Toggles contact list panel.
  513. */
  514. UI.toggleContactList = function () {
  515. PanelToggler.toggleContactList();
  516. };
  517. /**
  518. * Handle new user display name.
  519. */
  520. UI.inputDisplayNameHandler = function (newDisplayName) {
  521. eventEmitter.emit(UIEvents.NICKNAME_CHANGED, newDisplayName);
  522. };
  523. /**
  524. * Return the type of the remote video.
  525. * @param jid the jid for the remote video
  526. * @returns the video type video or screen.
  527. */
  528. UI.getRemoteVideoType = function (jid) {
  529. return VideoLayout.getRemoteVideoType(jid);
  530. };
  531. UI.connectionIndicatorShowMore = function(id) {
  532. VideoLayout.showMore(id);
  533. };
  534. // FIXME check if someone user this
  535. UI.showLoginPopup = function(callback) {
  536. console.log('password is required');
  537. var message = '<h2 data-i18n="dialog.passwordRequired">';
  538. message += APP.translation.translateString(
  539. "dialog.passwordRequired");
  540. message += '</h2>' +
  541. '<input name="username" type="text" ' +
  542. 'placeholder="user@domain.net" autofocus>' +
  543. '<input name="password" ' +
  544. 'type="password" data-i18n="[placeholder]dialog.userPassword"' +
  545. ' placeholder="user password">';
  546. messageHandler.openTwoButtonDialog(null, null, null, message,
  547. true,
  548. "dialog.Ok",
  549. function (e, v, m, f) {
  550. if (v) {
  551. if (f.username && f.password) {
  552. callback(f.username, f.password);
  553. }
  554. }
  555. },
  556. null, null, ':input:first'
  557. );
  558. };
  559. UI.askForNickname = function () {
  560. return window.prompt('Your nickname (optional)');
  561. };
  562. /**
  563. * Sets muted audio state for participant
  564. */
  565. UI.setAudioMuted = function (id, muted) {
  566. VideoLayout.onAudioMute(id, muted);
  567. if (APP.conference.isLocalId(id)) {
  568. Toolbar.markAudioIconAsMuted(muted);
  569. }
  570. };
  571. /**
  572. * Sets muted video state for participant
  573. */
  574. UI.setVideoMuted = function (id, muted) {
  575. VideoLayout.onVideoMute(id, muted);
  576. if (APP.conference.isLocalId(id)) {
  577. Toolbar.markVideoIconAsMuted(muted);
  578. }
  579. };
  580. UI.addListener = function (type, listener) {
  581. eventEmitter.on(type, listener);
  582. };
  583. UI.clickOnVideo = function (videoNumber) {
  584. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  585. if (remoteVideos.length > videoNumber) {
  586. remoteVideos[videoNumber].click();
  587. }
  588. };
  589. //Used by torture
  590. UI.showToolbar = function () {
  591. return ToolbarToggler.showToolbar();
  592. };
  593. //Used by torture
  594. UI.dockToolbar = function (isDock) {
  595. ToolbarToggler.dockToolbar(isDock);
  596. };
  597. /**
  598. * Update user avatar.
  599. * @param {string} id user id
  600. * @param {stirng} email user email
  601. */
  602. UI.setUserAvatar = function (id, email) {
  603. // update avatar
  604. Avatar.setUserAvatar(id, email);
  605. var avatarUrl = Avatar.getAvatarUrl(id);
  606. VideoLayout.changeUserAvatar(id, avatarUrl);
  607. ContactList.changeUserAvatar(id, avatarUrl);
  608. if (APP.conference.isLocalId(id)) {
  609. SettingsMenu.changeAvatar(avatarUrl);
  610. }
  611. };
  612. /**
  613. * Notify user that connection failed.
  614. * @param {string} stropheErrorMsg raw Strophe error message
  615. */
  616. UI.notifyConnectionFailed = function (stropheErrorMsg) {
  617. var title = APP.translation.generateTranslationHTML(
  618. "dialog.error");
  619. var message;
  620. if (stropheErrorMsg) {
  621. message = APP.translation.generateTranslationHTML(
  622. "dialog.connectErrorWithMsg", {msg: stropheErrorMsg});
  623. } else {
  624. message = APP.translation.generateTranslationHTML(
  625. "dialog.connectError");
  626. }
  627. messageHandler.openDialog(
  628. title, message, true, {}, function (e, v, m, f) { return false; }
  629. );
  630. };
  631. /**
  632. * Notify user that he was automatically muted when joned the conference.
  633. */
  634. UI.notifyInitiallyMuted = function () {
  635. messageHandler.notify(
  636. null, "notify.mutedTitle", "connected", "notify.muted", null, {timeOut: 120000}
  637. );
  638. };
  639. /**
  640. * Mark user as dominant speaker.
  641. * @param {string} id user id
  642. */
  643. UI.markDominantSpeaker = function (id) {
  644. VideoLayout.onDominantSpeakerChanged(id);
  645. };
  646. UI.handleLastNEndpoints = function (ids, enteringIds) {
  647. VideoLayout.onLastNEndpointsChanged(ids, enteringIds);
  648. };
  649. /**
  650. * Update audio level visualization for specified user.
  651. * @param {string} id user id
  652. * @param {number} lvl audio level
  653. */
  654. UI.setAudioLevel = function (id, lvl) {
  655. VideoLayout.setAudioLevel(id, lvl);
  656. };
  657. /**
  658. * Update state of desktop sharing buttons.
  659. */
  660. UI.updateDesktopSharingButtons = function () {
  661. Toolbar.updateDesktopSharingButtonState();
  662. };
  663. /**
  664. * Hide connection quality statistics from UI.
  665. */
  666. UI.hideStats = function () {
  667. VideoLayout.hideStats();
  668. };
  669. /**
  670. * Update local connection quality statistics.
  671. * @param {number} percent
  672. * @param {object} stats
  673. */
  674. UI.updateLocalStats = function (percent, stats) {
  675. VideoLayout.updateLocalConnectionStats(percent, stats);
  676. };
  677. /**
  678. * Update connection quality statistics for remote user.
  679. * @param {string} id user id
  680. * @param {number} percent
  681. * @param {object} stats
  682. */
  683. UI.updateRemoteStats = function (id, percent, stats) {
  684. VideoLayout.updateConnectionStats(id, percent, stats);
  685. };
  686. /**
  687. * Mark video as interrupted or not.
  688. * @param {boolean} interrupted if video is interrupted
  689. */
  690. UI.markVideoInterrupted = function (interrupted) {
  691. if (interrupted) {
  692. VideoLayout.onVideoInterrupted();
  693. } else {
  694. VideoLayout.onVideoRestored();
  695. }
  696. };
  697. /**
  698. * Mark room as locked or not.
  699. * @param {boolean} locked if room is locked.
  700. */
  701. UI.markRoomLocked = function (locked) {
  702. if (locked) {
  703. Toolbar.lockLockButton();
  704. } else {
  705. Toolbar.unlockLockButton();
  706. }
  707. };
  708. /**
  709. * Add chat message.
  710. * @param {string} from user id
  711. * @param {string} displayName user nickname
  712. * @param {string} message message text
  713. * @param {number} stamp timestamp when message was created
  714. */
  715. UI.addMessage = function (from, displayName, message, stamp) {
  716. Chat.updateChatConversation(from, displayName, message, stamp);
  717. };
  718. UI.updateDTMFSupport = function (isDTMFSupported) {
  719. //TODO: enable when the UI is ready
  720. //Toolbar.showDialPadButton(dtmfSupport);
  721. };
  722. /**
  723. * Invite participants to conference.
  724. * @param {string} roomUrl
  725. * @param {string} conferenceName
  726. * @param {string} key
  727. * @param {string} nick
  728. */
  729. UI.inviteParticipants = function (roomUrl, conferenceName, key, nick) {
  730. let keyText = "";
  731. if (key) {
  732. keyText = APP.translation.translateString(
  733. "email.sharedKey", {sharedKey: key}
  734. );
  735. }
  736. let and = APP.translation.translateString("email.and");
  737. let supportedBrowsers = `Chromium, Google Chrome ${and} Opera`;
  738. let subject = APP.translation.translateString(
  739. "email.subject", {appName:interfaceConfig.APP_NAME, conferenceName}
  740. );
  741. let body = APP.translation.translateString(
  742. "email.body", {
  743. appName:interfaceConfig.APP_NAME,
  744. sharedKeyText: keyText,
  745. roomUrl,
  746. supportedBrowsers
  747. }
  748. );
  749. body = body.replace(/\n/g, "%0D%0A");
  750. if (nick) {
  751. body += "%0D%0A%0D%0A" + UIUtil.escapeHtml(nick);
  752. }
  753. if (interfaceConfig.INVITATION_POWERED_BY) {
  754. body += "%0D%0A%0D%0A--%0D%0Apowered by jitsi.org";
  755. }
  756. window.open(`mailto:?subject=${subject}&body=${body}`, '_blank');
  757. };
  758. /**
  759. * Show user feedback dialog if its required or just show "thank you" dialog.
  760. * @returns {Promise} when dialog is closed.
  761. */
  762. UI.requestFeedback = function () {
  763. return new Promise(function (resolve, reject) {
  764. if (Feedback.isEnabled()) {
  765. // If the user has already entered feedback, we'll show the window and
  766. // immidiately start the conference dispose timeout.
  767. if (Feedback.feedbackScore > 0) {
  768. Feedback.openFeedbackWindow();
  769. resolve();
  770. } else { // Otherwise we'll wait for user's feedback.
  771. Feedback.openFeedbackWindow(resolve);
  772. }
  773. } else {
  774. // If the feedback functionality isn't enabled we show a thank you
  775. // dialog.
  776. messageHandler.openMessageDialog(
  777. null, null, null,
  778. APP.translation.translateString(
  779. "dialog.thankYou", {appName:interfaceConfig.APP_NAME}
  780. )
  781. );
  782. resolve();
  783. }
  784. });
  785. };
  786. /**
  787. * Request recording token from the user.
  788. * @returns {Promise}
  789. */
  790. UI.requestRecordingToken = function () {
  791. let msg = APP.translation.generateTranslationHTML("dialog.recordingToken");
  792. let token = APP.translation.translateString("dialog.token");
  793. return new Promise(function (resolve, reject) {
  794. messageHandler.openTwoButtonDialog(
  795. null, null, null,
  796. `<h2>${msg}</h2>
  797. <input name="recordingToken" type="text"
  798. data-i18n="[placeholder]dialog.token"
  799. placeholder="${token}" autofocus>`,
  800. false, "dialog.Save",
  801. function (e, v, m, f) {
  802. if (v && f.recordingToken) {
  803. resolve(UIUtil.escapeHtml(f.recordingToken));
  804. } else {
  805. reject();
  806. }
  807. },
  808. null,
  809. function () { },
  810. ':input:first'
  811. );
  812. });
  813. };
  814. UI.updateRecordingState = function (state) {
  815. Toolbar.updateRecordingState(state);
  816. };
  817. UI.notifyTokenAuthFailed = function () {
  818. messageHandler.showError("dialog.error", "dialog.tokenAuthFailed");
  819. };
  820. UI.notifyInternalError = function () {
  821. messageHandler.showError("dialog.sorry", "dialog.internalError");
  822. };
  823. UI.notifyFocusDisconnected = function (focus, retrySec) {
  824. messageHandler.notify(
  825. null, "notify.focus",
  826. 'disconnected', "notify.focusFail",
  827. {component: focus, ms: retrySec}
  828. );
  829. };
  830. /**
  831. * Notify user that focus left the conference so page should be reloaded.
  832. */
  833. UI.notifyFocusLeft = function () {
  834. let title = APP.translation.generateTranslationHTML(
  835. 'dialog.serviceUnavailable'
  836. );
  837. let msg = APP.translation.generateTranslationHTML(
  838. 'dialog.jicofoUnavailable'
  839. );
  840. messageHandler.openDialog(
  841. title,
  842. msg,
  843. true, // persistent
  844. [{title: 'retry'}],
  845. function () {
  846. reload();
  847. return false;
  848. }
  849. );
  850. };
  851. /**
  852. * Updates auth info on the UI.
  853. * @param {boolean} isAuthEnabled if authentication is enabled
  854. * @param {string} [login] current login
  855. */
  856. UI.updateAuthInfo = function (isAuthEnabled, login) {
  857. let loggedIn = !!login;
  858. Toolbar.showAuthenticateButton(isAuthEnabled);
  859. if (isAuthEnabled) {
  860. Toolbar.setAuthenticatedIdentity(login);
  861. Toolbar.showLoginButton(!loggedIn);
  862. Toolbar.showLogoutButton(loggedIn);
  863. }
  864. };
  865. /**
  866. * Show Prezi from the user.
  867. * @param {string} userId user id
  868. * @param {string} url Prezi url
  869. * @param {number} slide slide to show
  870. */
  871. UI.showPrezi = function (userId, url, slide) {
  872. preziManager.showPrezi(userId, url, slide);
  873. };
  874. /**
  875. * Stop showing Prezi from the user.
  876. * @param {string} userId user id
  877. */
  878. UI.stopPrezi = function (userId) {
  879. if (preziManager.isSharing(userId)) {
  880. preziManager.removePrezi(userId);
  881. }
  882. };
  883. UI.onStartMutedChanged = function (startAudioMuted, startVideoMuted) {
  884. SettingsMenu.updateStartMutedBox(startAudioMuted, startVideoMuted);
  885. };
  886. /**
  887. * Update list of available physical devices.
  888. * @param {object[]} devices new list of available devices
  889. */
  890. UI.onAvailableDevicesChanged = function (devices) {
  891. SettingsMenu.changeDevicesList(devices);
  892. };
  893. /**
  894. * Returns the id of the current video shown on large.
  895. * Currently used by tests (torture).
  896. */
  897. UI.getLargeVideoID = function () {
  898. return VideoLayout.getLargeVideoID();
  899. };
  900. /**
  901. * Shows dialog with a link to FF extension.
  902. */
  903. UI.showExtensionRequiredDialog = function (url) {
  904. messageHandler.openMessageDialog(
  905. "dialog.extensionRequired",
  906. null,
  907. null,
  908. APP.translation.generateTranslationHTML(
  909. "dialog.firefoxExtensionPrompt", {url: url}));
  910. };
  911. UI.updateDevicesAvailability = function (id, devices) {
  912. VideoLayout.setDeviceAvailabilityIcons(id, devices);
  913. };
  914. module.exports = UI;