Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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