Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ringnotify/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ web-build/
expo-env.d.ts

# Native
.kotlin/
*.orig.*
*.jks
*.p8
Expand Down
2 changes: 1 addition & 1 deletion ringnotify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This is an [Expo](https://expo.dev) project created with [`create-expo-app`](htt
2. Start the app

```bash
npx expo start
npx expo start
```

In the output, you'll find options to open the app in a
Expand Down
6 changes: 4 additions & 2 deletions ringnotify/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"version": "0.0.1",
"orientation": "portrait",
"icon": "./assets/images/icon.png",
"scheme": "myapp",
"scheme": "ringnotify",
"userInterfaceStyle": "automatic",
"newArchEnabled": false,
"ios": {
"supportsTablet": true
},
Expand All @@ -15,6 +16,7 @@
"foregroundImage": "./assets/images/adaptive-icon.png",
"backgroundColor": "#ebeae5"
},
"edgeToEdgeEnabled": true,
"package": "me.wtarit.ringnotify",
"googleServicesFile": "./google-services.json"
},
Expand All @@ -28,7 +30,7 @@
[
"expo-splash-screen",
{
"image": "./assets/images/icon.png",
"image": "./assets/images/splash-icon.png",
"imageWidth": 200,
"resizeMode": "contain",
"backgroundColor": "#ffffff"
Expand Down
16 changes: 12 additions & 4 deletions ringnotify/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@ import {
StatusBar,
Linking,
} from "react-native";
import messaging from "@react-native-firebase/messaging";
import {
getMessaging,
getToken,
onMessage,
} from "@react-native-firebase/messaging";
import CallScreen from "@/lib/callscreen";
import { createUser, testCall, getStoredApiKey } from "@/lib/api";
import * as Clipboard from "expo-clipboard";

export default function Index() {
const [apiKey, setApiKey] = useState<string>("");
const [isLoading, setIsLoading] = useState(false);
const messaging = getMessaging();

useEffect(() => {
CallScreen.setupCallKeep();
}, []);

useEffect(() => {
const unsubscribe = messaging().onMessage((remoteMessage) => {
const unsubscribe = onMessage(messaging, (remoteMessage) => {
if (remoteMessage.data && typeof remoteMessage.data.text === "string") {
console.log("foreground call");
CallScreen.displayIncomingCall(remoteMessage.data.text);
Expand All @@ -45,7 +50,7 @@ export default function Index() {
}

try {
const token = await messaging().getToken();
const token = await getToken(messaging);
console.log("FCM Token:", token);
const newApiKey = await createUser(token);
setApiKey(newApiKey);
Expand All @@ -61,7 +66,7 @@ export default function Index() {
const handleRegenerateApiKey = async () => {
try {
setIsLoading(true);
const token = await messaging().getToken();
const token = await getToken(messaging);
const newApiKey = await createUser(token);
setApiKey(newApiKey);
Alert.alert("Success", "API Key regenerated successfully");
Expand Down Expand Up @@ -146,13 +151,15 @@ const styles = StyleSheet.create({
fontWeight: "bold",
marginBottom: 20,
textAlign: "center",
color: "#000",
},
apiKeyContainer: {
marginBottom: 20,
},
label: {
fontSize: 16,
marginBottom: 8,
color: "#000",
},
inputContainer: {
flexDirection: "row",
Expand All @@ -165,6 +172,7 @@ const styles = StyleSheet.create({
borderRadius: 4,
padding: 10,
marginRight: 10,
color: "#000",
},
copyButton: {
backgroundColor: "#007AFF",
Expand Down
10 changes: 10 additions & 0 deletions ringnotify/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// https://docs.expo.dev/guides/using-eslint/
const { defineConfig } = require('eslint/config');
const expoConfig = require('eslint-config-expo/flat');

module.exports = defineConfig([
expoConfig,
{
ignores: ['dist/*'],
},
]);
29 changes: 18 additions & 11 deletions ringnotify/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import 'expo-router/entry'
import "expo-router/entry";

import messaging from '@react-native-firebase/messaging'
import { router } from 'expo-router'
import { callHandler } from './lib/fcm';
import { AppRegistry } from 'react-native';
import {
getMessaging,
setBackgroundMessageHandler,
} from "@react-native-firebase/messaging";
import { callHandler } from "./lib/fcm";
import { AppRegistry } from "react-native";

console.log("registering");
messaging().setBackgroundMessageHandler(callHandler);
const messaging = getMessaging();
setBackgroundMessageHandler(messaging, callHandler);

AppRegistry.registerHeadlessTask('RNCallKeepBackgroundMessage', () => ({ name, callUUID, handle }) => {
// Make your call here

return Promise.resolve();
});
AppRegistry.registerHeadlessTask(
"RNCallKeepBackgroundMessage",
() =>
({ name, callUUID, handle }) => {
// Make your call here

return Promise.resolve();
}
);
106 changes: 22 additions & 84 deletions ringnotify/lib/callscreen.ts
Original file line number Diff line number Diff line change
@@ -1,111 +1,49 @@
import { Platform } from "react-native";
import RNCallKeep from "react-native-callkeep";
import {randomUUID} from 'expo-crypto';

class IncomingCall {
currentCallId: string;
constructor() {
this.currentCallId = "";
}

configure = (incomingcallAnswer, endIncomingCall) => {
try {
this.setupCallKeep();
Platform.OS === "android" && RNCallKeep.setAvailable(true);
RNCallKeep.addEventListener("answerCall", incomingcallAnswer);
RNCallKeep.addEventListener("endCall", endIncomingCall);
} catch (error) {
console.error("initializeCallKeep error:", error?.message);
}
};

//These emthod will setup the call keep.
setupCallKeep = async () => {
try {
const result = await RNCallKeep.setup({
ios: {
appName: 'Ring Notify',
ios: {
appName: "Ring Notify",
},
android: {
alertTitle: "Permissions required",
alertDescription:
"This application needs to access your phone accounts",
cancelButton: "Cancel",
okButton: "ok",
imageName: "phone_account_icon",
// additionalPermissions: [PermissionsAndroid.PERMISSIONS.example],
additionalPermissions: [],
// Required to get audio in background when using Android 11
foregroundService: {
channelId: "me.wtarit.ringnotify",
channelName: "Foreground service for my app",
notificationTitle: "My app is running on background",
notificationIcon: "../assets/images/favicon.png",
},
android: {
alertTitle: 'Permissions required',
alertDescription:
'This application needs to access your phone accounts',
cancelButton: 'Cancel',
okButton: 'ok',
imageName: 'phone_account_icon',
// additionalPermissions: [PermissionsAndroid.PERMISSIONS.example],
additionalPermissions: [],
// Required to get audio in background when using Android 11
foregroundService: {
channelId: 'me.wtarit.ringnotify',
channelName: 'Foreground service for my app',
notificationTitle: 'My app is running on background',
notificationIcon: '../assets/images/favicon.png',
},
},
});
},
});
console.log(result);
} catch (error) {
console.error("initializeCallKeep error:", error?.message);
console.error("initializeCallKeep error:", (error as Error)?.message);
}
};

// Use startCall to ask the system to start a call - Initiate an outgoing call from this point
startCall = ({ handle, localizedCallerName }) => {
// Your normal start call action
RNCallKeep.startCall(this.getCurrentCallId(), handle, localizedCallerName);
};

reportEndCallWithUUID = (callUUID, reason) => {
RNCallKeep.reportEndCallWithUUID(callUUID, reason);
};

//These method will end the incoming call
endIncomingcallAnswer = () => {
RNCallKeep.endCall(this.currentCallId);
this.currentCallId = "";
this.removeEvents();
};

//These method will remove all the event listeners
removeEvents = () => {
RNCallKeep.removeEventListener("answerCall");
RNCallKeep.removeEventListener("endCall");
};

//These method will display the incoming call
displayIncomingCall = (callerName: string) => {
Platform.OS === "android" && RNCallKeep.setAvailable(false);
RNCallKeep.displayIncomingCall(
this.getCurrentCallId(),
"",
"ringnotify",
callerName,
"generic",
true,
undefined
);
};

//Bring the app to foreground
backToForeground = () => {
RNCallKeep.backToForeground();
};

//Return the ID of current Call
getCurrentCallId = () => {
if (!this.currentCallId) {
this.currentCallId = randomUUID();
}
return this.currentCallId;
};

//These Method will end the call
endAllCall = () => {
RNCallKeep.endAllCalls();
this.currentCallId = "";
this.removeEvents();
};

}

const CallScreen = new IncomingCall();
Expand Down
Loading