-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
33 lines (26 loc) · 836 Bytes
/
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
// NOTE: Needed in order to avoid depending on the window object
require('cometd-nodejs-client').adapt();
const lib = require('cometd');
const cometd = new lib.CometD();
const config = require('./config.json');
const authLib = require('./lib/salesforceAuth.js');
main();
async function main() {
const authToken = await authLib.authenticate(config);
cometd.configure({
url: `${config.myDomain}/cometd/54.0/`,
requestHeaders: {
Authorization: `Bearer ${authToken}`,
},
});
cometd.handshake(function (h) {
if (h.successful) {
// Subscribe to receive messages from the server.
cometd.subscribe(config.platformEvent.topicChannel, function (message) {
const dataFromServer = message.data;
console.log('>>> Data: ');
console.log(dataFromServer);
});
}
});
}