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

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