您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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 { setColorAlpha } from '../../react/features/base/util';
  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. * Starts the UI module and initializes all related components.
  85. *
  86. * @returns {boolean} true if the UI is ready and the conference should be
  87. * established, false - otherwise (for example in the case of welcome page)
  88. */
  89. UI.start = function() {
  90. VideoLayout.initLargeVideo();
  91. // Do not animate the video area on UI start (second argument passed into
  92. // resizeVideoArea) because the animation is not visible anyway. Plus with
  93. // the current dom layout, the quality label is part of the video layout and
  94. // will be seen animating in.
  95. VideoLayout.resizeVideoArea();
  96. sharedVideoManager = new SharedVideoManager(eventEmitter);
  97. if (isMobileBrowser()) {
  98. $('body').addClass('mobile-browser');
  99. } else {
  100. $('body').addClass('desktop-browser');
  101. if (config.backgroundAlpha !== undefined) {
  102. const backgroundColor = $('body').css('background-color');
  103. const alphaColor = setColorAlpha(backgroundColor, config.backgroundAlpha);
  104. $('body').css('background-color', alphaColor);
  105. }
  106. }
  107. if (config.iAmRecorder) {
  108. // in case of iAmSipGateway keep local video visible
  109. if (!config.iAmSipGateway) {
  110. APP.store.dispatch(setNotificationsEnabled(false));
  111. }
  112. APP.store.dispatch(setToolboxEnabled(false));
  113. }
  114. };
  115. /**
  116. * Setup some UI event listeners.
  117. */
  118. UI.registerListeners
  119. = () => UIListeners.forEach((value, key) => UI.addListener(key, value));
  120. /**
  121. * Setup some DOM event listeners.
  122. */
  123. UI.bindEvents = () => {
  124. /**
  125. *
  126. */
  127. function onResize() {
  128. VideoLayout.onResize();
  129. }
  130. // Resize and reposition videos in full screen mode.
  131. $(document).on(
  132. 'webkitfullscreenchange mozfullscreenchange fullscreenchange',
  133. onResize);
  134. $(window).resize(onResize);
  135. };
  136. /**
  137. * Unbind some DOM event listeners.
  138. */
  139. UI.unbindEvents = () => {
  140. $(document).off(
  141. 'webkitfullscreenchange mozfullscreenchange fullscreenchange');
  142. $(window).off('resize');
  143. };
  144. /**
  145. * Setup and show Etherpad.
  146. * @param {string} name etherpad id
  147. */
  148. UI.initEtherpad = name => {
  149. if (etherpadManager || !config.etherpad_base || !name) {
  150. return;
  151. }
  152. logger.log('Etherpad is enabled');
  153. etherpadManager = new EtherpadManager(eventEmitter);
  154. const url = new URL(name, config.etherpad_base);
  155. APP.store.dispatch(setDocumentUrl(url.toString()));
  156. if (config.openSharedDocumentOnJoin) {
  157. etherpadManager.toggleEtherpad();
  158. }
  159. };
  160. /**
  161. * Returns the shared document manager object.
  162. * @return {EtherpadManager} the shared document manager object
  163. */
  164. UI.getSharedDocumentManager = () => etherpadManager;
  165. /**
  166. * Show user on UI.
  167. * @param {JitsiParticipant} user
  168. */
  169. UI.addUser = function(user) {
  170. const status = user.getStatus();
  171. if (status) {
  172. // FIXME: move updateUserStatus in participantPresenceChanged action
  173. UI.updateUserStatus(user, status);
  174. }
  175. };
  176. /**
  177. * Updates the user status.
  178. *
  179. * @param {JitsiParticipant} user - The user which status we need to update.
  180. * @param {string} status - The new status.
  181. */
  182. UI.updateUserStatus = (user, status) => {
  183. const reduxState = APP.store.getState() || {};
  184. const { calleeInfoVisible } = reduxState['features/invite'] || {};
  185. // We hide status updates when join/leave notifications are disabled,
  186. // as jigasi is the component with statuses and they are seen as join/leave notifications.
  187. if (!status || calleeInfoVisible || joinLeaveNotificationsDisabled()) {
  188. return;
  189. }
  190. const displayName = user.getDisplayName();
  191. messageHandler.participantNotification(
  192. displayName,
  193. '',
  194. 'connected',
  195. 'dialOut.statusMessage',
  196. { status: UIUtil.escapeHtml(status) });
  197. };
  198. /**
  199. * Toggles filmstrip.
  200. */
  201. UI.toggleFilmstrip = function() {
  202. const { visible } = APP.store.getState()['features/filmstrip'];
  203. APP.store.dispatch(setFilmstripVisible(!visible));
  204. };
  205. /**
  206. * Sets muted audio state for participant
  207. */
  208. UI.setAudioMuted = function(id) {
  209. // FIXME: Maybe this can be removed!
  210. if (APP.conference.isLocalId(id)) {
  211. APP.conference.updateAudioIconEnabled();
  212. }
  213. };
  214. /**
  215. * Sets muted video state for participant
  216. */
  217. UI.setVideoMuted = function(id) {
  218. VideoLayout._updateLargeVideoIfDisplayed(id, true);
  219. if (APP.conference.isLocalId(id)) {
  220. APP.conference.updateVideoIconEnabled();
  221. }
  222. };
  223. UI.updateLargeVideo = (id, forceUpdate) => VideoLayout.updateLargeVideo(id, forceUpdate);
  224. /**
  225. * Adds a listener that would be notified on the given type of event.
  226. *
  227. * @param type the type of the event we're listening for
  228. * @param listener a function that would be called when notified
  229. */
  230. UI.addListener = function(type, listener) {
  231. eventEmitter.on(type, listener);
  232. };
  233. /**
  234. * Removes the all listeners for all events.
  235. *
  236. * @returns {void}
  237. */
  238. UI.removeAllListeners = function() {
  239. eventEmitter.removeAllListeners();
  240. };
  241. /**
  242. * Emits the event of given type by specifying the parameters in options.
  243. *
  244. * @param type the type of the event we're emitting
  245. * @param options the parameters for the event
  246. */
  247. UI.emitEvent = (type, ...options) => eventEmitter.emit(type, ...options);
  248. // Used by torture.
  249. UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  250. // Used by torture.
  251. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  252. /**
  253. * Updates the displayed avatar for participant.
  254. *
  255. * @param {string} id - User id whose avatar should be updated.
  256. * @param {string} avatarURL - The URL to avatar image to display.
  257. * @returns {void}
  258. */
  259. UI.refreshAvatarDisplay = function(id) {
  260. VideoLayout.changeUserAvatar(id);
  261. };
  262. /**
  263. * Notify user that connection failed.
  264. * @param {string} stropheErrorMsg raw Strophe error message
  265. */
  266. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  267. let descriptionKey;
  268. let descriptionArguments;
  269. if (stropheErrorMsg) {
  270. descriptionKey = 'dialog.connectErrorWithMsg';
  271. descriptionArguments = { msg: stropheErrorMsg };
  272. } else {
  273. descriptionKey = 'dialog.connectError';
  274. }
  275. messageHandler.showError({
  276. descriptionArguments,
  277. descriptionKey,
  278. titleKey: 'connection.CONNFAIL'
  279. });
  280. };
  281. /**
  282. * Notify user that maximum users limit has been reached.
  283. */
  284. UI.notifyMaxUsersLimitReached = function() {
  285. messageHandler.showError({
  286. hideErrorSupportLink: true,
  287. descriptionKey: 'dialog.maxUsersLimitReached',
  288. titleKey: 'dialog.maxUsersLimitReachedTitle'
  289. });
  290. };
  291. /**
  292. * Notify user that he was automatically muted when joned the conference.
  293. */
  294. UI.notifyInitiallyMuted = function() {
  295. messageHandler.participantNotification(
  296. null,
  297. 'notify.mutedTitle',
  298. 'connected',
  299. 'notify.muted',
  300. null);
  301. };
  302. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  303. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  304. };
  305. /**
  306. * Update audio level visualization for specified user.
  307. * @param {string} id user id
  308. * @param {number} lvl audio level
  309. */
  310. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  311. UI.notifyTokenAuthFailed = function() {
  312. messageHandler.showError({
  313. descriptionKey: 'dialog.tokenAuthFailed',
  314. titleKey: 'dialog.tokenAuthFailedTitle'
  315. });
  316. };
  317. UI.notifyFocusDisconnected = function(focus, retrySec) {
  318. messageHandler.participantNotification(
  319. null, 'notify.focus',
  320. 'disconnected', 'notify.focusFail',
  321. { component: focus,
  322. ms: retrySec }
  323. );
  324. };
  325. /**
  326. * Update list of available physical devices.
  327. */
  328. UI.onAvailableDevicesChanged = function() {
  329. APP.conference.updateAudioIconEnabled();
  330. APP.conference.updateVideoIconEnabled();
  331. };
  332. /**
  333. * Returns the id of the current video shown on large.
  334. * Currently used by tests (torture).
  335. */
  336. UI.getLargeVideoID = function() {
  337. return VideoLayout.getLargeVideoID();
  338. };
  339. /**
  340. * Returns the current video shown on large.
  341. * Currently used by tests (torture).
  342. */
  343. UI.getLargeVideo = function() {
  344. return VideoLayout.getLargeVideo();
  345. };
  346. /**
  347. * Show shared video.
  348. * @param {string} id the id of the sender of the command
  349. * @param {string} url video url
  350. * @param {string} attributes
  351. */
  352. UI.onSharedVideoStart = function(id, url, attributes) {
  353. if (sharedVideoManager) {
  354. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  355. }
  356. };
  357. /**
  358. * Update shared video.
  359. * @param {string} id the id of the sender of the command
  360. * @param {string} url video url
  361. * @param {string} attributes
  362. */
  363. UI.onSharedVideoUpdate = function(id, url, attributes) {
  364. if (sharedVideoManager) {
  365. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  366. }
  367. };
  368. /**
  369. * Stop showing shared video.
  370. * @param {string} id the id of the sender of the command
  371. * @param {string} attributes
  372. */
  373. UI.onSharedVideoStop = function(id, attributes) {
  374. if (sharedVideoManager) {
  375. sharedVideoManager.onSharedVideoStop(id, attributes);
  376. }
  377. };
  378. /**
  379. * Show shared video.
  380. * @param {string} url video url
  381. */
  382. UI.startSharedVideoEmitter = function(url) {
  383. if (sharedVideoManager) {
  384. sharedVideoManager.startSharedVideoEmitter(url);
  385. }
  386. };
  387. /**
  388. * Stop shared video.
  389. */
  390. UI.stopSharedVideoEmitter = function() {
  391. if (sharedVideoManager) {
  392. sharedVideoManager.stopSharedVideoEmitter();
  393. }
  394. };
  395. // TODO: Export every function separately. For now there is no point of doing
  396. // this because we are importing everything.
  397. export default UI;