Browse Source

Process

android-self-mode
Vitalik 4 months ago
parent
commit
2fb7234bd6
  1. 4
      .env.development
  2. 2
      .env.production
  3. 1
      .env.stage
  4. 20
      android/app/src/main/AndroidManifest.xml
  5. 2
      src/config/index.ts
  6. 57
      src/modules/calls/services/callkeep/callkeep-android.service.ts
  7. 3
      src/modules/calls/services/callkeep/callkeep-root.service.ts
  8. 56
      src/modules/calls/widgets/incoming-call.widget.tsx
  9. 2
      src/modules/root/index.tsx
  10. 2
      src/services/system/app-info.service.ts
  11. 5
      src/shared/events/index.ts

4
.env.development

@ -2,4 +2,6 @@ API_URL=http://localhost:3000 @@ -2,4 +2,6 @@ API_URL=http://localhost:3000
SOCKET_URL=http://localhost:3000
ONE_SIGNAL_KEY=8b9066f5-8c3f-49f7-bef4-c5ab621f9d27
SENTRY_ENVIROMENT=develop
SENTRY_ENVIROMENT=develop
SHOW_VERSION_MODAL=true

2
.env.production

@ -4,6 +4,8 @@ ONE_SIGNAL_KEY=5e1a5e18-33e5-4ed3-8423-45b1abc354c6 @@ -4,6 +4,8 @@ ONE_SIGNAL_KEY=5e1a5e18-33e5-4ed3-8423-45b1abc354c6
SENTRY_ENVIROMENT=production
SHOW_VERSION_MODAL=true
# API_URL=https://taskme-api.work-jetup.site
# SOCKET_URL=https://taskme-api.work-jetup.site
# ONE_SIGNAL_KEY=8b9066f5-8c3f-49f7-bef4-c5ab621f9d27

1
.env.stage

@ -4,3 +4,4 @@ ONE_SIGNAL_KEY=8b9066f5-8c3f-49f7-bef4-c5ab621f9d27 @@ -4,3 +4,4 @@ ONE_SIGNAL_KEY=8b9066f5-8c3f-49f7-bef4-c5ab621f9d27
SENTRY_ENVIROMENT=stage
SHOW_VERSION_MODAL=false

20
android/app/src/main/AndroidManifest.xml

@ -7,6 +7,18 @@ @@ -7,6 +7,18 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
<uses-permission android:name="android.permission.BIND_TELECOM_CONNECTION_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS"/>
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
@ -27,13 +39,7 @@ @@ -27,13 +39,7 @@
<uses-permission android:name="com.oppo.launcher.permission.READ_SETTINGS" tools:node="remove" />
<uses-permission android:name="com.oppo.launcher.permission.WRITE_SETTINGS" tools:node="remove" />
<uses-permission android:name="android.permission.BIND_TELECOM_CONNECTION_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS"/>
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<application

2
src/config/index.ts

@ -7,11 +7,13 @@ export const dynamicConfig = { @@ -7,11 +7,13 @@ export const dynamicConfig = {
baseUrl: Config.API_URL,
socketUrl: Config.SOCKET_URL,
oneSignalKey: Config.ONE_SIGNAL_KEY,
showVersionModal: Config.SHOW_VERSION_MODAL === 'true',
appStoreUrl: 'https://apps.apple.com/ua/app/task-me/id1482240685?l=uk',
googlePlayUrl:
'https://play.google.com/store/apps/details?id=com.app.task_me',
}
export const config = {
...dynamicConfig,
fonts,

57
src/modules/calls/services/callkeep/callkeep-android.service.ts

@ -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) {

3
src/modules/calls/services/callkeep/callkeep-root.service.ts

@ -9,7 +9,7 @@ import { DeviceInfoService } from '@/services/system' @@ -9,7 +9,7 @@ import { DeviceInfoService } from '@/services/system'
import { CallRoot } from '../call-root.service'
import { callsStreamsCtr, useCallDataStore, useLocalStream } from '../../hooks'
import { StopCall } from '../../core/stop-call'
import { PermissionsAndroid } from 'react-native'
import { Alert } from 'react-native'
export class CallKeepRootService extends CallRoot {
protected accountInited = false
@ -121,6 +121,7 @@ export class CallKeepRootService extends CallRoot { @@ -121,6 +121,7 @@ export class CallKeepRootService extends CallRoot {
}
protected async onEnd({ callUUID }) {
Alert.alert('ON END')
if (this.isCallWasRejected()) {
this.callAccepted = null
await rejectCallReq({

56
src/modules/calls/widgets/incoming-call.widget.tsx

@ -1,49 +1,37 @@ @@ -1,49 +1,37 @@
import { RouteKey, useSocketListener, useTheme } from '@/shared'
import { RouteKey, useEventsListener, useTheme } from '@/shared'
import React, { useState } from 'react'
import { Dimensions, Modal, StyleSheet, View } from 'react-native'
import {
callDataStoreHelper,
useCallDataStore,
useCallFromStore,
} from '../hooks'
import { PartialTheme } from '@/shared/themes/interfaces'
import { CallBackground, CallBtn } from '../components'
import { NavigationService } from '@/services/system'
import { RTCIceCandidate } from 'react-native-webrtc'
import { callService } from '../services'
import inCallManager from 'react-native-incall-manager'
import RNCallKeep from 'react-native-callkeep'
export const IncomingCallWidget = () => {
const [isVisible, setVisible] = useState(false)
const { title, avatarImageUrl } = useCallFromStore()
const { styles } = useTheme(createStyles)
const [data, setData] = useState<any>({})
// useSocketListener('call/canceled', data => {
// setVisible(false)
// })
// useSocketListener('call/ICEcandidate', data => {
// try {
// const candidates = data.candidates
// const peerConnection = callDataStoreHelper.peerConnection()
// candidates.map(it => {
// const item = new RTCIceCandidate(it)
// if (peerConnection) {
// peerConnection.addIceCandidate(item)
// } else {
// useCallDataStore.getState().addIcecanidate(item)
// }
// })
// } catch (e) {
// console.log(e)
// }
// })
useEventsListener(
'android/showIncomingCallUi',
data => {
console.log('Show displa incomi n call')
setVisible(true)
setData(data)
inCallManager.startRingtone('_BUNDLE_', [0, 1], null, 1)
},
[],
)
const decline = () => {}
const decline = () => {
RNCallKeep.rejectCall(data.callUUID)
setVisible(false)
setData({})
}
const accept = async () => {
// inCallManager.stopRingtone()
await callService.processAccept()
NavigationService.navigate(RouteKey.Call, {})
setVisible(false)
@ -63,8 +51,8 @@ export const IncomingCallWidget = () => { @@ -63,8 +51,8 @@ export const IncomingCallWidget = () => {
}}>
<View style={styles.container}>
<CallBackground
title={title}
avatarImageUrl={avatarImageUrl}
title={data.name ? data.name : 'Невідомий контакт'}
avatarImageUrl={null}
subtitle="Телефоннє">
<View style={styles.row}>
<CallBtn

2
src/modules/root/index.tsx

@ -39,6 +39,7 @@ import { StyleSheet } from 'react-native' @@ -39,6 +39,7 @@ import { StyleSheet } from 'react-native'
import { PartialTheme } from '@/shared/themes/interfaces'
import { useAppBadge, useAppSocketListener, useNetConnect } from './hooks'
import { PreviewFileModal, LoaderModal } from '@/shared/components/modals'
import { IncomingCallWidget } from '../calls/widgets'
export const Navigation: FC = () => {
const activeModule = useSelector(selectActiveNavigationModule)
@ -91,6 +92,7 @@ export const Navigation: FC = () => { @@ -91,6 +92,7 @@ export const Navigation: FC = () => {
<SelectTaxonomiesModalSmart />
<RecordAudioModalSmart />
<ChatSendImgModal />
<IncomingCallWidget />
</>
)
}

2
src/services/system/app-info.service.ts

@ -24,6 +24,8 @@ const updateApp = () => { @@ -24,6 +24,8 @@ const updateApp = () => {
const loadActualAppVersion = async () => {
try {
if (!config.showVersionModal) return
const { data } = await fetchActualAppVersionReq(Platform.OS)
if (data) {
const currentAppVersion = DeviceInfoService.getAppVersion()

5
src/shared/events/index.ts

@ -159,6 +159,11 @@ export type AppEvents = { @@ -159,6 +159,11 @@ export type AppEvents = {
}
onAccountWasLoaded: {}
callSettingUpdated: {}
'android/showIncomingCallUi': {
handle: string
callUUID: string
name: string
}
}
export type SocketEvents = {

Loading…
Cancel
Save