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

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