node-red-contrib-df1-gateway
Advanced tools
Comparing version 1.0.6 to 1.0.7
{ | ||
"name": "node-red-contrib-df1-gateway", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "", | ||
@@ -33,4 +33,4 @@ "main": "df1-gateway.js", | ||
"optionalDependencies": { | ||
"@protocols/node-df1-gateway": "^1.0.1" | ||
"@protocols/node-df1-gateway": "^1.0.2" | ||
} | ||
} |
@@ -20,28 +20,65 @@ try { | ||
node.df1 = RED.nodes.getNode(config.df1); | ||
if (!node.df1) { | ||
return node.error(RED._("df1.error.missingconfig")); | ||
const configNode = RED.nodes.getNode(config.endpoint); | ||
if (!configNode) { | ||
return this.error(RED._("df1.error.missingconfig")); | ||
} | ||
const server = new Gateway({productName: config.nameGateway}) | ||
const endpoint = RED.nodes.getNode(config.endpoint); | ||
let df1 = null; | ||
let that = this; | ||
let serverClosed = true; | ||
endpoint.on('connected', () => { | ||
const session = endpoint.getDf1Session() | ||
if(session) registerSession(session); | ||
}); | ||
let _reconnectTimeout = null; | ||
endpoint.on('error', () => { | ||
const session = endpoint.getDf1Session(); | ||
if(session) unRegisterSession(session); | ||
}); | ||
function connect() { | ||
endpoint.on('timeout', () => { | ||
const session = endpoint.getDf1Session(); | ||
if(session) unRegisterSession(session); | ||
}) | ||
if (_reconnectTimeout !== null) { | ||
clearTimeout(_reconnectTimeout); | ||
_reconnectTimeout = null; | ||
}; | ||
df1 = configNode.df1Endpoint(); | ||
if(df1){ | ||
df1.on('connected',registerSession); | ||
df1.on('error',unRegisterSession); | ||
df1.on('timeout',unRegisterSession); | ||
df1.on('disconnect',onDisconnect); | ||
}else{ | ||
onDisconnect(); | ||
} | ||
} | ||
function onDisconnect() { | ||
if(df1 !== null){ | ||
df1.removeListener('connected',registerSession); | ||
df1.removeListener('error',unRegisterSession); | ||
df1.removeListener('timeout',unRegisterSession); | ||
df1.removeListener('disconnect',onDisconnect); | ||
unRegisterSession(); | ||
df1 = null; | ||
}; | ||
if (!_reconnectTimeout) { | ||
_reconnectTimeout = setTimeout(connect, 5000); | ||
}; | ||
} | ||
function getDf1Session() { | ||
const df1protocol = df1.df1Protocol; | ||
if(df1protocol) return df1protocol.dataLinkSession; | ||
} | ||
function registerSession() { | ||
const session = getDf1Session(); | ||
if(session) server.registerDf1(session); | ||
}; | ||
function unRegisterSession() { | ||
const session = getDf1Session(); | ||
if(session) server.unRegisterDf1(session); | ||
}; | ||
server.on('error',(err) => { | ||
@@ -66,10 +103,2 @@ if (serverClosed == false) { | ||
function registerSession(df1) { | ||
server.registerDf1(df1); | ||
}; | ||
function unRegisterSession(df1) { | ||
server.unRegisterDf1(df1); | ||
}; | ||
function closeServer(){ | ||
@@ -85,2 +114,4 @@ serverClosed = true; | ||
}; | ||
connect(); | ||
}; | ||
@@ -87,0 +118,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8105
139