選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

UI.js 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  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. * @param {boolean} isSharingScreen if user is currently sharing his screen
  674. */
  675. UI.updateDesktopSharingButtons = function (isSharingScreen) {
  676. Toolbar.changeDesktopSharingButtonState(isSharingScreen);
  677. };
  678. /**
  679. * Hide connection quality statistics from UI.
  680. */
  681. UI.hideStats = function () {
  682. VideoLayout.hideStats();
  683. };
  684. /**
  685. * Update local connection quality statistics.
  686. * @param {number} percent
  687. * @param {object} stats
  688. */
  689. UI.updateLocalStats = function (percent, stats) {
  690. VideoLayout.updateLocalConnectionStats(percent, stats);
  691. };
  692. /**
  693. * Update connection quality statistics for remote user.
  694. * @param {string} id user id
  695. * @param {number} percent
  696. * @param {object} stats
  697. */
  698. UI.updateRemoteStats = function (id, percent, stats) {
  699. VideoLayout.updateConnectionStats(id, percent, stats);
  700. };
  701. /**
  702. * Mark video as interrupted or not.
  703. * @param {boolean} interrupted if video is interrupted
  704. */
  705. UI.markVideoInterrupted = function (interrupted) {
  706. if (interrupted) {
  707. VideoLayout.onVideoInterrupted();
  708. } else {
  709. VideoLayout.onVideoRestored();
  710. }
  711. };
  712. /**
  713. * Mark room as locked or not.
  714. * @param {boolean} locked if room is locked.
  715. */
  716. UI.markRoomLocked = function (locked) {
  717. if (locked) {
  718. Toolbar.lockLockButton();
  719. } else {
  720. Toolbar.unlockLockButton();
  721. }
  722. };
  723. /**
  724. * Add chat message.
  725. * @param {string} from user id
  726. * @param {string} displayName user nickname
  727. * @param {string} message message text
  728. * @param {number} stamp timestamp when message was created
  729. */
  730. UI.addMessage = function (from, displayName, message, stamp) {
  731. Chat.updateChatConversation(from, displayName, message, stamp);
  732. };
  733. UI.updateDTMFSupport = function (isDTMFSupported) {
  734. //TODO: enable when the UI is ready
  735. //Toolbar.showDialPadButton(dtmfSupport);
  736. };
  737. /**
  738. * Invite participants to conference.
  739. * @param {string} roomUrl
  740. * @param {string} conferenceName
  741. * @param {string} key
  742. * @param {string} nick
  743. */
  744. UI.inviteParticipants = function (roomUrl, conferenceName, key, nick) {
  745. let keyText = "";
  746. if (key) {
  747. keyText = APP.translation.translateString(
  748. "email.sharedKey", {sharedKey: key}
  749. );
  750. }
  751. let and = APP.translation.translateString("email.and");
  752. let supportedBrowsers = `Chromium, Google Chrome ${and} Opera`;
  753. let subject = APP.translation.translateString(
  754. "email.subject", {appName:interfaceConfig.APP_NAME, conferenceName}
  755. );
  756. let body = APP.translation.translateString(
  757. "email.body", {
  758. appName:interfaceConfig.APP_NAME,
  759. sharedKeyText: keyText,
  760. roomUrl,
  761. supportedBrowsers
  762. }
  763. );
  764. body = body.replace(/\n/g, "%0D%0A");
  765. if (nick) {
  766. body += "%0D%0A%0D%0A" + nick;
  767. }
  768. if (interfaceConfig.INVITATION_POWERED_BY) {
  769. body += "%0D%0A%0D%0A--%0D%0Apowered by jitsi.org";
  770. }
  771. window.open(`mailto:?subject=${subject}&body=${body}`, '_blank');
  772. };
  773. /**
  774. * Show user feedback dialog if its required or just show "thank you" dialog.
  775. * @returns {Promise} when dialog is closed.
  776. */
  777. UI.requestFeedback = function () {
  778. return new Promise(function (resolve, reject) {
  779. if (Feedback.isEnabled()) {
  780. // If the user has already entered feedback, we'll show the window and
  781. // immidiately start the conference dispose timeout.
  782. if (Feedback.feedbackScore > 0) {
  783. Feedback.openFeedbackWindow();
  784. resolve();
  785. } else { // Otherwise we'll wait for user's feedback.
  786. Feedback.openFeedbackWindow(resolve);
  787. }
  788. } else {
  789. // If the feedback functionality isn't enabled we show a thank you
  790. // dialog.
  791. messageHandler.openMessageDialog(
  792. null, null, null,
  793. APP.translation.translateString(
  794. "dialog.thankYou", {appName:interfaceConfig.APP_NAME}
  795. )
  796. );
  797. resolve();
  798. }
  799. });
  800. };
  801. /**
  802. * Request recording token from the user.
  803. * @returns {Promise}
  804. */
  805. UI.requestRecordingToken = function () {
  806. let msg = APP.translation.generateTranslationHTML("dialog.recordingToken");
  807. let token = APP.translation.translateString("dialog.token");
  808. return new Promise(function (resolve, reject) {
  809. messageHandler.openTwoButtonDialog(
  810. null, null, null,
  811. `<h2>${msg}</h2>
  812. <input name="recordingToken" type="text"
  813. data-i18n="[placeholder]dialog.token"
  814. placeholder="${token}" autofocus>`,
  815. false, "dialog.Save",
  816. function (e, v, m, f) {
  817. if (v && f.recordingToken) {
  818. resolve(UIUtil.escapeHtml(f.recordingToken));
  819. } else {
  820. reject();
  821. }
  822. },
  823. null,
  824. function () { },
  825. ':input:first'
  826. );
  827. });
  828. };
  829. UI.updateRecordingState = function (state) {
  830. Toolbar.updateRecordingState(state);
  831. };
  832. UI.notifyTokenAuthFailed = function () {
  833. messageHandler.showError("dialog.error", "dialog.tokenAuthFailed");
  834. };
  835. UI.notifyInternalError = function () {
  836. messageHandler.showError("dialog.sorry", "dialog.internalError");
  837. };
  838. UI.notifyFocusDisconnected = function (focus, retrySec) {
  839. messageHandler.notify(
  840. null, "notify.focus",
  841. 'disconnected', "notify.focusFail",
  842. {component: focus, ms: retrySec}
  843. );
  844. };
  845. /**
  846. * Notify user that focus left the conference so page should be reloaded.
  847. */
  848. UI.notifyFocusLeft = function () {
  849. let title = APP.translation.generateTranslationHTML(
  850. 'dialog.serviceUnavailable'
  851. );
  852. let msg = APP.translation.generateTranslationHTML(
  853. 'dialog.jicofoUnavailable'
  854. );
  855. messageHandler.openDialog(
  856. title,
  857. msg,
  858. true, // persistent
  859. [{title: 'retry'}],
  860. function () {
  861. reload();
  862. return false;
  863. }
  864. );
  865. };
  866. /**
  867. * Updates auth info on the UI.
  868. * @param {boolean} isAuthEnabled if authentication is enabled
  869. * @param {string} [login] current login
  870. */
  871. UI.updateAuthInfo = function (isAuthEnabled, login) {
  872. let loggedIn = !!login;
  873. Toolbar.showAuthenticateButton(isAuthEnabled);
  874. if (isAuthEnabled) {
  875. Toolbar.setAuthenticatedIdentity(login);
  876. Toolbar.showLoginButton(!loggedIn);
  877. Toolbar.showLogoutButton(loggedIn);
  878. }
  879. };
  880. /**
  881. * Show Prezi from the user.
  882. * @param {string} userId user id
  883. * @param {string} url Prezi url
  884. * @param {number} slide slide to show
  885. */
  886. UI.showPrezi = function (userId, url, slide) {
  887. preziManager.showPrezi(userId, url, slide);
  888. };
  889. /**
  890. * Stop showing Prezi from the user.
  891. * @param {string} userId user id
  892. */
  893. UI.stopPrezi = function (userId) {
  894. if (preziManager.isSharing(userId)) {
  895. preziManager.removePrezi(userId);
  896. }
  897. };
  898. UI.onStartMutedChanged = function () {
  899. SettingsMenu.onStartMutedChanged();
  900. };
  901. /**
  902. * Returns the id of the current video shown on large.
  903. * Currently used by tests (torture).
  904. */
  905. UI.getLargeVideoID = function () {
  906. return VideoLayout.getLargeVideoID();
  907. };
  908. /**
  909. * Shows dialog with a link to FF extension.
  910. */
  911. UI.showExtensionRequiredDialog = function (url) {
  912. messageHandler.openMessageDialog(
  913. "dialog.extensionRequired",
  914. null,
  915. null,
  916. APP.translation.generateTranslationHTML(
  917. "dialog.firefoxExtensionPrompt", {url: url}));
  918. };
  919. UI.updateDevicesAvailability = function (id, devices) {
  920. VideoLayout.setDeviceAvailabilityIcons(id, devices);
  921. };
  922. module.exports = UI;