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.7KB

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