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

UI.js 28KB

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