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

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