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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  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. if (config.openSharedDocumentOnJoin) {
  186. etherpadManager.toggleEtherpad();
  187. }
  188. };
  189. /**
  190. * Returns the shared document manager object.
  191. * @return {EtherpadManager} the shared document manager object
  192. */
  193. UI.getSharedDocumentManager = () => etherpadManager;
  194. /**
  195. * Show user on UI.
  196. * @param {JitsiParticipant} user
  197. */
  198. UI.addUser = function(user) {
  199. const id = user.getId();
  200. const displayName = user.getDisplayName();
  201. const status = user.getStatus();
  202. if (status) {
  203. // FIXME: move updateUserStatus in participantPresenceChanged action
  204. UI.updateUserStatus(user, status);
  205. }
  206. // set initial display name
  207. if (displayName) {
  208. UI.changeDisplayName(id, displayName);
  209. }
  210. };
  211. /**
  212. * Update videotype for specified user.
  213. * @param {string} id user id
  214. * @param {string} newVideoType new videotype
  215. */
  216. UI.onPeerVideoTypeChanged
  217. = (id, newVideoType) => VideoLayout.onVideoTypeChanged(id, newVideoType);
  218. /**
  219. * Updates the user status.
  220. *
  221. * @param {JitsiParticipant} user - The user which status we need to update.
  222. * @param {string} status - The new status.
  223. */
  224. UI.updateUserStatus = (user, status) => {
  225. const reduxState = APP.store.getState() || {};
  226. const { calleeInfoVisible } = reduxState['features/invite'] || {};
  227. // We hide status updates when join/leave notifications are disabled,
  228. // as jigasi is the component with statuses and they are seen as join/leave notifications.
  229. if (!status || calleeInfoVisible || joinLeaveNotificationsDisabled()) {
  230. return;
  231. }
  232. const displayName = user.getDisplayName();
  233. messageHandler.participantNotification(
  234. displayName,
  235. '',
  236. 'connected',
  237. 'dialOut.statusMessage',
  238. { status: UIUtil.escapeHtml(status) });
  239. };
  240. /**
  241. * Toggles filmstrip.
  242. */
  243. UI.toggleFilmstrip = function() {
  244. const { visible } = APP.store.getState()['features/filmstrip'];
  245. APP.store.dispatch(setFilmstripVisible(!visible));
  246. };
  247. /**
  248. * Toggles the visibility of the chat panel.
  249. */
  250. UI.toggleChat = () => APP.store.dispatch(toggleChat());
  251. /**
  252. * Sets muted audio state for participant
  253. */
  254. UI.setAudioMuted = function(id) {
  255. // FIXME: Maybe this can be removed!
  256. if (APP.conference.isLocalId(id)) {
  257. APP.conference.updateAudioIconEnabled();
  258. }
  259. };
  260. /**
  261. * Sets muted video state for participant
  262. */
  263. UI.setVideoMuted = function(id) {
  264. VideoLayout.onVideoMute(id);
  265. if (APP.conference.isLocalId(id)) {
  266. APP.conference.updateVideoIconEnabled();
  267. }
  268. };
  269. /**
  270. * Triggers an update of remote video and large video displays so they may pick
  271. * up any state changes that have occurred elsewhere.
  272. *
  273. * @returns {void}
  274. */
  275. UI.updateAllVideos = () => VideoLayout.updateAllVideos();
  276. /**
  277. * Adds a listener that would be notified on the given type of event.
  278. *
  279. * @param type the type of the event we're listening for
  280. * @param listener a function that would be called when notified
  281. */
  282. UI.addListener = function(type, listener) {
  283. eventEmitter.on(type, listener);
  284. };
  285. /**
  286. * Removes the all listeners for all events.
  287. *
  288. * @returns {void}
  289. */
  290. UI.removeAllListeners = function() {
  291. eventEmitter.removeAllListeners();
  292. };
  293. /**
  294. * Removes the given listener for the given type of event.
  295. *
  296. * @param type the type of the event we're listening for
  297. * @param listener the listener we want to remove
  298. */
  299. UI.removeListener = function(type, listener) {
  300. eventEmitter.removeListener(type, listener);
  301. };
  302. /**
  303. * Emits the event of given type by specifying the parameters in options.
  304. *
  305. * @param type the type of the event we're emitting
  306. * @param options the parameters for the event
  307. */
  308. UI.emitEvent = (type, ...options) => eventEmitter.emit(type, ...options);
  309. UI.clickOnVideo = videoNumber => VideoLayout.togglePin(videoNumber);
  310. // Used by torture.
  311. UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  312. // Used by torture.
  313. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  314. /**
  315. * Updates the displayed avatar for participant.
  316. *
  317. * @param {string} id - User id whose avatar should be updated.
  318. * @param {string} avatarURL - The URL to avatar image to display.
  319. * @returns {void}
  320. */
  321. UI.refreshAvatarDisplay = function(id) {
  322. VideoLayout.changeUserAvatar(id);
  323. };
  324. /**
  325. * Notify user that connection failed.
  326. * @param {string} stropheErrorMsg raw Strophe error message
  327. */
  328. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  329. let descriptionKey;
  330. let descriptionArguments;
  331. if (stropheErrorMsg) {
  332. descriptionKey = 'dialog.connectErrorWithMsg';
  333. descriptionArguments = { msg: stropheErrorMsg };
  334. } else {
  335. descriptionKey = 'dialog.connectError';
  336. }
  337. messageHandler.showError({
  338. descriptionArguments,
  339. descriptionKey,
  340. titleKey: 'connection.CONNFAIL'
  341. });
  342. };
  343. /**
  344. * Notify user that maximum users limit has been reached.
  345. */
  346. UI.notifyMaxUsersLimitReached = function() {
  347. messageHandler.showError({
  348. hideErrorSupportLink: true,
  349. descriptionKey: 'dialog.maxUsersLimitReached',
  350. titleKey: 'dialog.maxUsersLimitReachedTitle'
  351. });
  352. };
  353. /**
  354. * Notify user that he was automatically muted when joned the conference.
  355. */
  356. UI.notifyInitiallyMuted = function() {
  357. messageHandler.participantNotification(
  358. null,
  359. 'notify.mutedTitle',
  360. 'connected',
  361. 'notify.muted',
  362. null);
  363. };
  364. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  365. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  366. };
  367. /**
  368. * Update audio level visualization for specified user.
  369. * @param {string} id user id
  370. * @param {number} lvl audio level
  371. */
  372. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  373. /**
  374. * Hide connection quality statistics from UI.
  375. */
  376. UI.hideStats = function() {
  377. VideoLayout.hideStats();
  378. };
  379. UI.notifyTokenAuthFailed = function() {
  380. messageHandler.showError({
  381. descriptionKey: 'dialog.tokenAuthFailed',
  382. titleKey: 'dialog.tokenAuthFailedTitle'
  383. });
  384. };
  385. UI.notifyFocusDisconnected = function(focus, retrySec) {
  386. messageHandler.participantNotification(
  387. null, 'notify.focus',
  388. 'disconnected', 'notify.focusFail',
  389. { component: focus,
  390. ms: retrySec }
  391. );
  392. };
  393. /**
  394. * Update list of available physical devices.
  395. */
  396. UI.onAvailableDevicesChanged = function() {
  397. APP.conference.updateAudioIconEnabled();
  398. APP.conference.updateVideoIconEnabled();
  399. };
  400. /**
  401. * Returns the id of the current video shown on large.
  402. * Currently used by tests (torture).
  403. */
  404. UI.getLargeVideoID = function() {
  405. return VideoLayout.getLargeVideoID();
  406. };
  407. /**
  408. * Returns the current video shown on large.
  409. * Currently used by tests (torture).
  410. */
  411. UI.getLargeVideo = function() {
  412. return VideoLayout.getLargeVideo();
  413. };
  414. /**
  415. * Show shared video.
  416. * @param {string} id the id of the sender of the command
  417. * @param {string} url video url
  418. * @param {string} attributes
  419. */
  420. UI.onSharedVideoStart = function(id, url, attributes) {
  421. if (sharedVideoManager) {
  422. sharedVideoManager.onSharedVideoStart(id, url, attributes);
  423. }
  424. };
  425. /**
  426. * Update shared video.
  427. * @param {string} id the id of the sender of the command
  428. * @param {string} url video url
  429. * @param {string} attributes
  430. */
  431. UI.onSharedVideoUpdate = function(id, url, attributes) {
  432. if (sharedVideoManager) {
  433. sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
  434. }
  435. };
  436. /**
  437. * Stop showing shared video.
  438. * @param {string} id the id of the sender of the command
  439. * @param {string} attributes
  440. */
  441. UI.onSharedVideoStop = function(id, attributes) {
  442. if (sharedVideoManager) {
  443. sharedVideoManager.onSharedVideoStop(id, attributes);
  444. }
  445. };
  446. // TODO: Export every function separately. For now there is no point of doing
  447. // this because we are importing everything.
  448. export default UI;