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

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