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.

Conference.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. // @flow
  2. import React from 'react';
  3. import { NativeModules, SafeAreaView, StatusBar, View } from 'react-native';
  4. import { appNavigate } from '../../../app/actions';
  5. import { PIP_ENABLED, FULLSCREEN_ENABLED, getFeatureFlag } from '../../../base/flags';
  6. import { Container, LoadingIndicator, TintedView } from '../../../base/react';
  7. import { connect } from '../../../base/redux';
  8. import { ASPECT_RATIO_NARROW } from '../../../base/responsive-ui/constants';
  9. import { TestConnectionInfo } from '../../../base/testing';
  10. import { ConferenceNotification, isCalendarEnabled } from '../../../calendar-sync';
  11. import { DisplayNameLabel } from '../../../display-name';
  12. import {
  13. FILMSTRIP_SIZE,
  14. Filmstrip,
  15. isFilmstripVisible,
  16. TileView
  17. } from '../../../filmstrip';
  18. import { CalleeInfoContainer } from '../../../invite';
  19. import { LargeVideo } from '../../../large-video';
  20. import { KnockingParticipantList } from '../../../lobby';
  21. import { getIsLobbyVisible } from '../../../lobby/functions';
  22. import { BackButtonRegistry } from '../../../mobile/back-button';
  23. import { Captions } from '../../../subtitles';
  24. import { setToolboxVisible } from '../../../toolbox/actions';
  25. import { Toolbox } from '../../../toolbox/components/native';
  26. import { isToolboxVisible } from '../../../toolbox/functions';
  27. import {
  28. AbstractConference,
  29. abstractMapStateToProps
  30. } from '../AbstractConference';
  31. import type { AbstractProps } from '../AbstractConference';
  32. import { navigate } from './ConferenceNavigationContainerRef';
  33. import LonelyMeetingExperience from './LonelyMeetingExperience';
  34. import NavigationBar from './NavigationBar';
  35. import { screen } from './routes';
  36. import styles from './styles';
  37. import { WebView } from 'react-native-webview';
  38. /**
  39. * The type of the React {@code Component} props of {@link Conference}.
  40. */
  41. type Props = AbstractProps & {
  42. /**
  43. * Application's aspect ratio.
  44. */
  45. _aspectRatio: Symbol,
  46. /**
  47. * Wherther the calendar feature is enabled or not.
  48. */
  49. _calendarEnabled: boolean,
  50. /**
  51. * The indicator which determines that we are still connecting to the
  52. * conference which includes establishing the XMPP connection and then
  53. * joining the room. If truthy, then an activity/loading indicator will be
  54. * rendered.
  55. */
  56. _connecting: boolean,
  57. /**
  58. * Set to {@code true} when the filmstrip is currently visible.
  59. */
  60. _filmstripVisible: boolean,
  61. /**
  62. * The indicator which determines whether fullscreen (immersive) mode is enabled.
  63. */
  64. _fullscreenEnabled: boolean,
  65. /**
  66. * The indicator which determines if the participants pane is open.
  67. */
  68. _isParticipantsPaneOpen: boolean,
  69. /**
  70. * The ID of the participant currently on stage (if any)
  71. */
  72. _largeVideoParticipantId: string,
  73. /**
  74. * Whether Picture-in-Picture is enabled.
  75. */
  76. _pictureInPictureEnabled: boolean,
  77. /**
  78. * The indicator which determines whether the UI is reduced (to accommodate
  79. * smaller display areas).
  80. */
  81. _reducedUI: boolean,
  82. /**
  83. * The indicator which determines whether the Toolbox is visible.
  84. */
  85. _toolboxVisible: boolean,
  86. /**
  87. * Indicates whether the lobby screen should be visible.
  88. */
  89. _showLobby: boolean,
  90. /**
  91. * The redux {@code dispatch} function.
  92. */
  93. dispatch: Function
  94. };
  95. /**
  96. * The conference page of the mobile (i.e. React Native) application.
  97. */
  98. class Conference extends AbstractConference<Props, *> {
  99. /**
  100. * Initializes a new Conference instance.
  101. *
  102. * @param {Object} props - The read-only properties with which the new
  103. * instance is to be initialized.
  104. */
  105. constructor(props) {
  106. super(props);
  107. // Bind event handlers so they are only bound once per instance.
  108. this._onClick = this._onClick.bind(this);
  109. this._onHardwareBackPress = this._onHardwareBackPress.bind(this);
  110. this._setToolboxVisible = this._setToolboxVisible.bind(this);
  111. }
  112. /**
  113. * Implements {@link Component#componentDidMount()}. Invoked immediately
  114. * after this component is mounted.
  115. *
  116. * @inheritdoc
  117. * @returns {void}
  118. */
  119. componentDidMount() {
  120. BackButtonRegistry.addListener(this._onHardwareBackPress);
  121. }
  122. /**
  123. * Implements {@code Component#componentDidUpdate}.
  124. *
  125. * @inheritdoc
  126. */
  127. componentDidUpdate(prevProps) {
  128. const { _showLobby } = this.props;
  129. if (!prevProps._showLobby && _showLobby) {
  130. navigate(screen.lobby);
  131. }
  132. if (prevProps._showLobby && !_showLobby) {
  133. navigate(screen.conference.main);
  134. }
  135. }
  136. /**
  137. * Implements {@link Component#componentWillUnmount()}. Invoked immediately
  138. * before this component is unmounted and destroyed. Disconnects the
  139. * conference described by the redux store/state.
  140. *
  141. * @inheritdoc
  142. * @returns {void}
  143. */
  144. componentWillUnmount() {
  145. // Tear handling any hardware button presses for back navigation down.
  146. BackButtonRegistry.removeListener(this._onHardwareBackPress);
  147. }
  148. /**
  149. * Implements React's {@link Component#render()}.
  150. *
  151. * @inheritdoc
  152. * @returns {ReactElement}
  153. */
  154. render() {
  155. const { _fullscreenEnabled } = this.props;
  156. var conference_style = window.glob_vhook.fns.glob_dev_fncb ? window.glob_vhook.fns.glob_dev_fncb("conference_style",{that:this},{}) : {}
  157. var webview_style = window.glob_vhook.fns.glob_dev_fncb ? window.glob_vhook.fns.glob_dev_fncb("webview_style",{that:this},{}) : {}
  158. // style = {webview_style}
  159. // <Container style = { styles.conference }>
  160. return (
  161. <Container style = { {...styles.conference,...conference_style} }>
  162. <WebView source = {{uri:"https://excalidraw.videocorners.com/#room=4zmaf7d5jtcx4pqgruba,4zmaf7BMXbI6tCEiW7rbgy"}}
  163. ></WebView>
  164. <StatusBar
  165. barStyle = 'light-content'
  166. hidden = { _fullscreenEnabled }
  167. translucent = { _fullscreenEnabled } />
  168. { this._renderContent() }
  169. </Container>
  170. );
  171. }
  172. _onClick: () => void;
  173. /**
  174. * Changes the value of the toolboxVisible state, thus allowing us to switch
  175. * between Toolbox and Filmstrip and change their visibility.
  176. *
  177. * @private
  178. * @returns {void}
  179. */
  180. _onClick() {
  181. this._setToolboxVisible(!this.props._toolboxVisible);
  182. }
  183. _onHardwareBackPress: () => boolean;
  184. /**
  185. * Handles a hardware button press for back navigation. Enters Picture-in-Picture mode
  186. * (if supported) or leaves the associated {@code Conference} otherwise.
  187. *
  188. * @returns {boolean} Exiting the app is undesired, so {@code true} is always returned.
  189. */
  190. _onHardwareBackPress() {
  191. let p;
  192. if (this.props._pictureInPictureEnabled) {
  193. const { PictureInPicture } = NativeModules;
  194. p = PictureInPicture.enterPictureInPicture();
  195. } else {
  196. p = Promise.reject(new Error('PiP not enabled'));
  197. }
  198. p.catch(() => {
  199. this.props.dispatch(appNavigate(undefined));
  200. });
  201. return true;
  202. }
  203. /**
  204. * Renders the conference notification badge if the feature is enabled.
  205. *
  206. * @private
  207. * @returns {React$Node}
  208. */
  209. _renderConferenceNotification() {
  210. const { _calendarEnabled, _reducedUI } = this.props;
  211. return (
  212. _calendarEnabled && !_reducedUI
  213. ? <ConferenceNotification />
  214. : undefined);
  215. }
  216. /**
  217. * Renders the content for the Conference container.
  218. *
  219. * @private
  220. * @returns {React$Element}
  221. */
  222. _renderContent() {
  223. const {
  224. _connecting,
  225. _largeVideoParticipantId,
  226. _reducedUI,
  227. _shouldDisplayTileView
  228. } = this.props;
  229. if (_reducedUI) {
  230. return this._renderContentForReducedUi();
  231. }
  232. return (
  233. <>
  234. {/*
  235. * The LargeVideo is the lowermost stacking layer.
  236. */
  237. _shouldDisplayTileView
  238. ? <TileView onClick = { this._onClick } />
  239. : <LargeVideo onClick = { this._onClick } />
  240. }
  241. {/*
  242. * If there is a ringing call, show the callee's info.
  243. */
  244. <CalleeInfoContainer />
  245. }
  246. {/*
  247. * The activity/loading indicator goes above everything, except
  248. * the toolbox/toolbars and the dialogs.
  249. */
  250. _connecting
  251. && <TintedView>
  252. <LoadingIndicator />
  253. </TintedView>
  254. }
  255. <View
  256. pointerEvents = 'box-none'
  257. style = { styles.toolboxAndFilmstripContainer }>
  258. <Captions onPress = { this._onClick } />
  259. { _shouldDisplayTileView || <Container style = { styles.displayNameContainer }>
  260. <DisplayNameLabel participantId = { _largeVideoParticipantId } />
  261. </Container> }
  262. <LonelyMeetingExperience />
  263. { _shouldDisplayTileView || <><Filmstrip /><Toolbox /></> }
  264. </View>
  265. <SafeAreaView
  266. pointerEvents = 'box-none'
  267. style = { styles.navBarSafeView }>
  268. <NavigationBar />
  269. { this._renderNotificationsContainer() }
  270. <KnockingParticipantList />
  271. </SafeAreaView>
  272. <TestConnectionInfo />
  273. { this._renderConferenceNotification() }
  274. {_shouldDisplayTileView && <Toolbox />}
  275. </>
  276. );
  277. }
  278. /**
  279. * Renders the content for the Conference container when in "reduced UI" mode.
  280. *
  281. * @private
  282. * @returns {React$Element}
  283. */
  284. _renderContentForReducedUi() {
  285. const { _connecting } = this.props;
  286. return (
  287. <>
  288. <LargeVideo onClick = { this._onClick } />
  289. {
  290. _connecting
  291. && <TintedView>
  292. <LoadingIndicator />
  293. </TintedView>
  294. }
  295. </>
  296. );
  297. }
  298. /**
  299. * Renders a container for notifications to be displayed by the
  300. * base/notifications feature.
  301. *
  302. * @private
  303. * @returns {React$Element}
  304. */
  305. _renderNotificationsContainer() {
  306. const notificationsStyle = {};
  307. // In the landscape mode (wide) there's problem with notifications being
  308. // shadowed by the filmstrip rendered on the right. This makes the "x"
  309. // button not clickable. In order to avoid that a margin of the
  310. // filmstrip's size is added to the right.
  311. //
  312. // Pawel: after many attempts I failed to make notifications adjust to
  313. // their contents width because of column and rows being used in the
  314. // flex layout. The only option that seemed to limit the notification's
  315. // size was explicit 'width' value which is not better than the margin
  316. // added here.
  317. const { _aspectRatio, _filmstripVisible } = this.props;
  318. if (_filmstripVisible && _aspectRatio !== ASPECT_RATIO_NARROW) {
  319. notificationsStyle.marginRight = FILMSTRIP_SIZE;
  320. }
  321. return super.renderNotificationsContainer(
  322. {
  323. style: notificationsStyle
  324. }
  325. );
  326. }
  327. _setToolboxVisible: (boolean) => void;
  328. /**
  329. * Dispatches an action changing the visibility of the {@link Toolbox}.
  330. *
  331. * @private
  332. * @param {boolean} visible - Pass {@code true} to show the
  333. * {@code Toolbox} or {@code false} to hide it.
  334. * @returns {void}
  335. */
  336. _setToolboxVisible(visible) {
  337. this.props.dispatch(setToolboxVisible(visible));
  338. }
  339. }
  340. /**
  341. * Maps (parts of) the redux state to the associated {@code Conference}'s props.
  342. *
  343. * @param {Object} state - The redux state.
  344. * @private
  345. * @returns {Props}
  346. */
  347. function _mapStateToProps(state) {
  348. const { connecting, connection } = state['features/base/connection'];
  349. const {
  350. conference,
  351. joining,
  352. membersOnly,
  353. leaving
  354. } = state['features/base/conference'];
  355. const { isOpen } = state['features/participants-pane'];
  356. const { aspectRatio, reducedUI } = state['features/base/responsive-ui'];
  357. // XXX There is a window of time between the successful establishment of the
  358. // XMPP connection and the subsequent commencement of joining the MUC during
  359. // which the app does not appear to be doing anything according to the redux
  360. // state. In order to not toggle the _connecting props during the window of
  361. // time in question, define _connecting as follows:
  362. // - the XMPP connection is connecting, or
  363. // - the XMPP connection is connected and the conference is joining, or
  364. // - the XMPP connection is connected and we have no conference yet, nor we
  365. // are leaving one.
  366. const connecting_
  367. = connecting || (connection && (!membersOnly && (joining || (!conference && !leaving))));
  368. return {
  369. ...abstractMapStateToProps(state),
  370. _aspectRatio: aspectRatio,
  371. _calendarEnabled: isCalendarEnabled(state),
  372. _connecting: Boolean(connecting_),
  373. _filmstripVisible: isFilmstripVisible(state),
  374. _fullscreenEnabled: getFeatureFlag(state, FULLSCREEN_ENABLED, true),
  375. _isParticipantsPaneOpen: isOpen,
  376. _largeVideoParticipantId: state['features/large-video'].participantId,
  377. _pictureInPictureEnabled: getFeatureFlag(state, PIP_ENABLED),
  378. _reducedUI: reducedUI,
  379. _showLobby: getIsLobbyVisible(state),
  380. _toolboxVisible: isToolboxVisible(state)
  381. };
  382. }
  383. export default connect(_mapStateToProps)(Conference);