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

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