The registerToFCM
method registers a device to Firebase Cloud Messaging. Optionally registers with already existing ACG ID and ACG security token.
createFcmECDH
and generateFcmAuthSecret
functions. The auth secret and ECDH keys must be stored.Returns the ACG ID, ACG security token and FCM token, which must be stored.
The FCM token does not seem to expire.
import {
createFcmECDH,
generateFcmAuthSecret,
registerToFCM
} from '@aracna/fcm';
const authSecret = generateFcmAuthSecret();
const ecdh = createFcmECDH();
registerToFCM({
appID: 'YOUR_APP_ID',
ece: {
authSecret: authSecret,
publicKey: ecdh.getPublicKey()
},
firebase: {
apiKey: 'YOUR_FIREBASE_API_KEY',
appID: 'YOUR_FIREBASE_APP_ID',
projectID: 'YOUR_FIREBASE_PROJECT_ID'
},
vapidKey: 'YOUR_VAPID_KEY'
})
.catch(() => {})
.then((registration) => {
// will log { acg: { id: bigint, securityToken: bigint }, token: string }
console.log(registration);
});