-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: react-native-functional injected webview
- Loading branch information
1 parent
0ad978f
commit eb6fa24
Showing
9 changed files
with
18,615 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,3 +76,7 @@ android/keystores/debug.keystore | |
|
||
# generated by bob | ||
lib/ | ||
|
||
# custom | ||
android | ||
ios |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"build": { | ||
"development-simulator": { | ||
"developmentClient": true, | ||
"distribution": "internal", | ||
"ios": { | ||
"simulator": true | ||
} | ||
}, | ||
"development": { | ||
"developmentClient": true, | ||
"distribution": "internal" | ||
}, | ||
"preview": { | ||
"distribution": "internal" | ||
}, | ||
"production": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,25 @@ | ||
import * as React from 'react'; | ||
import React from 'react'; | ||
|
||
import { StyleSheet, View, Text } from 'react-native'; | ||
import { multiply } from 'react-native-functional'; | ||
import { StyleSheet, View } from 'react-native'; | ||
import Functional from 'react-native-functional'; | ||
|
||
export default function App() { | ||
const [result, setResult] = React.useState<number | undefined>(); | ||
|
||
React.useEffect(() => { | ||
multiply(3, 7).then(setResult); | ||
}, []); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<Text>Result: {result}</Text> | ||
<Functional | ||
roomId={'id'} | ||
accessToken={'token'} | ||
onEvent={(event) => { | ||
console.log('event: ', event); | ||
}} | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
box: { | ||
width: 60, | ||
height: 60, | ||
marginVertical: 20, | ||
width: '100%', | ||
height: '100%', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,48 @@ | ||
export function multiply(a: number, b: number): Promise<number> { | ||
return Promise.resolve(a * b); | ||
import { StyleSheet, View } from 'react-native'; | ||
import { WebView } from 'react-native-webview'; | ||
import { registerGlobals } from '@livekit/react-native'; | ||
import { RoomPage } from './livekit'; | ||
import React, { useRef } from 'react'; | ||
|
||
registerGlobals(); | ||
|
||
interface FunctionalProps { | ||
roomId: string; | ||
accessToken: string; | ||
onEvent?: (event: any) => void; | ||
} | ||
|
||
export default function Functional(props: FunctionalProps) { | ||
const { roomId, accessToken, onEvent } = props; | ||
const webViewRef = useRef(null); | ||
|
||
const onMessage = (event: { nativeEvent: { data: string } }) => { | ||
//receive message from the web page. working here until here | ||
const data = JSON.parse(event.nativeEvent.data); | ||
|
||
if (onEvent) onEvent(data); | ||
}; | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<WebView | ||
ref={webViewRef} | ||
style={styles.container} | ||
originWhitelist={['*']} | ||
source={{ | ||
uri: `https://draw.seoltab.com/whiteboard?room_id=${roomId}&access_token=${accessToken}`, | ||
}} | ||
allowsInlineMediaPlayback={true} | ||
onMessage={onMessage} | ||
/> | ||
<RoomPage url="url" token="token" /> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
width: '100%', | ||
height: '100%', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Room } from 'livekit-client'; | ||
import { AudioSession } from '@livekit/react-native'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { View } from 'react-native'; | ||
|
||
export const RoomPage = ({ url, token }: { url: string; token: string }) => { | ||
// Setup Room state | ||
const [room] = useState(() => new Room()); | ||
|
||
// Connect to Room | ||
useEffect(() => { | ||
const connect = async () => { | ||
await AudioSession.startAudioSession(); | ||
await room.connect(url, token, {}); | ||
}; | ||
connect(); | ||
|
||
return () => { | ||
room.disconnect(); | ||
AudioSession.stopAudioSession(); | ||
}; | ||
}, [url, token, room]); | ||
|
||
return <View />; | ||
}; |
Oops, something went wrong.