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

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