You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UI.js 30KB

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