@janiscommerce/app-push-notification 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -29,6 +29,31 @@ Inside remoteMessage you get the notifications object that contains the informat
|
|
|
29
29
|
|
|
30
30
|
For more information about this, read https://rnfirebase.io/reference/messaging/remotemessage
|
|
31
31
|
|
|
32
|
+
## Customize background notification sound:
|
|
33
|
+
|
|
34
|
+
To customize the background notification sound, you can pass the `backgroundNotificationSound` parameter to the `NotificationProvider` component. By default, it uses the 'default' sound.
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
import NotificationProvider from '@janiscommerce/app-push-notification'
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<NotificationProvider
|
|
41
|
+
appName='pickingApp'
|
|
42
|
+
events={["picking:session:created","picking:session:assigned"]}
|
|
43
|
+
environment='beta'
|
|
44
|
+
backgroundNotificationSound='custom_sound' // Custom sound file name
|
|
45
|
+
>
|
|
46
|
+
<MyComponent/>
|
|
47
|
+
</NotificationProvider>
|
|
48
|
+
)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
To use a custom sound on Android, you must:
|
|
52
|
+
1. Place the sound file in the `android/app/src/main/res/raw/` folder
|
|
53
|
+
2. The file name must be lowercase and without special characters
|
|
54
|
+
3. The sound file must be in .mp3, .wav, or .aac format
|
|
55
|
+
4. Pass the exactly file name (without extension) as the value of `backgroundNotificationSound`
|
|
56
|
+
|
|
32
57
|
# This library provides the following components and methods:
|
|
33
58
|
|
|
34
59
|
## Functions
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
* @param {string} environment The environment is necessary for the API that we are going to use to subscribe the device to notifications.
|
|
25
25
|
* @param {object} additionalInfo fields to be sent as part of the body of the subscription request
|
|
26
26
|
* @param {Array<string | object>} channelConfigs is the configuration that will be used to create new notification channels
|
|
27
|
+
* @param {string} backgroundNotificationSound is the sound that will be played when the app is in the background
|
|
27
28
|
* @throws null when not receive a children argument
|
|
28
29
|
* @returns {null | React.element}
|
|
29
30
|
* @example
|
|
@@ -48,6 +49,7 @@ const NotificationProvider = ({
|
|
|
48
49
|
environment,
|
|
49
50
|
additionalInfo,
|
|
50
51
|
channelConfigs = [],
|
|
52
|
+
backgroundNotificationSound,
|
|
51
53
|
}) => {
|
|
52
54
|
if (!children) return null;
|
|
53
55
|
|
|
@@ -58,6 +60,11 @@ const NotificationProvider = ({
|
|
|
58
60
|
const validChannelConfigs =
|
|
59
61
|
!!channelConfigs && isArray(channelConfigs) ? channelConfigs : [];
|
|
60
62
|
|
|
63
|
+
const safeBackgroundSound =
|
|
64
|
+
isString(backgroundNotificationSound) && backgroundNotificationSound?.trim()
|
|
65
|
+
? backgroundNotificationSound.trim()
|
|
66
|
+
: 'default';
|
|
67
|
+
|
|
61
68
|
const isRegistered = useRef(false);
|
|
62
69
|
const {
|
|
63
70
|
registerDeviceToNotifications,
|
|
@@ -113,7 +120,7 @@ const NotificationProvider = ({
|
|
|
113
120
|
|
|
114
121
|
await makeNotificationChannels(parsedChannelConfigs);
|
|
115
122
|
}
|
|
116
|
-
await makeDefaultChannel();
|
|
123
|
+
await makeDefaultChannel({sound: safeBackgroundSound});
|
|
117
124
|
};
|
|
118
125
|
|
|
119
126
|
useEffect(() => {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {AndroidImportance, AndroidVisibility} from '@notifee/react-native';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_CHANNEL_CONFIGS = {
|
|
4
|
+
badge: true,
|
|
5
|
+
importance: AndroidImportance.HIGH,
|
|
6
|
+
lights: true,
|
|
7
|
+
sound: 'default',
|
|
8
|
+
vibration: true,
|
|
9
|
+
vibrationPattern: [500, 1000, 500, 1000],
|
|
10
|
+
visibility: AndroidVisibility.PUBLIC,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default DEFAULT_CHANNEL_CONFIGS;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import notifee, {AndroidImportance} from '@notifee/react-native';
|
|
2
|
+
import DEFAULT_CHANNEL_CONFIGS from '../../constants/defaultChannelConfigs';
|
|
2
3
|
import {isObject, isString} from '..';
|
|
3
4
|
|
|
4
5
|
export const parseChannelConfiguration = (params = {}) => {
|
|
5
6
|
if (!params || !isObject(params)) return null;
|
|
6
7
|
|
|
7
|
-
const {name, id = '', description = ''} = params;
|
|
8
|
+
const {name, id = '', description = '', ...restConfigs} = params;
|
|
8
9
|
|
|
9
10
|
if (!name || !isString(name)) return null;
|
|
10
11
|
|
|
@@ -12,6 +13,8 @@ export const parseChannelConfiguration = (params = {}) => {
|
|
|
12
13
|
const hasValidId = !!id && isString(id);
|
|
13
14
|
|
|
14
15
|
return {
|
|
16
|
+
...DEFAULT_CHANNEL_CONFIGS,
|
|
17
|
+
...restConfigs,
|
|
15
18
|
name,
|
|
16
19
|
id: hasValidId ? id : name,
|
|
17
20
|
importance: AndroidImportance.HIGH,
|
|
@@ -56,12 +59,13 @@ export const makeNotificationChannels = async (channelConfigs) => {
|
|
|
56
59
|
};
|
|
57
60
|
|
|
58
61
|
/* eslint-disable consistent-return */
|
|
59
|
-
export const makeDefaultChannel = async () => {
|
|
62
|
+
export const makeDefaultChannel = async (configs = {}) => {
|
|
60
63
|
try {
|
|
61
64
|
const parsedChannel = parseChannelConfiguration({
|
|
62
|
-
id: '
|
|
63
|
-
name: '
|
|
64
|
-
description: 'Default channel to receive notifications',
|
|
65
|
+
id: 'channel_default',
|
|
66
|
+
name: 'Operational notifications',
|
|
67
|
+
description: 'Default channel to receive operational notifications',
|
|
68
|
+
...configs,
|
|
65
69
|
});
|
|
66
70
|
|
|
67
71
|
await makeNotificationChannel(parsedChannel);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@janiscommerce/app-push-notification",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"description": "This package will take care of performing the main actions for registration to receive notifications in the foreground and background.",
|
|
6
6
|
"main": "lib/index.js",
|