Skip to content

Commit

Permalink
[VoximplantDemo]: add missing foreground service for android
Browse files Browse the repository at this point in the history
  • Loading branch information
YuliaGrigorieva committed Dec 5, 2022
1 parent ffa16d6 commit db8fc72
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 56 deletions.
2 changes: 2 additions & 0 deletions VoximplantDemo/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package="com.voximplantdemo">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

<application
android:name=".MainApplication"
Expand All @@ -22,5 +23,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.voximplant.foregroundservice.VIForegroundService" android:exported="false"> </service>
</application>
</manifest>
1 change: 1 addition & 0 deletions VoximplantDemo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@react-native-firebase/messaging": "^16.4.6",
"@react-navigation/native": "^6.0.16",
"@react-navigation/native-stack": "^6.9.4",
"@voximplant/react-native-foreground-service": "^3.0.2",
"react": "18.1.0",
"react-native": "0.70.6",
"react-native-callkeep": "^4.3.3",
Expand Down
92 changes: 46 additions & 46 deletions VoximplantDemo/src/manager/ForegroundService.android.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
// /*
// * Copyright (c) 2011-2022, Zingaya, Inc. All rights reserved.
// */
//
// import VIForegroundService from '@voximplant/react-native-foreground-service';
//
// class ForegroundService {
// static instance = null;
//
// constructor() {
// this.service = VIForegroundService.getInstance();
// }
//
// static getInstance () {
// if (this.instance === null) {
// this.instance = new ForegroundService();
// }
// return this.instance;
// }
//
// async createNotificationChannel() {
// const channelConfig = {
// id: 'ForegroundServiceChannel',
// name: 'In progress calls',
// description: 'Notify the call is in progress',
// enableVibration: false,
// };
// await this.service.createNotificationChannel(channelConfig);
// }
//
// async startService() {
// const notificationConfig = {
// channelId: 'ForegroundServiceChannel',
// id: 3456,
// title: 'Voximplant',
// text: 'Call in progress',
// icon: 'ic_vox_notification',
// };
// await this.service.startService(notificationConfig);
// }
//
// async stopService() {
// await this.service.stopService();
// }
// }
// export default ForegroundService;
/*
* Copyright (c) 2011-2022, Zingaya, Inc. All rights reserved.
*/

import VIForegroundService from '@voximplant/react-native-foreground-service';

class ForegroundService {
static instance = null;

constructor() {
this.service = VIForegroundService.getInstance();
}

static getInstance() {
if (this.instance === null) {
this.instance = new ForegroundService();
}
return this.instance;
}

async createNotificationChannel() {
const channelConfig = {
id: 'ForegroundServiceChannel',
name: 'In progress calls',
description: 'Notify the call is in progress',
enableVibration: false,
};
await this.service.createNotificationChannel(channelConfig);
}

async startService() {
const notificationConfig = {
channelId: 'ForegroundServiceChannel',
id: 3456,
title: 'Voximplant',
text: 'Call in progress',
icon: 'ic_vox_notification',
};
await this.service.startService(notificationConfig);
}

async stopService() {
await this.service.stopService();
}
}
export default ForegroundService;
14 changes: 7 additions & 7 deletions VoximplantDemo/src/manager/ForegroundService.ios.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// /*
// * Copyright (c) 2011-2022, Zingaya, Inc. All rights reserved.
// */
//
// 'use strict';
//
// // do nothing for iOS. This functionality is required only on Android to work calls in background.
/*
* Copyright (c) 2011-2022, Zingaya, Inc. All rights reserved.
*/

'use strict';

// do nothing for iOS. This functionality is required only on Android to work calls in background.
6 changes: 3 additions & 3 deletions VoximplantDemo/src/screens/CallScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export default class CallScreen extends React.Component {
this.callState === CALL_STATES.CONNECTED
) {
(async () => {
ForegroundService.getInstance().stopService();
await ForegroundService.getInstance().stopService();
})();
}
this.callState = CALL_STATES.DISCONNECTED;
Expand All @@ -304,8 +304,8 @@ export default class CallScreen extends React.Component {
this.callState = CALL_STATES.CONNECTED;
if (Platform.OS === 'android' && Platform.Version >= 26) {
(async () => {
ForegroundService.getInstance().createNotificationChannel();
ForegroundService.getInstance().startService();
await ForegroundService.getInstance().createNotificationChannel();
await ForegroundService.getInstance().startService();
})();
}
};
Expand Down
5 changes: 5 additions & 0 deletions VoximplantDemo/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,11 @@
dependencies:
eslint-visitor-keys "^1.1.0"

"@voximplant/react-native-foreground-service@^3.0.2":
version "3.0.2"
resolved "https://registry.yarnpkg.com/@voximplant/react-native-foreground-service/-/react-native-foreground-service-3.0.2.tgz#14fca496808db5255799ce01553626cdb9aea03e"
integrity sha512-ZIyccOAXPqznA1PAVAYlKZ+GI7kXYCuYgH+gmAkhPouyJbkgrSXaCJJzQ+uBkPr4FBa/PuC/yjzK8vf6tJREQA==

"@xmldom/xmldom@~0.7.0":
version "0.7.9"
resolved "https://registry.yarnpkg.com/@xmldom/xmldom/-/xmldom-0.7.9.tgz#7f9278a50e737920e21b297b8a35286e9942c056"
Expand Down

0 comments on commit db8fc72

Please sign in to comment.