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

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