The FcmClient class establishes a TLS socket connection with Google MTalk and handles the communication.
registerToFCM
function.createFcmECDH
and generateFcmAuthSecret
functions.close
event when a close message is received.heartbeat
event when a heartbeat is received.iq
event when an IQ stanza is received.login
event when a login response is received.message
event when a message is received.message-data
event when a message is decrypted.The connect
function connects the socket to Google MTalk.
The ACG ID and ACG security token are required to connect.
import { FcmClient } from '@aracna/fcm';
const client = new FcmClient({
acg: {
id: BigInt('YOUR_ACG_ID'),
securityToken: BigInt('YOUR_ACG_SECURITY_TOKEN')
}
});
client.connect();
The disconnect
function disconnects the socket.
import { FcmClient } from '@aracna/fcm';
const client = new FcmClient({
acg: {
id: BigInt('YOUR_ACG_ID'),
securityToken: BigInt('YOUR_ACG_SECURITY_TOKEN')
}
});
client.on('close', () => {
console.log('disconnected');
});
client.connect().then(() => client.disconnect());
The client emits a message
event when a message is received and a message-data
event when a message is decrypted. The client is an event emitter, so you can use the on
function to listen to the events.
The ECE auth secret and ECE private key are required to decrypt the messages.
import { FcmClient } from '@aracna/fcm';
const client = new FcmClient({
acg: {
id: BigInt('YOUR_ACG_ID'),
securityToken: BigInt('YOUR_ACG_SECURITY_TOKEN')
},
ece: {
authSecret: 'YOUR_AUTH_SECRET',
privateKey: 'YOUR_ECDH_PRIVATE_KEY'
}
});
client.on('message', (message) => {
// will log the message
console.log(message);
});
client.on('message-data', (data) => {
// will log the decrypted message data
console.log(data);
});
client.connect();