Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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