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

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