您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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