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.

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