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

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