Skip to content

Commit 6338a00

Browse files
committed
v5.0.0
1 parent 6a27cdf commit 6338a00

File tree

195 files changed

+10654
-14298
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+10654
-14298
lines changed

examples/SampleApp/App.tsx

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
AppState,
88
AppStateStatus,
99
} from 'react-native';
10-
1110
import {
1211
CometChatIncomingCall,
1312
CometChatThemeProvider,
@@ -23,64 +22,87 @@ import RootStackNavigator from './src/navigation/RootStackNavigator';
2322
import {AppConstants} from './src/utils/AppConstants';
2423
import {
2524
requestAndroidPermissions,
25+
navigateToConversation,
2626
} from './src/utils/helper';
27+
import {navigationRef} from './src/navigation/NavigationService';
2728
import AsyncStorage from '@react-native-async-storage/async-storage';
2829
import {useActiveChat} from './src/utils/ActiveChatContext';
2930

31+
// Listener ID for registering and removing CometChat listeners.
3032
const listenerId = 'app';
3133

3234
const App = (): React.ReactElement => {
33-
const {activeChat} = useActiveChat();
3435
const [callReceived, setCallReceived] = useState(false);
3536
const incomingCall = useRef<CometChat.Call | CometChat.CustomMessage | null>(
3637
null,
3738
);
3839
const [isInitializing, setIsInitializing] = useState(true);
3940
const [isLoggedIn, setIsLoggedIn] = useState(false);
4041
const [userLoggedIn, setUserLoggedIn] = useState(false);
42+
const [hasValidAppCredentials, setHasValidAppCredentials] = useState(false);
4143

4244
/**
43-
* 1. Initial CometChat + UIKit Initialization
45+
* Initialize CometChat UIKit and configure Google Sign-In.
46+
* Retrieves credentials from AsyncStorage and uses fallback constants if needed.
4447
*/
4548
useEffect(() => {
4649
async function init() {
4750
try {
51+
// Retrieve stored app credentials or default to an empty object.
4852
const AppData = (await AsyncStorage.getItem('appCredentials')) || '{}';
53+
const storedCredentials = JSON.parse(AppData);
54+
55+
// Determine the final credentials (from AsyncStorage or AppConstants).
56+
const finalAppId = storedCredentials.appId || AppConstants.appId;
57+
const finalAuthKey = storedCredentials.authKey || AppConstants.authKey;
58+
const finalRegion = storedCredentials.region || AppConstants.region;
59+
60+
// Set hasValidAppCredentials based on whether all values are available.
61+
if (finalAppId && finalAuthKey && finalRegion) {
62+
setHasValidAppCredentials(true);
63+
} else {
64+
setHasValidAppCredentials(false);
65+
}
66+
4967
await CometChatUIKit.init({
50-
appId: JSON.parse(AppData).appId || AppConstants.appId,
51-
authKey: JSON.parse(AppData).authKey || AppConstants.authKey,
52-
region: JSON.parse(AppData).region || AppConstants.region,
68+
appId: finalAppId,
69+
authKey: finalAuthKey,
70+
region: finalRegion,
5371
subscriptionType: CometChat.AppSettings
5472
.SUBSCRIPTION_TYPE_ALL_USERS as UIKitSettings['subscriptionType'],
5573
});
5674

75+
// If a user is already logged in, update the state.
5776
const loggedInUser = CometChatUIKit.loggedInUser;
5877
if (loggedInUser) {
5978
setIsLoggedIn(true);
6079
}
80+
6181
} catch (error) {
62-
console.log('CometChat init or getLoggedinUser failed:', error);
82+
console.log('Error during initialization', error);
6383
} finally {
84+
// Mark initialization as complete.
6485
setIsInitializing(false);
6586
}
6687
}
6788
init();
6889
}, []);
6990

7091
/**
71-
* 2. Re-check user & possibly re-init or re-login if app resumes
92+
* Monitor app state changes to verify the logged-in status and clear notifications.
93+
* When the app becomes active, it cancels Android notifications and checks the login status.
7294
*/
7395
useEffect(() => {
96+
if (Platform.OS === 'android') {
97+
// Request required Android permissions for notifications.
98+
requestAndroidPermissions();
99+
}
74100
const handleAppStateChange = async (nextState: AppStateStatus) => {
75101
if (nextState === 'active') {
76102
try {
77-
// Check if CometChat still has a valid logged in user
103+
// Verify if there is a valid logged-in user.
78104
const chatUser = await CometChat.getLoggedinUser();
79-
if (!chatUser) {
80-
setIsLoggedIn(false);
81-
} else {
82-
setIsLoggedIn(true);
83-
}
105+
setIsLoggedIn(!!chatUser);
84106
} catch (error) {
85107
console.log('Error verifying CometChat user on resume:', error);
86108
}
@@ -94,19 +116,10 @@ const App = (): React.ReactElement => {
94116
}, []);
95117

96118
/**
97-
* 3. Handle inbound FCM messages in the foreground (Android).
119+
* Attach CometChat login listener to handle login and logout events.
120+
* Updates user login status accordingly.
98121
*/
99122
useEffect(() => {
100-
if (Platform.OS === 'android') {
101-
requestAndroidPermissions();
102-
}
103-
}, [activeChat]);
104-
105-
/**
106-
* 4. Attach CometChatLogin Listener and Call Listener
107-
*/
108-
useEffect(() => {
109-
// Login Listener
110123
CometChat.addLoginListener(
111124
listenerId,
112125
new CometChat.LoginListener({
@@ -125,55 +138,62 @@ const App = (): React.ReactElement => {
125138
}),
126139
);
127140

141+
// Clean up the login listener on component unmount.
128142
return () => {
129-
// Clean up CometChat listeners
130143
CometChat.removeLoginListener(listenerId);
131144
};
132145
}, []);
133146

147+
/**
148+
* Attach CometChat call listeners to handle incoming, outgoing, and cancelled call events.
149+
* Also handles UI events for call end.
150+
*/
134151
useEffect(() => {
135-
// Call Listener
152+
// Listener for call events.
136153
CometChat.addCallListener(
137154
listenerId,
138155
new CometChat.CallListener({
139156
onIncomingCallReceived: (call: CometChat.Call) => {
140-
// Close bottomsheet for incoming call overlay
157+
// Hide any bottom sheet UI before showing the incoming call screen.
141158
CometChatUIEventHandler.emitUIEvent(
142159
CometChatUIEvents.ccToggleBottomSheet,
143160
{
144161
isBottomSheetVisible: false,
145162
},
146163
);
164+
// Store the incoming call and update state.
147165
incomingCall.current = call;
148166
setCallReceived(true);
149167
},
150168
onOutgoingCallRejected: () => {
169+
// Clear the call state if outgoing call is rejected.
151170
incomingCall.current = null;
152171
setCallReceived(false);
153172
},
154173
onIncomingCallCancelled: () => {
174+
// Clear the call state if the incoming call is cancelled.
155175
incomingCall.current = null;
156176
setCallReceived(false);
157177
},
158178
}),
159179
);
160180

181+
// Additional listener to handle call end events.
161182
CometChatUIEventHandler.addCallListener(listenerId, {
162183
ccCallEnded: () => {
163184
incomingCall.current = null;
164185
setCallReceived(false);
165186
},
166187
});
167188

189+
// Remove call listeners on cleanup.
168190
return () => {
169-
// Clean up CometChat listeners
170191
CometChatUIEventHandler.removeCallListener(listenerId);
171192
CometChat.removeCallListener(listenerId);
172193
};
173194
}, [userLoggedIn]);
174195

175-
176-
// Show basic splash or blank screen while initializing
196+
// Show a blank/splash screen while the app is initializing.
177197
if (isInitializing) {
178198
return (
179199
<View
@@ -188,21 +208,26 @@ const App = (): React.ReactElement => {
188208
);
189209
}
190210

211+
// Once initialization is complete, render the main app UI.
191212
return (
192213
<SafeAreaProvider>
193214
<CometChatThemeProvider>
194-
{/* Only show incoming call UI if logged in + we have a call object */}
215+
{/* Render the incoming call UI if the user is logged in and a call is received */}
195216
{isLoggedIn && callReceived && incomingCall.current ? (
196217
<CometChatIncomingCall
197218
call={incomingCall.current}
198219
onDecline={() => {
220+
// Handle call decline by clearing the incoming call state.
199221
incomingCall.current = null;
200222
setCallReceived(false);
201223
}}
202224
/>
203225
) : null}
204-
{/* Pass isLoggedIn to your main stack */}
205-
<RootStackNavigator isLoggedIn={isLoggedIn} />
226+
{/* Render the main navigation stack, passing the login status as a prop */}
227+
<RootStackNavigator
228+
isLoggedIn={isLoggedIn}
229+
hasValidAppCredentials={hasValidAppCredentials}
230+
/>
206231
</CometChatThemeProvider>
207232
</SafeAreaProvider>
208233
);

examples/SampleApp/AppErrorBoundary.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ class AppErrorBoundary extends React.Component<Props, State> {
4747
<View style={styles.container}>
4848
<View style={styles.card}>
4949
<Text style={styles.title}>Something went wrong</Text>
50-
<Text style={styles.errorText}>
50+
{/* Uncomment the next line to show the error message */}
51+
{/* <Text style={styles.errorText}>
5152
{this.state.error ? this.state.error.toString() : 'Unknown error'}
52-
</Text>
53+
</Text> */}
5354
<View style={styles.buttonContainer}>
5455
<Button title="Retry" onPress={this.handleRetry} color={this.state.colorScheme === 'dark' ? "#bbbbbb" : "#333333"} />
5556
</View>

examples/SampleApp/android/app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,6 @@ dependencies {
120120
} else {
121121
implementation jscFlavor
122122
}
123+
124+
implementation 'com.facebook.fresco:animated-gif:3.6.0' //gif android
123125
}

examples/SampleApp/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<uses-permission android:name="android.permission.CAMERA" />
1010
<uses-permission android:name="android.permission.RECORD_AUDIO" />
1111
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
12-
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
1312
<uses-permission android:name="android.permission.BIND_TELECOM_CONNECTION_SERVICE"/>
1413
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
1514
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
@@ -24,6 +23,7 @@
2423
android:allowBackup="false"
2524
android:theme="@style/AppTheme"
2625
android:supportsRtl="true">
26+
2727

2828
<activity
2929
android:name=".MainActivity"
@@ -37,18 +37,6 @@
3737
<category android:name="android.intent.category.LAUNCHER" />
3838
</intent-filter>
3939
</activity>
40-
<service android:name="io.wazo.callkeep.RNCallKeepBackgroundMessagingService" />
41-
<service android:name="io.wazo.callkeep.VoiceConnectionService"
42-
android:label="Wazo"
43-
android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"
44-
android:foregroundServiceType="camera|microphone"
45-
android:exported="true"
46-
>
47-
48-
<intent-filter>
49-
<action android:name="android.telecom.ConnectionService" />
50-
</intent-filter>
51-
</service>
5240

5341
</application>
5442
</manifest>

examples/SampleApp/android/app/src/main/java/com/masterapp/MainApplication.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class MainApplication : Application(), ReactApplication {
1818
object : DefaultReactNativeHost(this) {
1919
override fun getPackages(): List<ReactPackage> =
2020
PackageList(this).packages.apply {
21+
2122
}
2223

2324
override fun getJSMainModuleName(): String = "index"

examples/SampleApp/android/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ buildscript {
66
targetSdkVersion = 34
77
ndkVersion = "27.1.12297006"
88
kotlinVersion = "2.0.21"
9-
version = "V5.0.0-beta.1"
9+
googlePlayServicesAuthVersion = "20.7.0"
10+
version = "V5.0.0"
1011
}
1112
repositories {
1213
google()

examples/SampleApp/android/settings.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@ extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autoli
44
rootProject.name = 'SampleApp'
55
include ':app'
66
includeBuild('../../../node_modules/@react-native/gradle-plugin')
7-
include ':react-native-callkeep'
8-
project(':react-native-callkeep').projectDir = new File(rootProject.projectDir, '../../../node_modules/react-native-callkeep/android')

examples/SampleApp/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {AppRegistry} from 'react-native';
22
import App from './App';
33
import {name as appName} from './app.json';
44
import AppErrorBoundary from './AppErrorBoundary';
5-
import { ActiveChatProvider } from './src/utils/ActiveChatContext';
5+
import {ActiveChatProvider} from './src/utils/ActiveChatContext';
66

77
if (global?.ErrorUtils) {
88
const defaultHandler = global.ErrorUtils.getGlobalHandler();

0 commit comments

Comments
 (0)