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

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