Repository navigation
Expand file tree
/
Copy pathpush.js
More file actions
59 lines (44 loc) · 1.29 KB
/
Copy pathpush.js
File metadata and controls
59 lines (44 loc) · 1.29 KB
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
49
50
51
52
53
54
55
56
57
58
59
const {
FirebaseApp,
PushReceiver,
PushSender,
} = require('../dist');
const crypto = require('crypto')
const { default: Conf } = require('@eneris/conf')
const main = async () => {
const storage = new Conf({
cwd: __dirname,
configName: 'storage',
fileExtension: 'json',
serialize: (data) => JSON.stringify(data, null, 2),
deserialize: JSON.parse,
})
const app = new FirebaseApp({
credentials: {
// Insert Firebase config here
},
storage,
crypto,
});
const client = new PushReceiver(app, {})
await client.connect();
if (!client.fcmToken) {
throw new Error('FCM token was not generated')
}
console.log('FCM token:', client.fcmToken)
client.onNotification((data) => {
console.log('onNotification', data);
});
const sender = new PushSender({
// Insert Firebase service account JSON here
});
await new Promise((res) => setTimeout(res, 2000))
await sender.testMessage(client.fcmToken);
await new Promise((res) => setTimeout(res, 2000))
await sender.testMessage(client.fcmToken);
await new Promise((res) => setTimeout(res, 2000))
}
main().catch((err) => {
console.error('Error in main:', err);
process.exit(1);
})