Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

UI.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. /* global APP, $, config */
  2. const UI = {};
  3. import EventEmitter from 'events';
  4. import Logger from 'jitsi-meet-logger';
  5. import { isMobileBrowser } from '../../react/features/base/environment/utils';
  6. import { toggleChat } from '../../react/features/chat';
  7. import { setDocumentUrl } from '../../react/features/etherpad';
  8. import { setFilmstripVisible } from '../../react/features/filmstrip';
  9. import { joinLeaveNotificationsDisabled, setNotificationsEnabled } from '../../react/features/notifications';
  10. import {
  11. dockToolbox,
  12. setToolboxEnabled,
  13. showToolbox
  14. } from '../../react/features/toolbox/actions.web';
  15. import UIEvents from '../../service/UI/UIEvents';
  16. import EtherpadManager from './etherpad/Etherpad';
  17. import SharedVideoManager from './shared_video/SharedVideo';
  18. import messageHandler from './util/MessageHandler';
  19. import UIUtil from './util/UIUtil';
  20. import VideoLayout from './videolayout/VideoLayout';
  21. const logger = Logger.getLogger(__filename);
  22. UI.messageHandler = messageHandler;
  23. const eventEmitter = new EventEmitter();
  24. UI.eventEmitter = eventEmitter;
  25. let etherpadManager;
  26. let sharedVideoManager;
  27. const UIListeners = new Map([
  28. [
  29. UIEvents.ETHERPAD_CLICKED,
  30. () => etherpadManager && etherpadManager.toggleEtherpad()
  31. ], [
  32. UIEvents.SHARED_VIDEO_CLICKED,
  33. () => sharedVideoManager && sharedVideoManager.toggleSharedVideo()
  34. ], [
  35. UIEvents.TOGGLE_FILMSTRIP,
  36. () => UI.toggleFilmstrip()
  37. ]
  38. ]);
  39. /**
  40. * Indicates if we're currently in full screen mode.
  41. *
  42. * @return {boolean} {true} to indicate that we're currently in full screen
  43. * mode, {false} otherwise
  44. */
  45. UI.isFullScreen = function() {
  46. return UIUtil.isFullScreen();
  47. };
  48. /**
  49. * Returns true if there is a shared video which is being shown (?).
  50. * @returns {boolean} - true if there is a shared video which is being shown.
  51. */
  52. UI.isSharedVideoShown = function() {
  53. return Boolean(sharedVideoManager && sharedVideoManager.isSharedVideoShown);
  54. };
  55. /**
  56. * Notify user that server has shut down.
  57. */
  58. UI.notifyGracefulShutdown = function() {
  59. messageHandler.showError({
  60. descriptionKey: 'dialog.gracefulShutdown',
  61. titleKey: 'dialog.serviceUnavailable'
  62. });
  63. };
  64. /**
  65. * Notify user that reservation error happened.
  66. */
  67. UI.notifyReservationError = function(code, msg) {
  68. messageHandler.showError({
  69. descriptionArguments: {
  70. code,
  71. msg
  72. },
  73. descriptionKey: 'dialog.reservationErrorMsg',
  74. titleKey: 'dialog.reservationError'
  75. });
  76. };
  77. /**
  78. * Initialize conference UI.
  79. */
  80. UI.initConference = function() {
  81. UI.showToolbar();
  82. };
  83. /**
  84. * Returns the shared document manager object.
  85. * @return {EtherpadManager} the shared document manager object
  86. */
  87. UI.getSharedVideoManager = function() {
  88. return sharedVideoManager;
  89. };
  90. /**
  91. * Starts the UI module and initializes all related components.
  92. *
  93. * @returns {boolean} true if the UI is ready and the conference should be
  94. * established, false - otherwise (for example in the case of welcome page)
  95. */
  96. UI.start = function() {
  97. // Set the defaults for prompt dialogs.
  98. $.prompt.setDefaults({ persistent: false });
  99. VideoLayout.initLargeVideo();
  100. // Do not animate the video area on UI start (second argument passed into
  101. // resizeVideoArea) because the animation is not visible anyway. Plus with
  102. // the current dom layout, the quality label is part of the video layout and
  103. // will be seen animating in.
  104. VideoLayout.resizeVideoArea();
  105. sharedVideoManager = new SharedVideoManager(eventEmitter);
  106. if (isMobileBrowser()) {
  107. $('body').addClass('mobile-browser');
  108. } else {
  109. $('body').addClass('desktop-browser');
  110. }
  111. if (config.iAmRecorder) {
  112. // in case of iAmSipGateway keep local video visible
  113. if (!config.iAmSipGateway) {
  114. APP.store.dispatch(setNotificationsEnabled(false));
  115. }
  116. APP.store.dispatch(setToolboxEnabled(false));
  117. UI.messageHandler.enablePopups(false);
  118. }
  119. };
  120. /**
  121. * Setup some UI event listeners.
  122. */
  123. UI.registerListeners
  124. = () => UIListeners.forEach((value, key) => UI.addListener(key, value));
  125. /**
  126. * Setup some DOM event listeners.
  127. */
  128. UI.bindEvents = () => {
  129. /**
  130. *
  131. */
  132. function onResize() {
  133. VideoLayout.onResize();
  134. }
  135. // Resize and reposition videos in full screen mode.
  136. $(document).on(
  137. 'webkitfullscreenchange mozfullscreenchange fullscreenchange',
  138. onResize);
  139. $(window).resize(onResize);
  140. };
  141. /**
  142. * Unbind some DOM event listeners.
  143. */
  144. UI.unbindEvents = () => {
  145. $(document).off(
  146. 'webkitfullscreenchange mozfullscreenchange fullscreenchange');
  147. $(window).off('resize');
  148. };
  149. /**
  150. * Setup and show Etherpad.
  151. * @param {string} name etherpad id
  152. */
  153. UI.initEtherpad = name => {
  154. if (etherpadManager || !config.etherpad_base || !name) {
  155. return;
  156. }
  157. logger.log('Etherpad is enabled');
  158. etherpadManager = new EtherpadManager(eventEmitter);
  159. const url = new URL(name, config.etherpad_base);
  160. APP.store.dispatch(setDocumentUrl(url.toString()));
  161. if (config.openSharedDocumentOnJoin) {
  162. etherpadManager.toggleEtherpad();
  163. }
  164. };
  165. /**
  166. * Returns the shared document manager object.
  167. * @return {EtherpadManager} the shared document manager object
  168. */
  169. UI.getSharedDocumentManager = () => etherpadManager;
  170. /**
  171. * Show user on UI.
  172. * @param {JitsiParticipant} user
  173. */
  174. UI.addUser = function(user) {
  175. const status = user.getStatus();
  176. if (status) {
  177. // FIXME: move updateUserStatus in participantPresenceChanged action
  178. UI.updateUserStatus(user, status);
  179. }
  180. };
  181. /**
  182. * Updates the user status.
  183. *
  184. * @param {JitsiParticipant} user - The user which status we need to update.
  185. * @param {string} status - The new status.
  186. */
  187. UI.updateUserStatus = (user, status) => {
  188. const reduxState = APP.store.getState() || {};
  189. const { calleeInfoVisible } = reduxState['features/invite'] || {};
  190. // We hide status updates when join/leave notifications are disabled,
  191. // as jigasi is the component with statuses and they are seen as join/leave notifications.
  192. if (!status || calleeInfoVisible || joinLeaveNotificationsDisabled()) {
  193. return;
  194. }
  195. const displayName = user.getDisplayName();
  196. messageHandler.participantNotification(
  197. displayName,
  198. '',
  199. 'connected',
  200. 'dialOut.statusMessage',
  201. { status: UIUtil.escapeHtml(status) });
  202. };
  203. /**
  204. * Toggles filmstrip.
  205. */
  206. UI.toggleFilmstrip = function() {
  207. const { visible } = APP.store.getState()['features/filmstrip'];
  208. APP.store.dispatch(setFilmstripVisible(!visible));
  209. };
  210. /**
  211. * Toggles the visibility of the chat panel.
  212. */
  213. UI.toggleChat = () => APP.store.dispatch(toggleChat());
  214. /**
  215. * Sets muted audio state for participant
  216. */
  217. UI.setAudioMuted = function(id) {
  218. // FIXME: Maybe this can be removed!
  219. if (APP.conference.isLocalId(id)) {
  220. APP.conference.updateAudioIconEnabled();
  221. }
  222. };
  223. /**
  224. * Sets muted video state for participant
  225. */
  226. UI.setVideoMuted = function(id) {
  227. VideoLayout._updateLargeVideoIfDisplayed(id, true);
  228. if (APP.conference.isLocalId(id)) {
  229. APP.conference.updateVideoIconEnabled();
  230. }
  231. };
  232. UI.updateLargeVideo = (id, forceUpdate) => VideoLayout.updateLargeVideo(id, forceUpdate);
  233. /**
  234. * Adds a listener that would be notified on the given type of event.
  235. *
  236. * @param type the type of the event we're listening for
  237. * @param listener a function that would be called when notified
  238. */
  239. UI.addListener = function(type, listener) {
  240. eventEmitter.on(type, listener);
  241. };
  242. /**
  243. * Removes the all listeners for all events.
  244. *
  245. * @returns {void}
  246. */
  247. UI.removeAllListeners = function() {
  248. eventEmitter.removeAllListeners();
  249. };
  250. /**
  251. * Removes the given listener for the given type of event.
  252. *
  253. * @param type the type of the event we're listening for
  254. * @param listener the listener we want to remove
  255. */
  256. UI.removeListener = function(type, listener) {
  257. eventEmitter.removeListener(type, listener);
  258. };
  259. /**
  260. * Emits the event of given type by specifying the parameters in options.
  261. *
  262. * @param type the type of the event we're emitting
  263. * @param options the parameters for the event
  264. */
  265. UI.emitEvent = (type, ...options) => eventEmitter.emit(type, ...options);
  266. // Used by torture.
  267. UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  268. // Used by torture.
  269. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  270. /**
  271. * Updates the displayed avatar for participant.
  272. *
  273. * @param {string} id - User id whose avatar should be updated.
  274. * @param {string} avatarURL - The URL to avatar image to display.
  275. * @returns {void}
  276. */
  277. UI.refreshAvatarDisplay = function(id) {
  278. VideoLayout.changeUserAvatar(id);
  279. };
  280. /**
  281. * Notify user that connection failed.
  282. * @param {string} stropheErrorMsg raw Strophe error message
  283. */
  284. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  285. let descriptionKey;
  286. let descriptionArguments;
  287. if (stropheErrorMsg) {
  288. descriptionKey = 'dialog.connectErrorWithMsg';
  289. descriptionArguments = { msg: stropheErrorMsg };
  290. } else {
  291. descriptionKey = 'dialog.connectError';
  292. }
  293. messageHandler.showError({
  294. descriptionArguments,
  295. descriptionKey,
  296. titleKey: 'connection.CONNFAIL'
  297. });
  298. };
  299. /**
  300. * Notify user that maximum users limit has been reached.
  301. */
  302. UI.notifyMaxUsersLimitReached = function() {
  303. messageHandler.showError({
  304. hideErrorSupportLink: true,
  305. descriptionKey: 'dialog.maxUsersLimitReached',
  306. titleKey: 'dialog.maxUsersLimitReachedTitle'
  307. });
  308. };
  309. /**
  310. * Notify user that he was automatically muted when joned the conference.
  311. */
  312. UI.notifyInitiallyMuted = function() {
  313. messageHandler.participantNotification(
  314. null,
  315. 'notify.mutedTitle',
  316. 'connected',
  317. 'notify.muted',
  318. null);
  319. };
  320. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  321. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  322. };
  323. /**
  324. * Update audio level visualization for specified user.
  325. * @param {string} id user id
  326. * @param {number} lvl audio level
  327. */
  328. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  329. UI.notifyTokenAuthFailed = function() {
  330. messageHandler.showError({
  331. descriptionKey: 'dialog.tokenAuthFailed',
  332. titleKey: 'dialog.tokenAuthFailedTitle'
  333. });
  334. };
  335. UI.notifyFocusDisconnected = function(focus, retrySec) {
  336. messageHandler.participantNotification(
  337. null, 'notify.focus',
  338. 'disconnected', 'notify.focusFail',
  339. { component: focus,
  340. ms: retrySec }
  341. );
  342. };
  343. /**
  344. * Update list of available physical devices.
  345. */
  346. UI.onAvailableDevicesChanged = function() {
  347. APP.conference.updateAudioIconEnabled();
  348. APP.conference.updateVideoIconEnabled();
  349. };
  350. /**
  351. * Returns the id of the current video shown on large.
  352. * Currently used by tests (torture).
  353. */
  354. UI.getLargeVideoID = function() {
  355. return VideoLayout.getLargeVideoID();
  356. };
  357. /**
  358. * Returns the current video shown on large.
  359. * Currently used by tests (torture).
  360. */
  361. UI.getLargeVideo = function() {
  362. return VideoLayout.getLargeVideo();
  363. };
  364. /**
  365. * Show shared video.
  366. * @param {string} id the id of the sender of the command
  367. * @param {string} url video url
  368. * @param {string} attributes
  369. */
  370. UI.onSharedVideoStart = function(id, url, attributes) {
  371. if (sharedVideoManager) {
  372. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  373. }
  374. };
  375. /**
  376. * Update shared video.
  377. * @param {string} id the id of the sender of the command
  378. * @param {string} url video url
  379. * @param {string} attributes
  380. */
  381. UI.onSharedVideoUpdate = function(id, url, attributes) {
  382. if (sharedVideoManager) {
  383. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  384. }
  385. };
  386. /**
  387. * Stop showing shared video.
  388. * @param {string} id the id of the sender of the command
  389. * @param {string} attributes
  390. */
  391. UI.onSharedVideoStop = function(id, attributes) {
  392. if (sharedVideoManager) {
  393. sharedVideoManager.onSharedVideoStop(id, attributes);
  394. }
  395. };
  396. /**
  397. * Show shared video.
  398. * @param {string} url video url
  399. */
  400. UI.startSharedVideoEmitter = function(url) {
  401. if (sharedVideoManager) {
  402. sharedVideoManager.startSharedVideoEmitter(url);
  403. }
  404. };
  405. /**
  406. * Stop shared video.
  407. */
  408. UI.stopSharedVideoEmitter = function() {
  409. if (sharedVideoManager) {
  410. sharedVideoManager.stopSharedVideoEmitter();
  411. }
  412. };
  413. // TODO: Export every function separately. For now there is no point of doing
  414. // this because we are importing everything.
  415. export default UI;