Skip to content

Commit

Permalink
Use singleton connection (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ottoszika authored Dec 9, 2019
1 parent 0310bd6 commit 6bc5e34
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/utils/ewelink-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ module.exports = {
// Set the node status to 'connecting'
this.setNodeStatusToConnecting(node);

// Create a new eWeLink connection instance
const connection = new ewelink(credentialsNode.credentials);
// Get global connection
let connection = node.context().global.eWeLinkConnection;

// If there is no global connection we create a new one and make it singleton
if (!connection) {
connection = new ewelink(credentialsNode.credentials);
node.context().global.eWeLinkConnection = connection;
}

return new Promise((resolve, reject) => {
// Logging in
Expand Down

0 comments on commit 6bc5e34

Please sign in to comment.