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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  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. let id = APP.conference.localId;
  205. Toolbar.updateRoomUrl(window.location.href);
  206. let meHTML = APP.translation.generateTranslationHTML("me");
  207. let email = Settings.getEmail();
  208. $("#localNick").html(email || `${id} (${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. let displayName = config.displayJids ? id : Settings.getDisplayName();
  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, 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. /**
  385. * Removed remote stream from UI.
  386. * @param {JitsiTrack} track stream to remove
  387. */
  388. UI.removeRemoteStream = function (track) {
  389. VideoLayout.onRemoteStreamRemoved(track);
  390. };
  391. function chatAddError(errorMessage, originalText) {
  392. return Chat.chatAddError(errorMessage, originalText);
  393. }
  394. /**
  395. * Update chat subject.
  396. * @param {string} subject new chat subject
  397. */
  398. UI.setSubject = function (subject) {
  399. Chat.setSubject(subject);
  400. };
  401. /**
  402. * Setup and show Etherpad.
  403. * @param {string} name etherpad id
  404. */
  405. UI.initEtherpad = function (name) {
  406. if (etherpadManager || !config.etherpad_base || !name) {
  407. return;
  408. }
  409. console.log('Etherpad is enabled');
  410. etherpadManager = new EtherpadManager(config.etherpad_base, name);
  411. Toolbar.showEtherpadButton();
  412. };
  413. /**
  414. * Show user on UI.
  415. * @param {string} id user id
  416. * @param {string} displayName user nickname
  417. */
  418. UI.addUser = function (id, displayName) {
  419. ContactList.addContact(id);
  420. messageHandler.notify(
  421. displayName,'notify.somebody', 'connected', 'notify.connected'
  422. );
  423. if (!config.startAudioMuted ||
  424. config.startAudioMuted > APP.conference.membersCount)
  425. UIUtil.playSoundNotification('userJoined');
  426. // Configure avatar
  427. UI.setUserAvatar(id);
  428. // Add Peer's container
  429. VideoLayout.addParticipantContainer(id);
  430. };
  431. /**
  432. * Remove user from UI.
  433. * @param {string} id user id
  434. * @param {string} displayName user nickname
  435. */
  436. UI.removeUser = function (id, displayName) {
  437. ContactList.removeContact(id);
  438. messageHandler.notify(
  439. displayName,'notify.somebody', 'disconnected', 'notify.disconnected'
  440. );
  441. if (!config.startAudioMuted
  442. || config.startAudioMuted > APP.conference.membersCount) {
  443. UIUtil.playSoundNotification('userLeft');
  444. }
  445. VideoLayout.removeParticipantContainer(id);
  446. };
  447. UI.updateUserStatus = function (id, status) {
  448. VideoLayout.setPresenceStatus(id, status);
  449. };
  450. /**
  451. * Update videotype for specified user.
  452. * @param {string} id user id
  453. * @param {string} newVideoType new videotype
  454. */
  455. UI.onPeerVideoTypeChanged = (id, newVideoType) => {
  456. VideoLayout.onVideoTypeChanged(id, newVideoType);
  457. };
  458. /**
  459. * Update local user role and show notification if user is moderator.
  460. * @param {boolean} isModerator if local user is moderator or not
  461. */
  462. UI.updateLocalRole = function (isModerator) {
  463. VideoLayout.showModeratorIndicator();
  464. Toolbar.showSipCallButton(isModerator);
  465. Toolbar.showRecordingButton(isModerator);
  466. SettingsMenu.onRoleChanged();
  467. if (isModerator) {
  468. messageHandler.notify(null, "notify.me", 'connected', "notify.moderator");
  469. Toolbar.checkAutoRecord();
  470. }
  471. };
  472. /**
  473. * Check the role for the user and reflect it in the UI, moderator ui indication
  474. * and notifies user who is the moderator
  475. * @param user to check for moderator
  476. */
  477. UI.updateUserRole = function (user) {
  478. VideoLayout.showModeratorIndicator();
  479. if (!user.isModerator()) {
  480. return;
  481. }
  482. var displayName = user.getDisplayName();
  483. if (displayName) {
  484. messageHandler.notify(
  485. displayName, 'notify.somebody',
  486. 'connected', 'notify.grantedTo', {
  487. to: UIUtil.escapeHtml(displayName)
  488. }
  489. );
  490. } else {
  491. messageHandler.notify(
  492. '', 'notify.somebody',
  493. 'connected', 'notify.grantedToUnknown', {}
  494. );
  495. }
  496. };
  497. /**
  498. * Toggles smileys in the chat.
  499. */
  500. UI.toggleSmileys = function () {
  501. Chat.toggleSmileys();
  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. /**
  522. * Handle new user display name.
  523. */
  524. UI.inputDisplayNameHandler = function (newDisplayName) {
  525. eventEmitter.emit(UIEvents.NICKNAME_CHANGED, newDisplayName);
  526. };
  527. /**
  528. * Return the type of the remote video.
  529. * @param jid the jid for the remote video
  530. * @returns the video type video or screen.
  531. */
  532. UI.getRemoteVideoType = function (jid) {
  533. return VideoLayout.getRemoteVideoType(jid);
  534. };
  535. UI.connectionIndicatorShowMore = function(id) {
  536. VideoLayout.showMore(id);
  537. };
  538. // FIXME check if someone user this
  539. UI.showLoginPopup = function(callback) {
  540. console.log('password is required');
  541. var message = '<h2 data-i18n="dialog.passwordRequired">';
  542. message += APP.translation.translateString(
  543. "dialog.passwordRequired");
  544. message += '</h2>' +
  545. '<input name="username" type="text" ' +
  546. 'placeholder="user@domain.net" autofocus>' +
  547. '<input name="password" ' +
  548. 'type="password" data-i18n="[placeholder]dialog.userPassword"' +
  549. ' placeholder="user password">';
  550. messageHandler.openTwoButtonDialog(null, null, null, message,
  551. true,
  552. "dialog.Ok",
  553. function (e, v, m, f) {
  554. if (v) {
  555. if (f.username && f.password) {
  556. callback(f.username, f.password);
  557. }
  558. }
  559. },
  560. null, null, ':input:first'
  561. );
  562. };
  563. UI.askForNickname = function () {
  564. return window.prompt('Your nickname (optional)');
  565. };
  566. /**
  567. * Sets muted audio state for participant
  568. */
  569. UI.setAudioMuted = function (id, muted) {
  570. VideoLayout.onAudioMute(id, muted);
  571. if (APP.conference.isLocalId(id)) {
  572. Toolbar.markAudioIconAsMuted(muted);
  573. }
  574. };
  575. /**
  576. * Sets muted video state for participant
  577. */
  578. UI.setVideoMuted = function (id, muted) {
  579. VideoLayout.onVideoMute(id, muted);
  580. if (APP.conference.isLocalId(id)) {
  581. Toolbar.markVideoIconAsMuted(muted);
  582. }
  583. };
  584. UI.addListener = function (type, listener) {
  585. eventEmitter.on(type, listener);
  586. };
  587. UI.clickOnVideo = function (videoNumber) {
  588. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  589. if (remoteVideos.length > videoNumber) {
  590. remoteVideos[videoNumber].click();
  591. }
  592. };
  593. //Used by torture
  594. UI.showToolbar = function () {
  595. return ToolbarToggler.showToolbar();
  596. };
  597. //Used by torture
  598. UI.dockToolbar = function (isDock) {
  599. ToolbarToggler.dockToolbar(isDock);
  600. };
  601. /**
  602. * Update user avatar.
  603. * @param {string} id user id
  604. * @param {stirng} email user email
  605. */
  606. UI.setUserAvatar = function (id, email) {
  607. // update avatar
  608. Avatar.setUserAvatar(id, email);
  609. var avatarUrl = Avatar.getAvatarUrl(id);
  610. VideoLayout.changeUserAvatar(id, avatarUrl);
  611. ContactList.changeUserAvatar(id, avatarUrl);
  612. if (APP.conference.isLocalId(id)) {
  613. SettingsMenu.changeAvatar(avatarUrl);
  614. }
  615. };
  616. /**
  617. * Notify user that connection failed.
  618. * @param {string} stropheErrorMsg raw Strophe error message
  619. */
  620. UI.notifyConnectionFailed = function (stropheErrorMsg) {
  621. var title = APP.translation.generateTranslationHTML(
  622. "dialog.error");
  623. var message;
  624. if (stropheErrorMsg) {
  625. message = APP.translation.generateTranslationHTML(
  626. "dialog.connectErrorWithMsg", {msg: stropheErrorMsg});
  627. } else {
  628. message = APP.translation.generateTranslationHTML(
  629. "dialog.connectError");
  630. }
  631. messageHandler.openDialog(
  632. title, message, true, {}, function (e, v, m, f) { return false; }
  633. );
  634. };
  635. /**
  636. * Notify user that he need to install Firefox extension to share screen.
  637. * @param {stirng} url extension url
  638. */
  639. UI.notifyFirefoxExtensionRequired = function (url) {
  640. messageHandler.openMessageDialog(
  641. "dialog.extensionRequired",
  642. null,
  643. null,
  644. APP.translation.generateTranslationHTML(
  645. "dialog.firefoxExtensionPrompt", {url}
  646. )
  647. );
  648. };
  649. /**
  650. * Notify user that he was automatically muted when joned the conference.
  651. */
  652. UI.notifyInitiallyMuted = function () {
  653. messageHandler.notify(
  654. null, "notify.mutedTitle", "connected", "notify.muted", null, {timeOut: 120000}
  655. );
  656. };
  657. /**
  658. * Mark user as dominant speaker.
  659. * @param {string} id user id
  660. */
  661. UI.markDominantSpeaker = function (id) {
  662. VideoLayout.onDominantSpeakerChanged(id);
  663. };
  664. UI.handleLastNEndpoints = function (ids, enteringIds) {
  665. VideoLayout.onLastNEndpointsChanged(ids, enteringIds);
  666. };
  667. /**
  668. * Update audio level visualization for specified user.
  669. * @param {string} id user id
  670. * @param {number} lvl audio level
  671. */
  672. UI.setAudioLevel = function (id, lvl) {
  673. VideoLayout.setAudioLevel(id, lvl);
  674. };
  675. /**
  676. * Update state of desktop sharing buttons.
  677. */
  678. UI.updateDesktopSharingButtons = function () {
  679. Toolbar.updateDesktopSharingButtonState();
  680. };
  681. /**
  682. * Hide connection quality statistics from UI.
  683. */
  684. UI.hideStats = function () {
  685. VideoLayout.hideStats();
  686. };
  687. /**
  688. * Update local connection quality statistics.
  689. * @param {number} percent
  690. * @param {object} stats
  691. */
  692. UI.updateLocalStats = function (percent, stats) {
  693. VideoLayout.updateLocalConnectionStats(percent, stats);
  694. };
  695. /**
  696. * Update connection quality statistics for remote user.
  697. * @param {string} id user id
  698. * @param {number} percent
  699. * @param {object} stats
  700. */
  701. UI.updateRemoteStats = function (id, percent, stats) {
  702. VideoLayout.updateConnectionStats(id, percent, stats);
  703. };
  704. /**
  705. * Mark video as interrupted or not.
  706. * @param {boolean} interrupted if video is interrupted
  707. */
  708. UI.markVideoInterrupted = function (interrupted) {
  709. if (interrupted) {
  710. VideoLayout.onVideoInterrupted();
  711. } else {
  712. VideoLayout.onVideoRestored();
  713. }
  714. };
  715. /**
  716. * Mark room as locked or not.
  717. * @param {boolean} locked if room is locked.
  718. */
  719. UI.markRoomLocked = function (locked) {
  720. if (locked) {
  721. Toolbar.lockLockButton();
  722. } else {
  723. Toolbar.unlockLockButton();
  724. }
  725. };
  726. /**
  727. * Add chat message.
  728. * @param {string} from user id
  729. * @param {string} displayName user nickname
  730. * @param {string} message message text
  731. * @param {number} stamp timestamp when message was created
  732. */
  733. UI.addMessage = function (from, displayName, message, stamp) {
  734. Chat.updateChatConversation(from, displayName, message, stamp);
  735. };
  736. UI.updateDTMFSupport = function (isDTMFSupported) {
  737. //TODO: enable when the UI is ready
  738. //Toolbar.showDialPadButton(dtmfSupport);
  739. };
  740. /**
  741. * Invite participants to conference.
  742. * @param {string} roomUrl
  743. * @param {string} conferenceName
  744. * @param {string} key
  745. * @param {string} nick
  746. */
  747. UI.inviteParticipants = function (roomUrl, conferenceName, key, nick) {
  748. let keyText = "";
  749. if (key) {
  750. keyText = APP.translation.translateString(
  751. "email.sharedKey", {sharedKey: key}
  752. );
  753. }
  754. let and = APP.translation.translateString("email.and");
  755. let supportedBrowsers = `Chromium, Google Chrome ${and} Opera`;
  756. let subject = APP.translation.translateString(
  757. "email.subject", {appName:interfaceConfig.APP_NAME, conferenceName}
  758. );
  759. let body = APP.translation.translateString(
  760. "email.body", {
  761. appName:interfaceConfig.APP_NAME,
  762. sharedKeyText: keyText,
  763. roomUrl,
  764. supportedBrowsers
  765. }
  766. );
  767. body = body.replace(/\n/g, "%0D%0A");
  768. if (nick) {
  769. body += "%0D%0A%0D%0A" + UIUtil.escapeHtml(nick);
  770. }
  771. if (interfaceConfig.INVITATION_POWERED_BY) {
  772. body += "%0D%0A%0D%0A--%0D%0Apowered by jitsi.org";
  773. }
  774. window.open(`mailto:?subject=${subject}&body=${body}`, '_blank');
  775. };
  776. /**
  777. * Show user feedback dialog if its required or just show "thank you" dialog.
  778. * @returns {Promise} when dialog is closed.
  779. */
  780. UI.requestFeedback = function () {
  781. return new Promise(function (resolve, reject) {
  782. if (Feedback.isEnabled()) {
  783. // If the user has already entered feedback, we'll show the window and
  784. // immidiately start the conference dispose timeout.
  785. if (Feedback.feedbackScore > 0) {
  786. Feedback.openFeedbackWindow();
  787. resolve();
  788. } else { // Otherwise we'll wait for user's feedback.
  789. Feedback.openFeedbackWindow(resolve);
  790. }
  791. } else {
  792. // If the feedback functionality isn't enabled we show a thank you
  793. // dialog.
  794. messageHandler.openMessageDialog(
  795. null, null, null,
  796. APP.translation.translateString(
  797. "dialog.thankYou", {appName:interfaceConfig.APP_NAME}
  798. )
  799. );
  800. resolve();
  801. }
  802. });
  803. };
  804. /**
  805. * Request recording token from the user.
  806. * @returns {Promise}
  807. */
  808. UI.requestRecordingToken = function () {
  809. let msg = APP.translation.generateTranslationHTML("dialog.recordingToken");
  810. let token = APP.translation.translateString("dialog.token");
  811. return new Promise(function (resolve, reject) {
  812. messageHandler.openTwoButtonDialog(
  813. null, null, null,
  814. `<h2>${msg}</h2>
  815. <input name="recordingToken" type="text"
  816. data-i18n="[placeholder]dialog.token"
  817. placeholder="${token}" autofocus>`,
  818. false, "dialog.Save",
  819. function (e, v, m, f) {
  820. if (v && f.recordingToken) {
  821. resolve(UIUtil.escapeHtml(f.recordingToken));
  822. } else {
  823. reject();
  824. }
  825. },
  826. null,
  827. function () { },
  828. ':input:first'
  829. );
  830. });
  831. };
  832. UI.updateRecordingState = function (state) {
  833. Toolbar.updateRecordingState(state);
  834. };
  835. UI.notifyTokenAuthFailed = function () {
  836. messageHandler.showError("dialog.error", "dialog.tokenAuthFailed");
  837. };
  838. UI.notifyInternalError = function () {
  839. messageHandler.showError("dialog.sorry", "dialog.internalError");
  840. };
  841. UI.notifyFocusDisconnected = function (focus, retrySec) {
  842. messageHandler.notify(
  843. null, "notify.focus",
  844. 'disconnected', "notify.focusFail",
  845. {component: focus, ms: retrySec}
  846. );
  847. };
  848. /**
  849. * Notify user that focus left the conference so page should be reloaded.
  850. */
  851. UI.notifyFocusLeft = function () {
  852. let title = APP.translation.generateTranslationHTML(
  853. 'dialog.serviceUnavailable'
  854. );
  855. let msg = APP.translation.generateTranslationHTML(
  856. 'dialog.jicofoUnavailable'
  857. );
  858. messageHandler.openDialog(
  859. title,
  860. msg,
  861. true, // persistent
  862. [{title: 'retry'}],
  863. function () {
  864. reload();
  865. return false;
  866. }
  867. );
  868. };
  869. /**
  870. * Updates auth info on the UI.
  871. * @param {boolean} isAuthEnabled if authentication is enabled
  872. * @param {string} [login] current login
  873. */
  874. UI.updateAuthInfo = function (isAuthEnabled, login) {
  875. let loggedIn = !!login;
  876. Toolbar.showAuthenticateButton(isAuthEnabled);
  877. if (isAuthEnabled) {
  878. Toolbar.setAuthenticatedIdentity(login);
  879. Toolbar.showLoginButton(!loggedIn);
  880. Toolbar.showLogoutButton(loggedIn);
  881. }
  882. };
  883. /**
  884. * Show Prezi from the user.
  885. * @param {string} userId user id
  886. * @param {string} url Prezi url
  887. * @param {number} slide slide to show
  888. */
  889. UI.showPrezi = function (userId, url, slide) {
  890. preziManager.showPrezi(userId, url, slide);
  891. };
  892. /**
  893. * Stop showing Prezi from the user.
  894. * @param {string} userId user id
  895. */
  896. UI.stopPrezi = function (userId) {
  897. if (preziManager.isSharing(userId)) {
  898. preziManager.removePrezi(userId);
  899. }
  900. };
  901. UI.onStartMutedChanged = function () {
  902. SettingsMenu.onStartMutedChanged();
  903. };
  904. /**
  905. * Update list of available physical devices.
  906. * @param {object[]} devices new list of available devices
  907. */
  908. UI.onAvailableDevicesChanged = function (devices) {
  909. SettingsMenu.onAvailableDevicesChanged(devices);
  910. };
  911. /**
  912. * Returns the id of the current video shown on large.
  913. * Currently used by tests (torture).
  914. */
  915. UI.getLargeVideoID = function () {
  916. return VideoLayout.getLargeVideoID();
  917. };
  918. /**
  919. * Shows dialog with a link to FF extension.
  920. */
  921. UI.showExtensionRequiredDialog = function (url) {
  922. messageHandler.openMessageDialog(
  923. "dialog.extensionRequired",
  924. null,
  925. null,
  926. APP.translation.generateTranslationHTML(
  927. "dialog.firefoxExtensionPrompt", {url: url}));
  928. };
  929. UI.updateDevicesAvailability = function (id, devices) {
  930. VideoLayout.setDeviceAvailabilityIcons(id, devices);
  931. };
  932. module.exports = UI;