Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

UI.js 34KB

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