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

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