Skip to content

Commit

Permalink
Merge pull request #84 from taneeshaa15/master
Browse files Browse the repository at this point in the history
Real-time Chat Application with Video Calling
  • Loading branch information
smilewithkhushi authored Jul 21, 2024
2 parents 9c30ebb + 4e232a8 commit e17b28f
Show file tree
Hide file tree
Showing 11 changed files with 632 additions and 48 deletions.
44 changes: 44 additions & 0 deletions MyChatApp/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// App.js
import React, { useEffect } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import firebase from '@react-native-firebase/app';
import auth from '@react-native-firebase/auth';

// Initialize Firebase
const firebaseConfig = {
// Your Firebase config here
};

if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}

const Stack = createStackNavigator();

const App = () => {
useEffect(() => {
// Check if the user is already signed in
const unsubscribe = auth().onAuthStateChanged(user => {
if (user) {
// User is signed in
console.log('User is signed in: ', user.uid);
} else {
// No user is signed in
console.log('No user signed in');
}
});

return () => unsubscribe();
}, []);

return (
<NavigationContainer>
<Stack.Navigator>
{/* Define your app screens here */}
</Stack.Navigator>
</NavigationContainer>
);
};

export default App;
22 changes: 22 additions & 0 deletions MyChatApp/AppNavigator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';

// Screens
import ChatScreen from './screens/ChatScreen';
import VideoCallScreen from './screens/VideoCallScreen';

const Stack = createStackNavigator();

const AppNavigator = () => {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Chat">
<Stack.Screen name="Chat" component={ChatScreen} />
<Stack.Screen name="VideoCall" component={VideoCallScreen} />
</Stack.Navigator>
</NavigationContainer>
);
};

export default AppNavigator;
53 changes: 53 additions & 0 deletions MyChatApp/ChatScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React, { useState, useEffect } from 'react';
import { View, Text, TextInput, Button, FlatList } from 'react-native';
import { db } from './firebase'; // Assuming you've set up Firebase

const ChatScreen = () => {
const [messages, setMessages] = useState([]);
const [input, setInput] = useState('');

useEffect(() => {
const unsubscribe = db.collection('messages')
.orderBy('timestamp', 'desc')
.onSnapshot(snapshot => {
setMessages(snapshot.docs.map(doc => ({
id: doc.id,
data: doc.data()
})));
});

return () => {
unsubscribe();
};
}, []);

const sendMessage = () => {
db.collection('messages').add({
message: input,
timestamp: new Date().toISOString(),
});
setInput('');
};

return (
<View>
<FlatList
data={messages}
renderItem={({ item }) => (
<View>
<Text>{item.data.message}</Text>
</View>
)}
keyExtractor={(item) => item.id}
/>
<TextInput
placeholder="Enter message"
value={input}
onChangeText={(text) => setInput(text)}
/>
<Button title="Send" onPress={sendMessage} />
</View>
);
};

export default ChatScreen;
28 changes: 28 additions & 0 deletions MyChatApp/LoginScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// LoginScreen.js
import React, { useState } from 'react';
import { View, Text, TextInput, Button, StyleSheet } from 'react-native';
import auth from '@react-native-firebase/auth';

const LoginScreen = () => {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');

const handleLogin = async () => {
try {
const userCredential = await auth().signInWithEmailAndPassword(email, password);
console.log('User logged in successfully:', userCredential.user.uid);
// Navigate to chat screen or home screen after successful login
} catch (error) {
console.error('Error logging in:', error);
}
};

return (
<View style={styles.container}>
<Text>Login</Text>
<TextInput
style={styles.input}
placeholder="Email"
onChangeText={text => setEmail(text)}
value={email}

19 changes: 19 additions & 0 deletions MyChatApp/VideoCallScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { View, Text, Button } from 'react-native';

const VideoCallScreen = () => {
const startVideoCall = () => {
// Add your Twilio Video or WebRTC integration code here
// Example: Start a video call using Twilio Video or WebRTC SDK
console.log('Video call started');
};

return (
<View>
<Text>Video Call Screen</Text>
<Button title="Start Video Call" onPress={startVideoCall} />
</View>
);
};

export default VideoCallScreen;
50 changes: 50 additions & 0 deletions MyChatApp/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apply plugin: "com.android.application"
apply plugin: "com.facebook.react"
apply plugin: "kotlin-android"
apply plugin: "com.google.gms.google-services" // Apply Google services plugin

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
applicationId "com.mychatapp" // Replace with your app's package name
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}

buildTypes {
release {
// Customize as needed
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])

implementation "com.facebook.react:react-native:+" // Replace with your React Native version

// Add Firebase dependencies
implementation platform('com.google.firebase:firebase-bom:31.0.2')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-firestore'
// Add other Firebase dependencies as needed
}

// Ensure this line is at the bottom of the file
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
30 changes: 30 additions & 0 deletions MyChatApp/android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"project_info": {
"project_number": "PROJECT_NUMBER",
"project_id": "mychatapp-9134a",
"storage_bucket": "mychatapp-9134a.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "MOBILE_SDK_APP_ID",
"android_client_info": {
"package_name": "com.mychatapp"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "API_KEY"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}

29 changes: 29 additions & 0 deletions MyChatApp/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
buildscript {
ext {
buildToolsVersion = "34.0.0"
minSdkVersion = 23
compileSdkVersion = 34
targetSdkVersion = 34
ndkVersion = "26.1.10909125"
kotlinVersion = "1.9.22"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:4.3.10") // Update to the latest version
classpath("com.facebook.react:react-native-gradle-plugin") // Ensure this matches your React Native version
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10") // Update to the latest version

// Add the Google services classpath
classpath 'com.google.gms:google-services:4.3.10'
}
}

allprojects {
repositories {
google()
mavenCentral()
}
}
19 changes: 19 additions & 0 deletions MyChatApp/firebase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { initializeApp } from '@firebase/app';
import { getFirestore } from '@firebase/firestore';
import { getAuth } from '@firebase/auth';

const firebaseConfig = {
apiKey: "AIzaSyCTdHgVlgzpQ28Kr8DvjW0OppZ5EwasCSY",
authDomain: "mychatapp-9134a.firebaseapp.com",
projectId: "mychatapp-9134a",
storageBucket: "mychatapp-9134a.appspot.com",
messagingSenderId: "633011419193",
appId: "1:633011419193:android:68e21f3e5c56377fa8f5e8"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
const auth = getAuth(app);

export { db, auth };
Loading

0 comments on commit e17b28f

Please sign in to comment.