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

UI.js 34KB

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