You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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