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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  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 max users limit is already reached.
  632. */
  633. UI.notifyMaxUsersLimitReached = function () {
  634. var title = APP.translation.generateTranslationHTML(
  635. "dialog.error");
  636. var message = APP.translation.generateTranslationHTML(
  637. "dialog.maxUsersLimitReached");
  638. messageHandler.openDialog(
  639. title, message, true, {}, function (e, v, m, f) { return false; }
  640. );
  641. };
  642. /**
  643. * Notify user that he was automatically muted when joned the conference.
  644. */
  645. UI.notifyInitiallyMuted = function () {
  646. messageHandler.notify(
  647. null, "notify.mutedTitle", "connected", "notify.muted", null, {timeOut: 120000}
  648. );
  649. };
  650. /**
  651. * Mark user as dominant speaker.
  652. * @param {string} id user id
  653. */
  654. UI.markDominantSpeaker = function (id) {
  655. VideoLayout.onDominantSpeakerChanged(id);
  656. };
  657. UI.handleLastNEndpoints = function (ids, enteringIds) {
  658. VideoLayout.onLastNEndpointsChanged(ids, enteringIds);
  659. };
  660. /**
  661. * Update audio level visualization for specified user.
  662. * @param {string} id user id
  663. * @param {number} lvl audio level
  664. */
  665. UI.setAudioLevel = function (id, lvl) {
  666. VideoLayout.setAudioLevel(id, lvl);
  667. };
  668. /**
  669. * Update state of desktop sharing buttons.
  670. */
  671. UI.updateDesktopSharingButtons = function () {
  672. Toolbar.updateDesktopSharingButtonState();
  673. };
  674. /**
  675. * Hide connection quality statistics from UI.
  676. */
  677. UI.hideStats = function () {
  678. VideoLayout.hideStats();
  679. };
  680. /**
  681. * Update local connection quality statistics.
  682. * @param {number} percent
  683. * @param {object} stats
  684. */
  685. UI.updateLocalStats = function (percent, stats) {
  686. VideoLayout.updateLocalConnectionStats(percent, stats);
  687. };
  688. /**
  689. * Update connection quality statistics for remote user.
  690. * @param {string} id user id
  691. * @param {number} percent
  692. * @param {object} stats
  693. */
  694. UI.updateRemoteStats = function (id, percent, stats) {
  695. VideoLayout.updateConnectionStats(id, percent, stats);
  696. };
  697. /**
  698. * Mark video as interrupted or not.
  699. * @param {boolean} interrupted if video is interrupted
  700. */
  701. UI.markVideoInterrupted = function (interrupted) {
  702. if (interrupted) {
  703. VideoLayout.onVideoInterrupted();
  704. } else {
  705. VideoLayout.onVideoRestored();
  706. }
  707. };
  708. /**
  709. * Mark room as locked or not.
  710. * @param {boolean} locked if room is locked.
  711. */
  712. UI.markRoomLocked = function (locked) {
  713. if (locked) {
  714. Toolbar.lockLockButton();
  715. } else {
  716. Toolbar.unlockLockButton();
  717. }
  718. };
  719. /**
  720. * Add chat message.
  721. * @param {string} from user id
  722. * @param {string} displayName user nickname
  723. * @param {string} message message text
  724. * @param {number} stamp timestamp when message was created
  725. */
  726. UI.addMessage = function (from, displayName, message, stamp) {
  727. Chat.updateChatConversation(from, displayName, message, stamp);
  728. };
  729. UI.updateDTMFSupport = function (isDTMFSupported) {
  730. //TODO: enable when the UI is ready
  731. //Toolbar.showDialPadButton(dtmfSupport);
  732. };
  733. /**
  734. * Invite participants to conference.
  735. * @param {string} roomUrl
  736. * @param {string} conferenceName
  737. * @param {string} key
  738. * @param {string} nick
  739. */
  740. UI.inviteParticipants = function (roomUrl, conferenceName, key, nick) {
  741. let keyText = "";
  742. if (key) {
  743. keyText = APP.translation.translateString(
  744. "email.sharedKey", {sharedKey: key}
  745. );
  746. }
  747. let and = APP.translation.translateString("email.and");
  748. let supportedBrowsers = `Chromium, Google Chrome ${and} Opera`;
  749. let subject = APP.translation.translateString(
  750. "email.subject", {appName:interfaceConfig.APP_NAME, conferenceName}
  751. );
  752. let body = APP.translation.translateString(
  753. "email.body", {
  754. appName:interfaceConfig.APP_NAME,
  755. sharedKeyText: keyText,
  756. roomUrl,
  757. supportedBrowsers
  758. }
  759. );
  760. body = body.replace(/\n/g, "%0D%0A");
  761. if (nick) {
  762. body += "%0D%0A%0D%0A" + UIUtil.escapeHtml(nick);
  763. }
  764. if (interfaceConfig.INVITATION_POWERED_BY) {
  765. body += "%0D%0A%0D%0A--%0D%0Apowered by jitsi.org";
  766. }
  767. window.open(`mailto:?subject=${subject}&body=${body}`, '_blank');
  768. };
  769. /**
  770. * Show user feedback dialog if its required or just show "thank you" dialog.
  771. * @returns {Promise} when dialog is closed.
  772. */
  773. UI.requestFeedback = function () {
  774. return new Promise(function (resolve, reject) {
  775. if (Feedback.isEnabled()) {
  776. // If the user has already entered feedback, we'll show the window and
  777. // immidiately start the conference dispose timeout.
  778. if (Feedback.feedbackScore > 0) {
  779. Feedback.openFeedbackWindow();
  780. resolve();
  781. } else { // Otherwise we'll wait for user's feedback.
  782. Feedback.openFeedbackWindow(resolve);
  783. }
  784. } else {
  785. // If the feedback functionality isn't enabled we show a thank you
  786. // dialog.
  787. messageHandler.openMessageDialog(
  788. null, null, null,
  789. APP.translation.translateString(
  790. "dialog.thankYou", {appName:interfaceConfig.APP_NAME}
  791. )
  792. );
  793. resolve();
  794. }
  795. });
  796. };
  797. /**
  798. * Request recording token from the user.
  799. * @returns {Promise}
  800. */
  801. UI.requestRecordingToken = function () {
  802. let msg = APP.translation.generateTranslationHTML("dialog.recordingToken");
  803. let token = APP.translation.translateString("dialog.token");
  804. return new Promise(function (resolve, reject) {
  805. messageHandler.openTwoButtonDialog(
  806. null, null, null,
  807. `<h2>${msg}</h2>
  808. <input name="recordingToken" type="text"
  809. data-i18n="[placeholder]dialog.token"
  810. placeholder="${token}" autofocus>`,
  811. false, "dialog.Save",
  812. function (e, v, m, f) {
  813. if (v && f.recordingToken) {
  814. resolve(UIUtil.escapeHtml(f.recordingToken));
  815. } else {
  816. reject();
  817. }
  818. },
  819. null,
  820. function () { },
  821. ':input:first'
  822. );
  823. });
  824. };
  825. UI.updateRecordingState = function (state) {
  826. Toolbar.updateRecordingState(state);
  827. };
  828. UI.notifyTokenAuthFailed = function () {
  829. messageHandler.showError("dialog.error", "dialog.tokenAuthFailed");
  830. };
  831. UI.notifyInternalError = function () {
  832. messageHandler.showError("dialog.sorry", "dialog.internalError");
  833. };
  834. UI.notifyFocusDisconnected = function (focus, retrySec) {
  835. messageHandler.notify(
  836. null, "notify.focus",
  837. 'disconnected', "notify.focusFail",
  838. {component: focus, ms: retrySec}
  839. );
  840. };
  841. /**
  842. * Notify user that focus left the conference so page should be reloaded.
  843. */
  844. UI.notifyFocusLeft = function () {
  845. let title = APP.translation.generateTranslationHTML(
  846. 'dialog.serviceUnavailable'
  847. );
  848. let msg = APP.translation.generateTranslationHTML(
  849. 'dialog.jicofoUnavailable'
  850. );
  851. messageHandler.openDialog(
  852. title,
  853. msg,
  854. true, // persistent
  855. [{title: 'retry'}],
  856. function () {
  857. reload();
  858. return false;
  859. }
  860. );
  861. };
  862. /**
  863. * Updates auth info on the UI.
  864. * @param {boolean} isAuthEnabled if authentication is enabled
  865. * @param {string} [login] current login
  866. */
  867. UI.updateAuthInfo = function (isAuthEnabled, login) {
  868. let loggedIn = !!login;
  869. Toolbar.showAuthenticateButton(isAuthEnabled);
  870. if (isAuthEnabled) {
  871. Toolbar.setAuthenticatedIdentity(login);
  872. Toolbar.showLoginButton(!loggedIn);
  873. Toolbar.showLogoutButton(loggedIn);
  874. }
  875. };
  876. /**
  877. * Show Prezi from the user.
  878. * @param {string} userId user id
  879. * @param {string} url Prezi url
  880. * @param {number} slide slide to show
  881. */
  882. UI.showPrezi = function (userId, url, slide) {
  883. preziManager.showPrezi(userId, url, slide);
  884. };
  885. /**
  886. * Stop showing Prezi from the user.
  887. * @param {string} userId user id
  888. */
  889. UI.stopPrezi = function (userId) {
  890. if (preziManager.isSharing(userId)) {
  891. preziManager.removePrezi(userId);
  892. }
  893. };
  894. UI.onStartMutedChanged = function (startAudioMuted, startVideoMuted) {
  895. SettingsMenu.updateStartMutedBox(startAudioMuted, startVideoMuted);
  896. };
  897. /**
  898. * Update list of available physical devices.
  899. * @param {object[]} devices new list of available devices
  900. */
  901. UI.onAvailableDevicesChanged = function (devices) {
  902. SettingsMenu.changeDevicesList(devices);
  903. };
  904. /**
  905. * Returns the id of the current video shown on large.
  906. * Currently used by tests (torture).
  907. */
  908. UI.getLargeVideoID = function () {
  909. return VideoLayout.getLargeVideoID();
  910. };
  911. /**
  912. * Shows dialog with a link to FF extension.
  913. */
  914. UI.showExtensionRequiredDialog = function (url) {
  915. messageHandler.openMessageDialog(
  916. "dialog.extensionRequired",
  917. null,
  918. null,
  919. APP.translation.generateTranslationHTML(
  920. "dialog.firefoxExtensionPrompt", {url: url}));
  921. };
  922. UI.updateDevicesAvailability = function (id, devices) {
  923. VideoLayout.setDeviceAvailabilityIcons(id, devices);
  924. };
  925. module.exports = UI;