diff --git a/native/root.react.js b/native/root.react.js --- a/native/root.react.js +++ b/native/root.react.js @@ -24,6 +24,8 @@ import { ENSCacheProvider } from 'lib/components/ens-cache-provider.react.js'; import IntegrityHandler from 'lib/components/integrity-handler.react.js'; import { MediaCacheProvider } from 'lib/components/media-cache-provider.react.js'; +import { createTunnelbrokerSocket } from 'lib/shared/socket-utils.js'; +import { TunnelbrokerProvider } from 'lib/tunnelbroker/tunnelbroker-context.js'; import { actionLogger } from 'lib/utils/action-logger.js'; import { RegistrationContextProvider } from './account/registration/registration-context-provider.react.js'; @@ -64,6 +66,7 @@ import { DarkTheme, LightTheme } from './themes/navigation.js'; import ThemeHandler from './themes/theme-handler.react.js'; import { provider } from './utils/ethers-utils.js'; +import { useTunnelbrokerInitMessage } from './utils/tunnelbroker-utils.js'; // Add custom items to expo-dev-menu import './dev-menu.js'; @@ -236,6 +239,8 @@ return undefined; })(); + const tunnelbrokerInitMessage = useTunnelbrokerInitMessage(); + const gated: React.Node = ( <> @@ -273,51 +278,58 @@ return ( - - - - - - - - - - - - - - - - - - - {gated} - - - - - {navigation} - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + {gated} + + + + + {navigation} + + + + + + + + + + + + + + + + ); @@ -338,4 +350,5 @@ ); } + export default AppRoot; diff --git a/native/utils/tunnelbroker-utils.js b/native/utils/tunnelbroker-utils.js new file mode 100644 --- /dev/null +++ b/native/utils/tunnelbroker-utils.js @@ -0,0 +1,36 @@ +// @flow + +import * as React from 'react'; + +import type { ConnectionInitializationMessage } from 'lib/types/tunnelbroker/session-types.js'; + +import { getContentSigningKey } from './crypto-utils.js'; +import { useSelector } from '../redux/redux-utils.js'; + +function useTunnelbrokerInitMessage(): ?ConnectionInitializationMessage { + const [deviceID, setDeviceID] = React.useState(); + const userID = useSelector(state => state.currentUserInfo?.id); + const accessToken = useSelector(state => state.commServicesAccessToken); + + React.useEffect(() => { + (async () => { + const contentSigningKey = await getContentSigningKey(); + setDeviceID(contentSigningKey); + })(); + }, []); + + return React.useMemo(() => { + if (!deviceID || !accessToken || !userID) { + return null; + } + return ({ + type: 'ConnectionInitializationMessage', + deviceID, + accessToken, + userID, + deviceType: 'mobile', + }: ConnectionInitializationMessage); + }, [accessToken, deviceID, userID]); +} + +export { useTunnelbrokerInitMessage };