|
|
|
@ -1,17 +1,18 @@
@@ -1,17 +1,18 @@
|
|
|
|
|
import RNCallKeep from 'react-native-callkeep' |
|
|
|
|
import { CallKeepRootService } from './callkeep-root.service' |
|
|
|
|
import { Alert, Linking, PermissionsAndroid } from 'react-native' |
|
|
|
|
import { appEvents } from '@/shared' |
|
|
|
|
|
|
|
|
|
export class CallkeepAndroidService extends CallKeepRootService { |
|
|
|
|
protected async onAnswer(data: any) { |
|
|
|
|
this.callAccepted = true |
|
|
|
|
RNCallKeep.backToForeground() |
|
|
|
|
RNCallKeep.setConnectionState(data.callUUID, 128) |
|
|
|
|
await delay(100) |
|
|
|
|
RNCallKeep.endAllCalls() |
|
|
|
|
// protected async onAnswer(data: any) {
|
|
|
|
|
// // this.callAccepted = true
|
|
|
|
|
// // RNCallKeep.backToForeground()
|
|
|
|
|
// // RNCallKeep.setConnectionState(data.callUUID, 128)
|
|
|
|
|
// // await delay(100)
|
|
|
|
|
// // RNCallKeep.endAllCalls()
|
|
|
|
|
|
|
|
|
|
super.onAnswer(data) |
|
|
|
|
} |
|
|
|
|
// super.onAnswer(data)
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
protected async init() { |
|
|
|
|
await this.requestPermissions() |
|
|
|
@ -30,16 +31,17 @@ export class CallkeepAndroidService extends CallKeepRootService {
@@ -30,16 +31,17 @@ export class CallkeepAndroidService extends CallKeepRootService {
|
|
|
|
|
cancelButton: 'Cancel', |
|
|
|
|
okButton: 'ok', |
|
|
|
|
imageName: 'phone_account_icon', |
|
|
|
|
isHide: false, |
|
|
|
|
|
|
|
|
|
additionalPermissions: [], |
|
|
|
|
foregroundService: { |
|
|
|
|
channelId: 'com.company.my', |
|
|
|
|
channelId: 'com.taskme.app', |
|
|
|
|
channelName: 'Foreground service for my app', |
|
|
|
|
notificationTitle: 'My app is running on background', |
|
|
|
|
notificationIcon: |
|
|
|
|
'Path to the resource icon of the notification', |
|
|
|
|
}, |
|
|
|
|
} as any, |
|
|
|
|
selfManaged: true, |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
RNCallKeep.endAllCalls() |
|
|
|
@ -48,13 +50,18 @@ export class CallkeepAndroidService extends CallKeepRootService {
@@ -48,13 +50,18 @@ export class CallkeepAndroidService extends CallKeepRootService {
|
|
|
|
|
private async requestPermissions() { |
|
|
|
|
try { |
|
|
|
|
const granted = await PermissionsAndroid.requestMultiple([ |
|
|
|
|
PermissionsAndroid.PERMISSIONS.CALL_PHONE, |
|
|
|
|
PermissionsAndroid.PERMISSIONS.ANSWER_PHONE_CALLS, |
|
|
|
|
PermissionsAndroid.PERMISSIONS.CAMERA, |
|
|
|
|
PermissionsAndroid.PERMISSIONS.RECORD_AUDIO, |
|
|
|
|
PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE, |
|
|
|
|
PermissionsAndroid.PERMISSIONS.READ_CALL_LOG, |
|
|
|
|
PermissionsAndroid.PERMISSIONS.READ_CONTACTS, |
|
|
|
|
// PermissionsAndroid.PERMISSIONS.BLUETOOTH,
|
|
|
|
|
// PermissionsAndroid.PERMISSIONS.BLUETOOTH_ADMIN,
|
|
|
|
|
PermissionsAndroid.PERMISSIONS.ANSWER_PHONE_CALLS, |
|
|
|
|
PermissionsAndroid.PERMISSIONS.CALL_PHONE, |
|
|
|
|
// PermissionsAndroid.PERMISSIONS.READ_CALL_LOG,
|
|
|
|
|
// PermissionsAndroid.PERMISSIONS.WRITE_CALL_LOG,
|
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
console.log(granted) |
|
|
|
|
const allPermissionsGranted = Object.values(granted).every( |
|
|
|
|
permission => permission === PermissionsAndroid.RESULTS.GRANTED, |
|
|
|
|
) |
|
|
|
@ -78,9 +85,27 @@ export class CallkeepAndroidService extends CallKeepRootService {
@@ -78,9 +85,27 @@ export class CallkeepAndroidService extends CallKeepRootService {
|
|
|
|
|
|
|
|
|
|
return allPermissionsGranted |
|
|
|
|
} catch (err) { |
|
|
|
|
console.warn(err) |
|
|
|
|
console.log(err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected async initListeners() { |
|
|
|
|
super.initListeners() |
|
|
|
|
|
|
|
|
|
RNCallKeep.addEventListener( |
|
|
|
|
'showIncomingCallUi', |
|
|
|
|
this.onShowIncomingCallUI.bind(this), |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected async removeListeners() { |
|
|
|
|
super.removeListeners() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private async onShowIncomingCallUI(data) { |
|
|
|
|
// Alert.alert('Iconming caal from' + data.name)
|
|
|
|
|
appEvents.emit('android/showIncomingCallUi', data) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function delay(ms: number) { |
|
|
|
|