This is a simple example that shows NodeJS to OpenFin integration. We co-deploy a NodeJS service with our OpenFin application (see the app.json file for specifics) and use the Inter Application Bus on both side to demonstrate connectivity.
npm install && npm start
- On
npm start
the "node-service" folder will be zipped up and moved to the public folder. - Simulating a remote web server,
grunt:connect
will serve the public folder - The OpenFin
grunt:openfin
plugin (github) will launch the node-integration-example application from public/app.json.
On a successfull launch, the contents of the "node-service" folder will be deployed onto OpenFin and launched by main.js:
fin.desktop.System.launchExternalProcess({
alias: nodeServiceAlias,
arguments: 'index.js --port ' + port,
lifetime: 'window'
}, payload => resolve(payload)
, (reason, error) => reject(error));
The "node-service" will use the node-adapter to connect to the OpenFin Bus in index.js:
const { connect } = require('node-adapter');
const connectOptions = {
address: `ws://localhost:${port}`,
uuid: 'node-integration-example-service',
nonPersistant: true
};
connect(connectOptions).then(onConnected);
See the Gruntfile for specifics.
Both the NodeJS service and the OpenFin application publish/subscribe to messages over the Inter Application Bus:
NodeJS side: index.js
//use the inter application bus.
fin.InterApplicationBus.subscribe(webAppIdentity, toServiceTopic, (msg, senderIdentity) => {
console.log(`Received ${msg.data}
from ${senderIdentity.uuid}, ${senderIdentity.name}
at: ${new Date(msg.timeStamp).toLocaleTimeString()}`);
}).catch(err => console.log(err));
//send messages every second.
setInterval(() => {
fin.InterApplicationBus.send(webAppIdentity, toWebTopic, {
data: 'Hello web',
timeStamp: Date.now()
});
}, 1000);
OpenFin side: main.js
fin.desktop.InterApplicationBus.subscribe(serviceUuid, toWebTopic, function(msg, uuid) {
messageCtrl.innerText = `Received ${msg.data} from ${uuid}`;
timeStampCtrl.innerText = new Date(msg.timeStamp).toLocaleTimeString();
});
setInterval(() => {
fin.desktop.InterApplicationBus.send(serviceUuid, toServiceTopic, {
data: 'Hello Service',
timeStamp: Date.now()
});
}, 1000);
MIT
The code in this repository is covered by the included license.
However, if you run this code, it may call on the OpenFin RVM or OpenFin Runtime, which are covered by OpenFin’s Developer, Community, and Enterprise licenses. You can learn more about OpenFin licensing at the links listed below or just email us at support@openfin.co with questions.
https://openfin.co/developer-agreement/
https://openfin.co/licensing/
Please enter an issue in the repo for any questions or problems. Alternatively, please contact us at support@openfin.co