You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UI.js 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. /* global APP, config */
  2. const UI = {};
  3. import Logger from '@jitsi/logger';
  4. import EventEmitter from 'events';
  5. import $ from 'jquery';
  6. import { isMobileBrowser } from '../../react/features/base/environment/utils';
  7. import { setColorAlpha } from '../../react/features/base/util';
  8. import { setDocumentUrl } from '../../react/features/etherpad';
  9. import { setFilmstripVisible } from '../../react/features/filmstrip';
  10. import {
  11. NOTIFICATION_TIMEOUT_TYPE,
  12. joinLeaveNotificationsDisabled,
  13. setNotificationsEnabled,
  14. showNotification
  15. } from '../../react/features/notifications';
  16. import {
  17. dockToolbox,
  18. setToolboxEnabled,
  19. showToolbox
  20. } from '../../react/features/toolbox/actions.web';
  21. import UIEvents from '../../service/UI/UIEvents';
  22. import EtherpadManager from './etherpad/Etherpad';
  23. import messageHandler from './util/MessageHandler';
  24. import UIUtil from './util/UIUtil';
  25. import VideoLayout from './videolayout/VideoLayout';
  26. const logger = Logger.getLogger(__filename);
  27. UI.messageHandler = messageHandler;
  28. const eventEmitter = new EventEmitter();
  29. UI.eventEmitter = eventEmitter;
  30. let etherpadManager;
  31. const UIListeners = new Map([
  32. [
  33. UIEvents.ETHERPAD_CLICKED,
  34. () => etherpadManager && etherpadManager.toggleEtherpad()
  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. * Notify user that server has shut down.
  51. */
  52. UI.notifyGracefulShutdown = function() {
  53. messageHandler.showError({
  54. descriptionKey: 'dialog.gracefulShutdown',
  55. titleKey: 'dialog.serviceUnavailable'
  56. });
  57. };
  58. /**
  59. * Notify user that reservation error happened.
  60. */
  61. UI.notifyReservationError = function(code, msg) {
  62. messageHandler.showError({
  63. descriptionArguments: {
  64. code,
  65. msg
  66. },
  67. descriptionKey: 'dialog.reservationErrorMsg',
  68. titleKey: 'dialog.reservationError'
  69. });
  70. };
  71. /**
  72. * Initialize conference UI.
  73. */
  74. UI.initConference = function() {
  75. UI.showToolbar();
  76. };
  77. /**
  78. * Starts the UI module and initializes all related components.
  79. *
  80. * @returns {boolean} true if the UI is ready and the conference should be
  81. * established, false - otherwise (for example in the case of welcome page)
  82. */
  83. UI.start = function() {
  84. VideoLayout.initLargeVideo();
  85. // Do not animate the video area on UI start (second argument passed into
  86. // resizeVideoArea) because the animation is not visible anyway. Plus with
  87. // the current dom layout, the quality label is part of the video layout and
  88. // will be seen animating in.
  89. VideoLayout.resizeVideoArea();
  90. if (isMobileBrowser()) {
  91. $('body').addClass('mobile-browser');
  92. } else {
  93. $('body').addClass('desktop-browser');
  94. }
  95. if (config.backgroundAlpha !== undefined) {
  96. const backgroundColor = $('body').css('background-color');
  97. const alphaColor = setColorAlpha(backgroundColor, config.backgroundAlpha);
  98. $('body').css('background-color', alphaColor);
  99. }
  100. if (config.iAmRecorder) {
  101. // in case of iAmSipGateway keep local video visible
  102. if (!config.iAmSipGateway) {
  103. APP.store.dispatch(setNotificationsEnabled(false));
  104. }
  105. APP.store.dispatch(setToolboxEnabled(false));
  106. }
  107. };
  108. /**
  109. * Setup some UI event listeners.
  110. */
  111. UI.registerListeners
  112. = () => UIListeners.forEach((value, key) => UI.addListener(key, value));
  113. /**
  114. * Setup some DOM event listeners.
  115. */
  116. UI.bindEvents = () => {
  117. /**
  118. *
  119. */
  120. function onResize() {
  121. VideoLayout.onResize();
  122. }
  123. // Resize and reposition videos in full screen mode.
  124. $(document).on(
  125. 'webkitfullscreenchange mozfullscreenchange fullscreenchange',
  126. onResize);
  127. $(window).resize(onResize);
  128. };
  129. /**
  130. * Unbind some DOM event listeners.
  131. */
  132. UI.unbindEvents = () => {
  133. $(document).off(
  134. 'webkitfullscreenchange mozfullscreenchange fullscreenchange');
  135. $(window).off('resize');
  136. };
  137. /**
  138. * Setup and show Etherpad.
  139. * @param {string} name etherpad id
  140. */
  141. UI.initEtherpad = name => {
  142. if (etherpadManager || !config.etherpad_base || !name) {
  143. return;
  144. }
  145. logger.log('Etherpad is enabled');
  146. etherpadManager = new EtherpadManager(eventEmitter);
  147. const url = new URL(name, config.etherpad_base);
  148. APP.store.dispatch(setDocumentUrl(url.toString()));
  149. if (config.openSharedDocumentOnJoin) {
  150. etherpadManager.toggleEtherpad();
  151. }
  152. };
  153. /**
  154. * Returns the shared document manager object.
  155. * @return {EtherpadManager} the shared document manager object
  156. */
  157. UI.getSharedDocumentManager = () => etherpadManager;
  158. /**
  159. * Show user on UI.
  160. * @param {JitsiParticipant} user
  161. */
  162. UI.addUser = function(user) {
  163. const status = user.getStatus();
  164. if (status) {
  165. // FIXME: move updateUserStatus in participantPresenceChanged action
  166. UI.updateUserStatus(user, status);
  167. }
  168. };
  169. /**
  170. * Updates the user status.
  171. *
  172. * @param {JitsiParticipant} user - The user which status we need to update.
  173. * @param {string} status - The new status.
  174. */
  175. UI.updateUserStatus = (user, status) => {
  176. const reduxState = APP.store.getState() || {};
  177. const { calleeInfoVisible } = reduxState['features/invite'] || {};
  178. // We hide status updates when join/leave notifications are disabled,
  179. // as jigasi is the component with statuses and they are seen as join/leave notifications.
  180. if (!status || calleeInfoVisible || joinLeaveNotificationsDisabled()) {
  181. return;
  182. }
  183. const displayName = user.getDisplayName();
  184. APP.store.dispatch(showNotification({
  185. titleKey: `${displayName} connected`,
  186. descriptionKey: 'dialOut.statusMessage'
  187. }, NOTIFICATION_TIMEOUT_TYPE.SHORT));
  188. };
  189. /**
  190. * Toggles filmstrip.
  191. */
  192. UI.toggleFilmstrip = function() {
  193. const { visible } = APP.store.getState()['features/filmstrip'];
  194. APP.store.dispatch(setFilmstripVisible(!visible));
  195. };
  196. /**
  197. * Sets muted audio state for participant
  198. */
  199. UI.setAudioMuted = function(id) {
  200. // FIXME: Maybe this can be removed!
  201. if (APP.conference.isLocalId(id)) {
  202. APP.conference.updateAudioIconEnabled();
  203. }
  204. };
  205. /**
  206. * Sets muted video state for participant
  207. */
  208. UI.setVideoMuted = function(id) {
  209. VideoLayout._updateLargeVideoIfDisplayed(id, true);
  210. if (APP.conference.isLocalId(id)) {
  211. APP.conference.updateVideoIconEnabled();
  212. }
  213. };
  214. UI.updateLargeVideo = (id, forceUpdate) => VideoLayout.updateLargeVideo(id, forceUpdate);
  215. /**
  216. * Adds a listener that would be notified on the given type of event.
  217. *
  218. * @param type the type of the event we're listening for
  219. * @param listener a function that would be called when notified
  220. */
  221. UI.addListener = function(type, listener) {
  222. eventEmitter.on(type, listener);
  223. };
  224. /**
  225. * Removes the all listeners for all events.
  226. *
  227. * @returns {void}
  228. */
  229. UI.removeAllListeners = function() {
  230. eventEmitter.removeAllListeners();
  231. };
  232. /**
  233. * Emits the event of given type by specifying the parameters in options.
  234. *
  235. * @param type the type of the event we're emitting
  236. * @param options the parameters for the event
  237. */
  238. UI.emitEvent = (type, ...options) => eventEmitter.emit(type, ...options);
  239. // Used by torture.
  240. UI.showToolbar = timeout => APP.store.dispatch(showToolbox(timeout));
  241. // Used by torture.
  242. UI.dockToolbar = dock => APP.store.dispatch(dockToolbox(dock));
  243. /**
  244. * Notify user that connection failed.
  245. * @param {string} stropheErrorMsg raw Strophe error message
  246. */
  247. UI.notifyConnectionFailed = function(stropheErrorMsg) {
  248. let descriptionKey;
  249. let descriptionArguments;
  250. if (stropheErrorMsg) {
  251. descriptionKey = 'dialog.connectErrorWithMsg';
  252. descriptionArguments = { msg: stropheErrorMsg };
  253. } else {
  254. descriptionKey = 'dialog.connectError';
  255. }
  256. messageHandler.showError({
  257. descriptionArguments,
  258. descriptionKey,
  259. titleKey: 'connection.CONNFAIL'
  260. });
  261. };
  262. /**
  263. * Notify user that maximum users limit has been reached.
  264. */
  265. UI.notifyMaxUsersLimitReached = function() {
  266. messageHandler.showError({
  267. hideErrorSupportLink: true,
  268. descriptionKey: 'dialog.maxUsersLimitReached',
  269. titleKey: 'dialog.maxUsersLimitReachedTitle'
  270. });
  271. };
  272. UI.handleLastNEndpoints = function(leavingIds, enteringIds) {
  273. VideoLayout.onLastNEndpointsChanged(leavingIds, enteringIds);
  274. };
  275. /**
  276. * Update audio level visualization for specified user.
  277. * @param {string} id user id
  278. * @param {number} lvl audio level
  279. */
  280. UI.setAudioLevel = (id, lvl) => VideoLayout.setAudioLevel(id, lvl);
  281. UI.notifyTokenAuthFailed = function() {
  282. messageHandler.showError({
  283. descriptionKey: 'dialog.tokenAuthFailed',
  284. titleKey: 'dialog.tokenAuthFailedTitle'
  285. });
  286. };
  287. /**
  288. * Update list of available physical devices.
  289. */
  290. UI.onAvailableDevicesChanged = function() {
  291. APP.conference.updateAudioIconEnabled();
  292. APP.conference.updateVideoIconEnabled();
  293. };
  294. /**
  295. * Returns the id of the current video shown on large.
  296. * Currently used by tests (torture).
  297. */
  298. UI.getLargeVideoID = function() {
  299. return VideoLayout.getLargeVideoID();
  300. };
  301. /**
  302. * Returns the current video shown on large.
  303. * Currently used by tests (torture).
  304. */
  305. UI.getLargeVideo = function() {
  306. return VideoLayout.getLargeVideo();
  307. };
  308. // TODO: Export every function separately. For now there is no point of doing
  309. // this because we are importing everything.
  310. export default UI;