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

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