選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

UI.js 35KB

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