Skip to content

Commit

Permalink
feat: react-native-functional injected webview
Browse files Browse the repository at this point in the history
  • Loading branch information
momenthana committed Feb 7, 2024
1 parent 0ad978f commit eb6fa24
Show file tree
Hide file tree
Showing 9 changed files with 18,615 additions and 33 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ android/keystores/debug.keystore

# generated by bob
lib/

# custom
android
ios
35 changes: 30 additions & 5 deletions example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,45 @@
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"assetBundlePatterns": [
"**/*"
],
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true
"bundleIdentifier": "com.seoltab.functional",
"supportsTablet": true,
"bitcode": false
},
"android": {
"package": "com.seoltab.functional",
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#ffffff"
}
},
"permissions": [
"android.permission.ACCESS_NETWORK_STATE",
"android.permission.BLUETOOTH",
"android.permission.CAMERA",
"android.permission.INTERNET",
"android.permission.MODIFY_AUDIO_SETTINGS",
"android.permission.RECORD_AUDIO",
"android.permission.SYSTEM_ALERT_WINDOW",
"android.permission.WAKE_LOCK"
]
},
"web": {
"favicon": "./assets/favicon.png"
},
"plugins": [
[
"@config-plugins/react-native-webrtc",
{
"cameraPermission": "Allow $(PRODUCT_NAME) to access your camera",
"microphonePermission": "Allow $(PRODUCT_NAME) to access your microphone"
}
]
],
"extra": {
"eas": {
"projectId": "23fa8ef4-e803-4ff1-a3d6-1606a53410f4"
}
}
}
}
19 changes: 19 additions & 0 deletions example/eas.json
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": {}
}
}
20 changes: 13 additions & 7 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,29 @@
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"android": "expo run:android",
"ios": "expo run:ios",
"web": "expo start --web"
},
"dependencies": {
"@config-plugins/react-native-webrtc": "^8.0.0",
"@livekit/react-native": "^1.4.3",
"@livekit/react-native-webrtc": "^114.0.0",
"expo": "~50.0.6",
"expo-dev-client": "~3.3.8",
"expo-status-bar": "~1.11.1",
"react": "18.2.0",
"react-native": "0.73.4",
"react-dom": "18.2.0",
"react-native-web": "~0.19.6"
"react-native": "0.73.4",
"react-native-web": "~0.19.6",
"react-native-webrtc": "^118.0.1",
"react-native-webview": "13.6.4"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"babel-plugin-module-resolver": "^5.0.0",
"@expo/webpack-config": "^18.0.1",
"babel-loader": "^8.1.0"
"@expo/webpack-config": "~19.0.1",
"babel-loader": "^8.1.0",
"babel-plugin-module-resolver": "^5.0.0"
},
"private": true
}
30 changes: 12 additions & 18 deletions example/src/App.tsx
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%',
},
});
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
"devDependencies": {
"@commitlint/config-conventional": "^17.0.2",
"@evilmartians/lefthook": "^1.5.0",
"@livekit/react-native": "^1.4.3",
"@livekit/react-native-webrtc": "^114.0.0",
"@react-native/eslint-config": "^0.72.2",
"@release-it/conventional-changelog": "^5.0.0",
"@types/jest": "^28.1.2",
Expand All @@ -70,6 +72,7 @@
"react": "18.2.0",
"react-native": "0.73.4",
"react-native-builder-bob": "^0.23.2",
"react-native-webview": "^13.7.1",
"release-it": "^15.0.0",
"typescript": "^5.0.2"
},
Expand All @@ -78,7 +81,8 @@
},
"peerDependencies": {
"react": "*",
"react-native": "*"
"react-native": "*",
"react-native-webview": "*"
},
"workspaces": [
"example"
Expand Down
49 changes: 47 additions & 2 deletions src/index.tsx
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%',
},
});
25 changes: 25 additions & 0 deletions src/livekit.tsx
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 />;
};
Loading

0 comments on commit eb6fa24

Please sign in to comment.