You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UI.js 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296
  1. /* global APP, JitsiMeetJS, $, config, interfaceConfig */
  2. const logger = require("jitsi-meet-logger").getLogger(__filename);
  3. var UI = {};
  4. import Chat from "./side_pannels/chat/Chat";
  5. import SidePanels from "./side_pannels/SidePanels";
  6. import Avatar from "./avatar/Avatar";
  7. import SideContainerToggler from "./side_pannels/SideContainerToggler";
  8. import messageHandler from "./util/MessageHandler";
  9. import UIUtil from "./util/UIUtil";
  10. import { activateTooltips } from './util/Tooltip';
  11. import UIEvents from "../../service/UI/UIEvents";
  12. import EtherpadManager from './etherpad/Etherpad';
  13. import SharedVideoManager from './shared_video/SharedVideo';
  14. import Recording from "./recording/Recording";
  15. import VideoLayout from "./videolayout/VideoLayout";
  16. import Filmstrip from "./videolayout/Filmstrip";
  17. import SettingsMenu from "./side_pannels/settings/SettingsMenu";
  18. import Profile from "./side_pannels/profile/Profile";
  19. import Settings from "./../settings/Settings";
  20. import { debounce } from "../util/helpers";
  21. import { updateDeviceList } from '../../react/features/base/devices';
  22. import {
  23. openDeviceSelectionDialog
  24. } from '../../react/features/device-selection';
  25. import { openDisplayNamePrompt } from '../../react/features/display-name';
  26. import {
  27. checkAutoEnableDesktopSharing,
  28. clearButtonPopup,
  29. dockToolbox,
  30. setButtonPopupTimeout,
  31. setToolbarButton,
  32. showDialPadButton,
  33. showEtherpadButton,
  34. showSharedVideoButton,
  35. showDialOutButton,
  36. showToolbox
  37. } from '../../react/features/toolbox';
  38. import {
  39. maybeShowNotificationWithDoNotDisplay,
  40. setNotificationsEnabled
  41. } from '../../react/features/notifications';
  42. var EventEmitter = require("events");
  43. UI.messageHandler = messageHandler;
  44. import FollowMe from "../FollowMe";
  45. var eventEmitter = new EventEmitter();
  46. UI.eventEmitter = eventEmitter;
  47. let etherpadManager;
  48. let sharedVideoManager;
  49. let followMeHandler;
  50. const TrackErrors = JitsiMeetJS.errors.track;
  51. const JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP = {
  52. microphone: {},
  53. camera: {}
  54. };
  55. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.UNSUPPORTED_RESOLUTION]
  56. = "dialog.cameraUnsupportedResolutionError";
  57. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.GENERAL]
  58. = "dialog.cameraUnknownError";
  59. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.PERMISSION_DENIED]
  60. = "dialog.cameraPermissionDeniedError";
  61. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.NOT_FOUND]
  62. = "dialog.cameraNotFoundError";
  63. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.CONSTRAINT_FAILED]
  64. = "dialog.cameraConstraintFailedError";
  65. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.NO_DATA_FROM_SOURCE]
  66. = "dialog.cameraNotSendingData";
  67. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.GENERAL]
  68. = "dialog.micUnknownError";
  69. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.PERMISSION_DENIED]
  70. = "dialog.micPermissionDeniedError";
  71. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.NOT_FOUND]
  72. = "dialog.micNotFoundError";
  73. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.CONSTRAINT_FAILED]
  74. = "dialog.micConstraintFailedError";
  75. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.NO_DATA_FROM_SOURCE]
  76. = "dialog.micNotSendingData";
  77. /**
  78. * Toggles the application in and out of full screen mode
  79. * (a.k.a. presentation mode in Chrome).
  80. */
  81. UI.toggleFullScreen = function() {
  82. (UIUtil.isFullScreen())
  83. ? UIUtil.exitFullScreen()
  84. : UIUtil.enterFullScreen();
  85. };
  86. /**
  87. * Notify user that server has shut down.
  88. */
  89. UI.notifyGracefulShutdown = function () {
  90. messageHandler.openMessageDialog(
  91. 'dialog.serviceUnavailable',
  92. 'dialog.gracefulShutdown'
  93. );
  94. };
  95. /**
  96. * Notify user that reservation error happened.
  97. */
  98. UI.notifyReservationError = function (code, msg) {
  99. var message = APP.translation.generateTranslationHTML(
  100. "dialog.reservationErrorMsg", {code: code, msg: msg});
  101. messageHandler.openDialog(
  102. "dialog.reservationError", message, true, {}, () => false);
  103. };
  104. /**
  105. * Notify user that he has been kicked from the server.
  106. */
  107. UI.notifyKicked = function () {
  108. messageHandler.openMessageDialog(
  109. "dialog.sessTerminated",
  110. "dialog.kickMessage");
  111. };
  112. /**
  113. * Notify user that conference was destroyed.
  114. * @param reason {string} the reason text
  115. */
  116. UI.notifyConferenceDestroyed = function (reason) {
  117. //FIXME: use Session Terminated from translation, but
  118. // 'reason' text comes from XMPP packet and is not translated
  119. messageHandler.openDialog(
  120. "dialog.sessTerminated", reason, true, {}, () => false);
  121. };
  122. /**
  123. * Show chat error.
  124. * @param err the Error
  125. * @param msg
  126. */
  127. UI.showChatError = function (err, msg) {
  128. if (interfaceConfig.filmStripOnly) {
  129. return;
  130. }
  131. Chat.chatAddError(err, msg);
  132. };
  133. /**
  134. * Change nickname for the user.
  135. * @param {string} id user id
  136. * @param {string} displayName new nickname
  137. */
  138. UI.changeDisplayName = function (id, displayName) {
  139. if (UI.ContactList)
  140. UI.ContactList.onDisplayNameChange(id, displayName);
  141. VideoLayout.onDisplayNameChanged(id, displayName);
  142. if (APP.conference.isLocalId(id) || id === 'localVideoContainer') {
  143. Profile.changeDisplayName(displayName);
  144. Chat.setChatConversationMode(!!displayName);
  145. }
  146. };
  147. /**
  148. * Shows/hides the indication about local connection being interrupted.
  149. *
  150. * @param {boolean} isInterrupted <tt>true</tt> if local connection is
  151. * currently in the interrupted state or <tt>false</tt> if the connection
  152. * is fine.
  153. */
  154. UI.showLocalConnectionInterrupted = function (isInterrupted) {
  155. VideoLayout.showLocalConnectionInterrupted(isInterrupted);
  156. };
  157. /**
  158. * Sets the "raised hand" status for a participant.
  159. */
  160. UI.setRaisedHandStatus = (participant, raisedHandStatus) => {
  161. VideoLayout.setRaisedHandStatus(participant.getId(), raisedHandStatus);
  162. if (raisedHandStatus) {
  163. messageHandler.participantNotification(participant.getDisplayName(),
  164. 'notify.somebody', 'connected', 'notify.raisedHand');
  165. }
  166. };
  167. /**
  168. * Sets the local "raised hand" status.
  169. */
  170. UI.setLocalRaisedHandStatus
  171. = raisedHandStatus =>
  172. VideoLayout.setRaisedHandStatus(
  173. APP.conference.getMyUserId(),
  174. raisedHandStatus);
  175. /**
  176. * Initialize conference UI.
  177. */
  178. UI.initConference = function () {
  179. let id = APP.conference.getMyUserId();
  180. // Add myself to the contact list.
  181. if (UI.ContactList)
  182. UI.ContactList.addContact(id, true);
  183. // Update default button states before showing the toolbar
  184. // if local role changes buttons state will be again updated.
  185. UI.updateLocalRole(APP.conference.isModerator);
  186. UI.showToolbar();
  187. let displayName = config.displayJids ? id : Settings.getDisplayName();
  188. if (displayName) {
  189. UI.changeDisplayName('localVideoContainer', displayName);
  190. }
  191. // Make sure we configure our avatar id, before creating avatar for us
  192. let email = Settings.getEmail();
  193. if (email) {
  194. UI.setUserEmail(id, email);
  195. } else {
  196. UI.setUserAvatarID(id, Settings.getAvatarId());
  197. }
  198. APP.store.dispatch(checkAutoEnableDesktopSharing());
  199. // FollowMe attempts to copy certain aspects of the moderator's UI into the
  200. // other participants' UI. Consequently, it needs (1) read and write access
  201. // to the UI (depending on the moderator role of the local participant) and
  202. // (2) APP.conference as means of communication between the participants.
  203. followMeHandler = new FollowMe(APP.conference, UI);
  204. activateTooltips();
  205. };
  206. UI.mucJoined = function () {
  207. VideoLayout.mucJoined();
  208. // Update local video now that a conference is joined a user ID should be
  209. // set.
  210. UI.changeDisplayName('localVideoContainer', APP.settings.getDisplayName());
  211. };
  212. /***
  213. * Handler for toggling filmstrip
  214. */
  215. UI.handleToggleFilmstrip = () => UI.toggleFilmstrip();
  216. /**
  217. * Sets tooltip defaults.
  218. *
  219. * @private
  220. */
  221. function _setTooltipDefaults() {
  222. $.fn.tooltip.defaults = {
  223. opacity: 1, //defaults to 1
  224. offset: 1,
  225. delayIn: 0, //defaults to 500
  226. hoverable: true,
  227. hideOnClick: true,
  228. aria: true
  229. };
  230. }
  231. /**
  232. * Returns the shared document manager object.
  233. * @return {EtherpadManager} the shared document manager object
  234. */
  235. UI.getSharedVideoManager = function () {
  236. return sharedVideoManager;
  237. };
  238. /**
  239. * Starts the UI module and initializes all related components.
  240. *
  241. * @returns {boolean} true if the UI is ready and the conference should be
  242. * established, false - otherwise (for example in the case of welcome page)
  243. */
  244. UI.start = function () {
  245. document.title = interfaceConfig.APP_NAME;
  246. // Set the defaults for prompt dialogs.
  247. $.prompt.setDefaults({persistent: false});
  248. // Set the defaults for tooltips.
  249. _setTooltipDefaults();
  250. SideContainerToggler.init(eventEmitter);
  251. Filmstrip.init(eventEmitter);
  252. VideoLayout.init(eventEmitter);
  253. if (!interfaceConfig.filmStripOnly) {
  254. VideoLayout.initLargeVideo();
  255. }
  256. VideoLayout.resizeVideoArea(true, true);
  257. sharedVideoManager = new SharedVideoManager(eventEmitter);
  258. if (!interfaceConfig.filmStripOnly) {
  259. let debouncedShowToolbar
  260. = debounce(
  261. () => UI.showToolbar(),
  262. 100,
  263. { leading: true, trailing: false });
  264. $("#videoconference_page").mousemove(debouncedShowToolbar);
  265. // Initialise the recording module.
  266. if (config.enableRecording) {
  267. Recording.init(eventEmitter, config.recordingType);
  268. }
  269. // Initialize side panels
  270. SidePanels.init(eventEmitter);
  271. } else {
  272. $("body").addClass("filmstrip-only");
  273. UI.showToolbar();
  274. Filmstrip.setFilmstripOnly();
  275. APP.store.dispatch(setNotificationsEnabled(false));
  276. }
  277. if (interfaceConfig.VERTICAL_FILMSTRIP) {
  278. $("body").addClass("vertical-filmstrip");
  279. }
  280. document.title = interfaceConfig.APP_NAME;
  281. };
  282. /**
  283. * Invokes cleanup of any deferred execution within relevant UI modules.
  284. *
  285. * @returns {void}
  286. */
  287. UI.stopDaemons = () => {
  288. VideoLayout.resetLargeVideo();
  289. };
  290. /**
  291. * Setup some UI event listeners.
  292. */
  293. UI.registerListeners
  294. = () => UIListeners.forEach((value, key) => UI.addListener(key, value));
  295. /**
  296. * Unregister some UI event listeners.
  297. */
  298. UI.unregisterListeners
  299. = () => UIListeners.forEach((value, key) => UI.removeListener(key, value));
  300. /**
  301. * Setup some DOM event listeners.
  302. */
  303. UI.bindEvents = () => {
  304. function onResize() {
  305. SideContainerToggler.resize();
  306. VideoLayout.resizeVideoArea();
  307. }
  308. // Resize and reposition videos in full screen mode.
  309. $(document).on(
  310. 'webkitfullscreenchange mozfullscreenchange fullscreenchange',
  311. () => {
  312. eventEmitter.emit(
  313. UIEvents.FULLSCREEN_TOGGLED,
  314. UIUtil.isFullScreen());
  315. onResize();
  316. });
  317. $(window).resize(onResize);
  318. };
  319. /**
  320. * Unbind some DOM event listeners.
  321. */
  322. UI.unbindEvents = () => {
  323. $(document).off(
  324. 'webkitfullscreenchange mozfullscreenchange fullscreenchange');
  325. $(window).off('resize');
  326. };
  327. /**
  328. * Show local stream on UI.
  329. * @param {JitsiTrack} track stream to show
  330. */
  331. UI.addLocalStream = track => {
  332. switch (track.getType()) {
  333. case 'audio':
  334. VideoLayout.changeLocalAudio(track);
  335. break;
  336. case 'video':
  337. VideoLayout.changeLocalVideo(track);
  338. break;
  339. default:
  340. logger.error("Unknown stream type: " + track.getType());
  341. break;
  342. }
  343. };
  344. /**
  345. * Show remote stream on UI.
  346. * @param {JitsiTrack} track stream to show
  347. */
  348. UI.addRemoteStream = track => VideoLayout.onRemoteStreamAdded(track);
  349. /**
  350. * Removed remote stream from UI.
  351. * @param {JitsiTrack} track stream to remove
  352. */
  353. UI.removeRemoteStream = track => VideoLayout.onRemoteStreamRemoved(track);
  354. /**
  355. * Update chat subject.
  356. * @param {string} subject new chat subject
  357. */
  358. UI.setSubject = subject => Chat.setSubject(subject);
  359. /**
  360. * Setup and show Etherpad.
  361. * @param {string} name etherpad id
  362. */
  363. UI.initEtherpad = name => {
  364. if (etherpadManager || !config.etherpad_base || !name) {
  365. return;
  366. }
  367. logger.log('Etherpad is enabled');
  368. etherpadManager
  369. = new EtherpadManager(config.etherpad_base, name, eventEmitter);
  370. APP.store.dispatch(showEtherpadButton());
  371. };
  372. /**
  373. * Returns the shared document manager object.
  374. * @return {EtherpadManager} the shared document manager object
  375. */
  376. UI.getSharedDocumentManager = () => etherpadManager;
  377. /**
  378. * Show user on UI.
  379. * @param {JitsiParticipant} user
  380. */
  381. UI.addUser = function (user) {
  382. var id = user.getId();
  383. var displayName = user.getDisplayName();
  384. if (UI.ContactList)
  385. UI.ContactList.addContact(id);
  386. messageHandler.participantNotification(
  387. displayName,'notify.somebody', 'connected', 'notify.connected'
  388. );
  389. if (!config.startAudioMuted ||
  390. config.startAudioMuted > APP.conference.membersCount)
  391. UIUtil.playSoundNotification('userJoined');
  392. // Add Peer's container
  393. VideoLayout.addParticipantContainer(user);
  394. // Configure avatar
  395. UI.setUserEmail(id);
  396. // set initial display name
  397. if(displayName)
  398. UI.changeDisplayName(id, displayName);
  399. };
  400. /**
  401. * Remove user from UI.
  402. * @param {string} id user id
  403. * @param {string} displayName user nickname
  404. */
  405. UI.removeUser = function (id, displayName) {
  406. if (UI.ContactList)
  407. UI.ContactList.removeContact(id);
  408. messageHandler.participantNotification(
  409. displayName,'notify.somebody', 'disconnected', 'notify.disconnected'
  410. );
  411. if (!config.startAudioMuted
  412. || config.startAudioMuted > APP.conference.membersCount) {
  413. UIUtil.playSoundNotification('userLeft');
  414. }
  415. VideoLayout.removeParticipantContainer(id);
  416. };
  417. /**
  418. * Update videotype for specified user.
  419. * @param {string} id user id
  420. * @param {string} newVideoType new videotype
  421. */
  422. UI.onPeerVideoTypeChanged
  423. = (id, newVideoType) => VideoLayout.onVideoTypeChanged(id, newVideoType);
  424. /**
  425. * Update local user role and show notification if user is moderator.
  426. * @param {boolean} isModerator if local user is moderator or not
  427. */
  428. UI.updateLocalRole = isModerator => {
  429. VideoLayout.showModeratorIndicator();
  430. APP.store.dispatch(showDialOutButton(isModerator));
  431. APP.store.dispatch(showSharedVideoButton());
  432. Recording.showRecordingButton(isModerator);
  433. SettingsMenu.showStartMutedOptions(isModerator);
  434. SettingsMenu.showFollowMeOptions(isModerator);
  435. if (isModerator) {
  436. if (!interfaceConfig.DISABLE_FOCUS_INDICATOR)
  437. messageHandler.participantNotification(
  438. null, "notify.me", 'connected', "notify.moderator");
  439. Recording.checkAutoRecord();
  440. }
  441. };
  442. /**
  443. * Check the role for the user and reflect it in the UI, moderator ui indication
  444. * and notifies user who is the moderator
  445. * @param user to check for moderator
  446. */
  447. UI.updateUserRole = user => {
  448. VideoLayout.showModeratorIndicator();
  449. // We don't need to show moderator notifications when the focus (moderator)
  450. // indicator is disabled.
  451. if (!user.isModerator() || interfaceConfig.DISABLE_FOCUS_INDICATOR) {
  452. return;
  453. }
  454. var displayName = user.getDisplayName();
  455. if (displayName) {
  456. messageHandler.participantNotification(
  457. displayName, 'notify.somebody',
  458. 'connected', 'notify.grantedTo', {
  459. to: UIUtil.escapeHtml(displayName)
  460. }
  461. );
  462. } else {
  463. messageHandler.participantNotification(
  464. '', 'notify.somebody',
  465. 'connected', 'notify.grantedToUnknown');
  466. }
  467. };
  468. /**
  469. * Updates the user status.
  470. *
  471. * @param {JitsiParticipant} user - The user which status we need to update.
  472. * @param {string} status - The new status.
  473. */
  474. UI.updateUserStatus = (user, status) => {
  475. let displayName = user.getDisplayName();
  476. messageHandler.participantNotification(
  477. displayName, '', 'connected', "dialOut.statusMessage",
  478. {
  479. status: UIUtil.escapeHtml(status)
  480. });
  481. };
  482. /**
  483. * Toggles smileys in the chat.
  484. */
  485. UI.toggleSmileys = () => Chat.toggleSmileys();
  486. /**
  487. * Toggles filmstrip.
  488. */
  489. UI.toggleFilmstrip = function () {
  490. var self = Filmstrip;
  491. self.toggleFilmstrip.apply(self, arguments);
  492. VideoLayout.resizeVideoArea(true, false);
  493. };
  494. /**
  495. * Indicates if the filmstrip is currently visible or not.
  496. * @returns {true} if the filmstrip is currently visible, otherwise
  497. */
  498. UI.isFilmstripVisible = () => Filmstrip.isFilmstripVisible();
  499. /**
  500. * Toggles chat panel.
  501. */
  502. UI.toggleChat = () => UI.toggleSidePanel("chat_container");
  503. /**
  504. * Toggles contact list panel.
  505. */
  506. UI.toggleContactList = () => UI.toggleSidePanel("contacts_container");
  507. /**
  508. * Toggles the given side panel.
  509. *
  510. * @param {String} sidePanelId the identifier of the side panel to toggle
  511. */
  512. UI.toggleSidePanel = sidePanelId => SideContainerToggler.toggle(sidePanelId);
  513. /**
  514. * Handle new user display name.
  515. */
  516. UI.inputDisplayNameHandler = function (newDisplayName) {
  517. eventEmitter.emit(UIEvents.NICKNAME_CHANGED, newDisplayName);
  518. };
  519. /**
  520. * Show custom popup/tooltip for a specified button.
  521. *
  522. * @param {string} buttonName - The name of the button as specified in the
  523. * button configurations for the toolbar.
  524. * @param {string} popupSelectorID - The id of the popup to show as specified in
  525. * the button configurations for the toolbar.
  526. * @param {boolean} show - True or false/show or hide the popup
  527. * @param {number} timeout - The time to show the popup
  528. * @returns {void}
  529. */
  530. UI.showCustomToolbarPopup = function (buttonName, popupID, show, timeout) {
  531. const action = show
  532. ? setButtonPopupTimeout(buttonName, popupID, timeout)
  533. : clearButtonPopup(buttonName);
  534. APP.store.dispatch(action);
  535. };
  536. /**
  537. * Return the type of the remote video.
  538. * @param jid the jid for the remote video
  539. * @returns the video type video or screen.
  540. */
  541. UI.getRemoteVideoType = function (jid) {
  542. return VideoLayout.getRemoteVideoType(jid);
  543. };
  544. // FIXME check if someone user this
  545. UI.showLoginPopup = function(callback) {
  546. logger.log('password is required');
  547. let message = (
  548. `<input name="username" type="text"
  549. placeholder="user@domain.net"
  550. class="input-control" autofocus>
  551. <input name="password" type="password"
  552. data-i18n="[placeholder]dialog.userPassword"
  553. class="input-control"
  554. placeholder="user password">`
  555. );
  556. let submitFunction = (e, v, m, f) => {
  557. if (v) {
  558. if (f.username && f.password) {
  559. callback(f.username, f.password);
  560. }
  561. }
  562. };
  563. messageHandler.openTwoButtonDialog({
  564. titleKey : "dialog.passwordRequired",
  565. msgString: message,
  566. leftButtonKey: 'dialog.Ok',
  567. submitFunction,
  568. focus: ':input:first'
  569. });
  570. };
  571. UI.askForNickname = function () {
  572. return window.prompt('Your nickname (optional)');
  573. };
  574. /**
  575. * Sets muted audio state for participant
  576. */
  577. UI.setAudioMuted = function (id, muted) {
  578. VideoLayout.onAudioMute(id, muted);
  579. if (APP.conference.isLocalId(id)) {
  580. APP.conference.updateAudioIconEnabled();
  581. }
  582. };
  583. /**
  584. * Sets muted video state for participant
  585. */
  586. UI.setVideoMuted = function (id, muted) {
  587. VideoLayout.onVideoMute(id, muted);
  588. if (APP.conference.isLocalId(id)) {
  589. APP.conference.updateVideoIconEnabled();
  590. }
  591. };
  592. /**
  593. * Triggers an update of remote video and large video displays so they may pick
  594. * up any state changes that have occurred elsewhere.
  595. *
  596. * @returns {void}
  597. */
  598. UI.updateAllVideos = () => VideoLayout.updateAllVideos();
  599. /**
  600. * Adds a listener that would be notified on the given type of event.
  601. *
  602. * @param type the type of the event we're listening for
  603. * @param listener a function that would be called when notified
  604. */
  605. UI.addListener = function (type, listener) {
  606. eventEmitter.on(type, listener);
  607. };
  608. /**
  609. * Removes the given listener for the given type of event.
  610. *
  611. * @param type the type of the event we're listening for
  612. * @param listener the listener we want to remove
  613. */
  614. UI.removeListener = function (type, listener) {
  615. eventEmitter.removeListener(type, listener);
  616. };
  617. /**
  618. * Emits the event of given type by specifying the parameters in options.
  619. *
  620. * @param type the type of the event we're emitting
  621. * @param options the parameters for the event
  622. */
  623. UI.emitEvent = (type, ...options) => eventEmitter.emit(type, ...options);
  624. UI.clickOnVideo = function (videoNumber) {
  625. let videos = $("#remoteVideos .videocontainer:not(#mixedstream)");
  626. let videosLength = videos.length;
  627. if(videosLength <= videoNumber) {
  628. return;
  629. }
  630. let videoIndex = videoNumber === 0 ? 0 : videosLength - videoNumber;
  631. videos[videoIndex].click();
  632. };
  633. // Used by torture.
  634. UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  635. // Used by torture.
  636. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  637. /**
  638. * Updates the avatar for participant.
  639. * @param {string} id user id
  640. * @param {string} avatarUrl the URL for the avatar
  641. */
  642. function changeAvatar(id, avatarUrl) {
  643. VideoLayout.changeUserAvatar(id, avatarUrl);
  644. if (UI.ContactList)
  645. UI.ContactList.changeUserAvatar(id, avatarUrl);
  646. if (APP.conference.isLocalId(id)) {
  647. Profile.changeAvatar(avatarUrl);
  648. }
  649. }
  650. /**
  651. * Update user email.
  652. * @param {string} id user id
  653. * @param {string} email user email
  654. */
  655. UI.setUserEmail = function (id, email) {
  656. // update avatar
  657. Avatar.setUserEmail(id, email);
  658. changeAvatar(id, Avatar.getAvatarUrl(id));
  659. if (APP.conference.isLocalId(id)) {
  660. Profile.changeEmail(email);
  661. }
  662. };
  663. /**
  664. * Update user avtar id.
  665. * @param {string} id user id
  666. * @param {string} avatarId user's avatar id
  667. */
  668. UI.setUserAvatarID = function (id, avatarId) {
  669. // update avatar
  670. Avatar.setUserAvatarID(id, avatarId);
  671. changeAvatar(id, Avatar.getAvatarUrl(id));
  672. };
  673. /**
  674. * Update user avatar URL.
  675. * @param {string} id user id
  676. * @param {string} url user avatar url
  677. */
  678. UI.setUserAvatarUrl = function (id, url) {
  679. // update avatar
  680. Avatar.setUserAvatarUrl(id, url);
  681. changeAvatar(id, Avatar.getAvatarUrl(id));
  682. };
  683. /**
  684. * Notify user that connection failed.
  685. * @param {string} stropheErrorMsg raw Strophe error message
  686. */
  687. UI.notifyConnectionFailed = function (stropheErrorMsg) {
  688. var message;
  689. if (stropheErrorMsg) {
  690. message = APP.translation.generateTranslationHTML(
  691. "dialog.connectErrorWithMsg", {msg: stropheErrorMsg});
  692. } else {
  693. message = APP.translation.generateTranslationHTML(
  694. "dialog.connectError");
  695. }
  696. messageHandler.openDialog("dialog.error", message, true, {}, () => false);
  697. };
  698. /**
  699. * Notify user that maximum users limit has been reached.
  700. */
  701. UI.notifyMaxUsersLimitReached = function () {
  702. var message = APP.translation.generateTranslationHTML(
  703. "dialog.maxUsersLimitReached");
  704. messageHandler.openDialog("dialog.error", message, true, {}, () => false);
  705. };
  706. /**
  707. * Notify user that he was automatically muted when joned the conference.
  708. */
  709. UI.notifyInitiallyMuted = function () {
  710. messageHandler.participantNotification(
  711. null,
  712. "notify.mutedTitle",
  713. "connected",
  714. "notify.muted",
  715. null,
  716. 120000);
  717. };
  718. /**
  719. * Mark user as dominant speaker.
  720. * @param {string} id user id
  721. */
  722. UI.markDominantSpeaker = function (id) {
  723. VideoLayout.onDominantSpeakerChanged(id);
  724. };
  725. UI.handleLastNEndpoints = function (leavingIds, enteringIds) {
  726. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  727. };
  728. /**
  729. * Will handle notification about participant's connectivity status change.
  730. *
  731. * @param {string} id the id of remote participant(MUC jid)
  732. */
  733. UI.participantConnectionStatusChanged = function (id) {
  734. VideoLayout.onParticipantConnectionStatusChanged(id);
  735. };
  736. /**
  737. * Prompt user for nickname.
  738. */
  739. UI.promptDisplayName = () => {
  740. APP.store.dispatch(openDisplayNamePrompt());
  741. };
  742. /**
  743. * Update audio level visualization for specified user.
  744. * @param {string} id user id
  745. * @param {number} lvl audio level
  746. */
  747. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  748. /**
  749. * Update state of desktop sharing buttons.
  750. *
  751. * @returns {void}
  752. */
  753. UI.updateDesktopSharingButtons
  754. = () =>
  755. APP.store.dispatch(setToolbarButton('desktop', {
  756. toggled: APP.conference.isSharingScreen
  757. }));
  758. /**
  759. * Hide connection quality statistics from UI.
  760. */
  761. UI.hideStats = function () {
  762. VideoLayout.hideStats();
  763. };
  764. /**
  765. * Mark video as interrupted or not.
  766. * @param {boolean} interrupted if video is interrupted
  767. */
  768. UI.markVideoInterrupted = function (interrupted) {
  769. if (interrupted) {
  770. VideoLayout.onVideoInterrupted();
  771. } else {
  772. VideoLayout.onVideoRestored();
  773. }
  774. };
  775. /**
  776. * Add chat message.
  777. * @param {string} from user id
  778. * @param {string} displayName user nickname
  779. * @param {string} message message text
  780. * @param {number} stamp timestamp when message was created
  781. */
  782. UI.addMessage = function (from, displayName, message, stamp) {
  783. Chat.updateChatConversation(from, displayName, message, stamp);
  784. };
  785. UI.updateDTMFSupport
  786. = isDTMFSupported => APP.store.dispatch(showDialPadButton(isDTMFSupported));
  787. UI.updateRecordingState = function (state) {
  788. Recording.updateRecordingState(state);
  789. };
  790. UI.notifyTokenAuthFailed = function () {
  791. messageHandler.showError( "dialog.tokenAuthFailedTitle",
  792. "dialog.tokenAuthFailed");
  793. };
  794. UI.notifyInternalError = function () {
  795. messageHandler.showError( "dialog.internalErrorTitle",
  796. "dialog.internalError");
  797. };
  798. UI.notifyFocusDisconnected = function (focus, retrySec) {
  799. messageHandler.participantNotification(
  800. null, "notify.focus",
  801. 'disconnected', "notify.focusFail",
  802. {component: focus, ms: retrySec}
  803. );
  804. };
  805. /**
  806. * Updates auth info on the UI.
  807. * @param {boolean} isAuthEnabled if authentication is enabled
  808. * @param {string} [login] current login
  809. */
  810. UI.updateAuthInfo = function (isAuthEnabled, login) {
  811. let showAuth = isAuthEnabled && UIUtil.isAuthenticationEnabled();
  812. let loggedIn = !!login;
  813. Profile.showAuthenticationButtons(showAuth);
  814. if (showAuth) {
  815. Profile.setAuthenticatedIdentity(login);
  816. Profile.showLoginButton(!loggedIn);
  817. Profile.showLogoutButton(loggedIn);
  818. }
  819. };
  820. UI.onStartMutedChanged = function (startAudioMuted, startVideoMuted) {
  821. SettingsMenu.updateStartMutedBox(startAudioMuted, startVideoMuted);
  822. };
  823. /**
  824. * Notifies interested listeners that the raise hand property has changed.
  825. *
  826. * @param {boolean} isRaisedHand indicates the current state of the
  827. * "raised hand"
  828. */
  829. UI.onLocalRaiseHandChanged = function (isRaisedHand) {
  830. eventEmitter.emit(UIEvents.LOCAL_RAISE_HAND_CHANGED, isRaisedHand);
  831. };
  832. /**
  833. * Update list of available physical devices.
  834. * @param {object[]} devices new list of available devices
  835. */
  836. UI.onAvailableDevicesChanged = function (devices) {
  837. APP.store.dispatch(updateDeviceList(devices));
  838. APP.conference.updateAudioIconEnabled();
  839. APP.conference.updateVideoIconEnabled();
  840. };
  841. /**
  842. * Returns the id of the current video shown on large.
  843. * Currently used by tests (torture).
  844. */
  845. UI.getLargeVideoID = function () {
  846. return VideoLayout.getLargeVideoID();
  847. };
  848. /**
  849. * Returns the current video shown on large.
  850. * Currently used by tests (torture).
  851. */
  852. UI.getLargeVideo = function () {
  853. return VideoLayout.getLargeVideo();
  854. };
  855. /**
  856. * Returns whether or not the passed in user id is currently pinned to the large
  857. * video.
  858. *
  859. * @param {string} userId - The id of the user to check is pinned or not.
  860. * @returns {boolean} True if the user is currently pinned to the large video.
  861. */
  862. UI.isPinned = userId => VideoLayout.getPinnedId() === userId;
  863. /**
  864. * Shows dialog with a link to FF extension.
  865. */
  866. UI.showExtensionRequiredDialog = function (url) {
  867. messageHandler.openMessageDialog(
  868. "dialog.extensionRequired",
  869. "[html]dialog.firefoxExtensionPrompt",
  870. {url: url});
  871. };
  872. /**
  873. * Shows "Please go to chrome webstore to install the desktop sharing extension"
  874. * 2 button dialog with buttons - cancel and go to web store.
  875. * @param url {string} the url of the extension.
  876. */
  877. UI.showExtensionExternalInstallationDialog = function (url) {
  878. let openedWindow = null;
  879. let submitFunction = function(e,v){
  880. if (v) {
  881. e.preventDefault();
  882. if (openedWindow === null || openedWindow.closed) {
  883. openedWindow
  884. = window.open(
  885. url,
  886. "extension_store_window",
  887. "resizable,scrollbars=yes,status=1");
  888. } else {
  889. openedWindow.focus();
  890. }
  891. }
  892. };
  893. let closeFunction = function (e, v) {
  894. if (openedWindow) {
  895. // Ideally we would close the popup, but this does not seem to work
  896. // on Chrome. Leaving it uncommented in case it could work
  897. // in some version.
  898. openedWindow.close();
  899. openedWindow = null;
  900. }
  901. if (!v) {
  902. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  903. }
  904. };
  905. messageHandler.openTwoButtonDialog({
  906. titleKey: 'dialog.externalInstallationTitle',
  907. msgKey: 'dialog.externalInstallationMsg',
  908. leftButtonKey: 'dialog.goToStore',
  909. submitFunction,
  910. loadedFunction: $.noop,
  911. closeFunction
  912. });
  913. };
  914. /**
  915. * Shows a dialog which asks user to install the extension. This one is
  916. * displayed after installation is triggered from the script, but fails because
  917. * it must be initiated by user gesture.
  918. * @param callback {function} function to be executed after user clicks
  919. * the install button - it should make another attempt to install the extension.
  920. */
  921. UI.showExtensionInlineInstallationDialog = function (callback) {
  922. let submitFunction = function(e,v){
  923. if (v) {
  924. callback();
  925. }
  926. };
  927. let closeFunction = function (e, v) {
  928. if (!v) {
  929. eventEmitter.emit(UIEvents.EXTERNAL_INSTALLATION_CANCELED);
  930. }
  931. };
  932. messageHandler.openTwoButtonDialog({
  933. titleKey: 'dialog.externalInstallationTitle',
  934. msgKey: 'dialog.inlineInstallationMsg',
  935. leftButtonKey: 'dialog.inlineInstallExtension',
  936. submitFunction,
  937. loadedFunction: $.noop,
  938. closeFunction
  939. });
  940. };
  941. /**
  942. * Shows a notifications about the passed in microphone error.
  943. *
  944. * @param {JitsiTrackError} micError - An error object related to using or
  945. * acquiring an audio stream.
  946. * @returns {void}
  947. */
  948. UI.showMicErrorNotification = function (micError) {
  949. if (!micError) {
  950. return;
  951. }
  952. const { message, name } = micError;
  953. const persistenceKey = `doNotShowErrorAgain-mic-${name}`;
  954. const micJitsiTrackErrorMsg
  955. = JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[name];
  956. const micErrorMsg = micJitsiTrackErrorMsg
  957. || JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.microphone[TrackErrors.GENERAL];
  958. const additionalMicErrorMsg = micJitsiTrackErrorMsg ? null : message;
  959. APP.store.dispatch(maybeShowNotificationWithDoNotDisplay(
  960. persistenceKey,
  961. {
  962. additionalMessage: additionalMicErrorMsg,
  963. messageKey: micErrorMsg,
  964. showToggle: Boolean(micJitsiTrackErrorMsg),
  965. subtitleKey: 'dialog.micErrorPresent',
  966. titleKey: name === TrackErrors.PERMISSION_DENIED
  967. ? 'deviceError.microphonePermission' : 'dialog.error',
  968. toggleLabelKey: 'dialog.doNotShowWarningAgain'
  969. }));
  970. };
  971. /**
  972. * Shows a notifications about the passed in camera error.
  973. *
  974. * @param {JitsiTrackError} cameraError - An error object related to using or
  975. * acquiring a video stream.
  976. * @returns {void}
  977. */
  978. UI.showCameraErrorNotification = function (cameraError) {
  979. if (!cameraError) {
  980. return;
  981. }
  982. const { message, name } = cameraError;
  983. const persistenceKey = `doNotShowErrorAgain-camera-${name}`;
  984. const cameraJitsiTrackErrorMsg =
  985. JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[name];
  986. const cameraErrorMsg = cameraJitsiTrackErrorMsg
  987. || JITSI_TRACK_ERROR_TO_MESSAGE_KEY_MAP.camera[TrackErrors.GENERAL];
  988. const additionalCameraErrorMsg = cameraJitsiTrackErrorMsg ? null : message;
  989. APP.store.dispatch(maybeShowNotificationWithDoNotDisplay(
  990. persistenceKey,
  991. {
  992. additionalMessage: additionalCameraErrorMsg,
  993. messageKey: cameraErrorMsg,
  994. showToggle: Boolean(cameraJitsiTrackErrorMsg),
  995. subtitleKey: 'dialog.cameraErrorPresent',
  996. titleKey: name === TrackErrors.PERMISSION_DENIED
  997. ? 'deviceError.cameraPermission' : 'dialog.error',
  998. toggleLabelKey: 'dialog.doNotShowWarningAgain'
  999. }));
  1000. };
  1001. /**
  1002. * Shows error dialog that informs the user that no data is received from the
  1003. * device.
  1004. */
  1005. UI.showTrackNotWorkingDialog = function (stream) {
  1006. messageHandler.openMessageDialog(
  1007. "dialog.error",
  1008. stream.isAudioTrack()? "dialog.micNotSendingData" :
  1009. "dialog.cameraNotSendingData");
  1010. };
  1011. UI.updateDevicesAvailability = function (id, devices) {
  1012. VideoLayout.setDeviceAvailabilityIcons(id, devices);
  1013. };
  1014. /**
  1015. * Show shared video.
  1016. * @param {string} id the id of the sender of the command
  1017. * @param {string} url video url
  1018. * @param {string} attributes
  1019. */
  1020. UI.onSharedVideoStart = function (id, url, attributes) {
  1021. if (sharedVideoManager)
  1022. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  1023. };
  1024. /**
  1025. * Update shared video.
  1026. * @param {string} id the id of the sender of the command
  1027. * @param {string} url video url
  1028. * @param {string} attributes
  1029. */
  1030. UI.onSharedVideoUpdate = function (id, url, attributes) {
  1031. if (sharedVideoManager)
  1032. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  1033. };
  1034. /**
  1035. * Stop showing shared video.
  1036. * @param {string} id the id of the sender of the command
  1037. * @param {string} attributes
  1038. */
  1039. UI.onSharedVideoStop = function (id, attributes) {
  1040. if (sharedVideoManager)
  1041. sharedVideoManager.onSharedVideoStop(id, attributes);
  1042. };
  1043. /**
  1044. * Handles user's features changes.
  1045. */
  1046. UI.onUserFeaturesChanged = user => VideoLayout.onUserFeaturesChanged(user);
  1047. /**
  1048. * Returns the number of known remote videos.
  1049. *
  1050. * @returns {number} The number of remote videos.
  1051. */
  1052. UI.getRemoteVideosCount = () => VideoLayout.getRemoteVideosCount();
  1053. /**
  1054. * Sets the remote control active status for a remote participant.
  1055. *
  1056. * @param {string} participantID - The id of the remote participant.
  1057. * @param {boolean} isActive - The new remote control active status.
  1058. * @returns {void}
  1059. */
  1060. UI.setRemoteControlActiveStatus = function(participantID, isActive) {
  1061. VideoLayout.setRemoteControlActiveStatus(participantID, isActive);
  1062. };
  1063. /**
  1064. * Sets the remote control active status for the local participant.
  1065. *
  1066. * @returns {void}
  1067. */
  1068. UI.setLocalRemoteControlActiveChanged = function() {
  1069. VideoLayout.setLocalRemoteControlActiveChanged();
  1070. };
  1071. const UIListeners = new Map([
  1072. [
  1073. UIEvents.ETHERPAD_CLICKED,
  1074. () => etherpadManager && etherpadManager.toggleEtherpad()
  1075. ], [
  1076. UIEvents.SHARED_VIDEO_CLICKED,
  1077. () => sharedVideoManager && sharedVideoManager.toggleSharedVideo()
  1078. ], [
  1079. UIEvents.TOGGLE_FULLSCREEN,
  1080. UI.toggleFullScreen
  1081. ], [
  1082. UIEvents.TOGGLE_CHAT,
  1083. UI.toggleChat
  1084. ], [
  1085. UIEvents.TOGGLE_SETTINGS,
  1086. () => {
  1087. // Opening of device selection is special-cased as it is a dialog
  1088. // opened through a button in settings and not directly displayed in
  1089. // settings itself. As it is not useful to only have a settings menu
  1090. // with a button to open a dialog, open the dialog directly instead.
  1091. if (interfaceConfig.SETTINGS_SECTIONS.length === 1
  1092. && UIUtil.isSettingEnabled('devices')) {
  1093. APP.store.dispatch(openDeviceSelectionDialog());
  1094. } else {
  1095. UI.toggleSidePanel("settings_container");
  1096. }
  1097. }
  1098. ], [
  1099. UIEvents.TOGGLE_CONTACT_LIST,
  1100. UI.toggleContactList
  1101. ], [
  1102. UIEvents.TOGGLE_PROFILE,
  1103. () => {
  1104. const {
  1105. isGuest
  1106. } = APP.store.getState()['features/jwt'];
  1107. isGuest && UI.toggleSidePanel('profile_container');
  1108. }
  1109. ], [
  1110. UIEvents.TOGGLE_FILMSTRIP,
  1111. UI.handleToggleFilmstrip
  1112. ], [
  1113. UIEvents.FOLLOW_ME_ENABLED,
  1114. enabled => (followMeHandler && followMeHandler.enableFollowMe(enabled))
  1115. ]
  1116. ]);
  1117. // TODO: Export every function separately. For now there is no point of doing
  1118. // this because we are importing everything.
  1119. export default UI;