-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
48 lines (39 loc) · 1.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* @format
*/
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import { API_URL } from '@env';
import io from 'socket.io-client';
import notifee, { AndroidImportance } from '@notifee/react-native';
const socket = io(API_URL);
socket.on('connect', () => {
console.log('Connected to socket.io server');
});
socket.on('new_notification', async (data) => {
console.log('Received new notification:', data);
// Request permissions (required for iOS)
await notifee.requestPermission()
// Create a channel (required for Android)
const channelId = await notifee.createChannel({
id: data.userId,
name: 'Rekados Push Notification',
importance: AndroidImportance.HIGH,
});
if (data.userId !== data.authorId) {
// Display a notification
await notifee.displayNotification({
title: data.title,
body: data.message,
android: {
channelId,
// pressAction is needed if you want the notification to open the app when pressed
pressAction: {
id: 'default',
},
},
});
};
});
AppRegistry.registerComponent(appName, () => App);