Skip to content

Commit

Permalink
Merge pull request #63 from FlowFuse/3560-feature-flags
Browse files Browse the repository at this point in the history
Display "feature not available" if feature flag is false
  • Loading branch information
Steve-Mcl authored Mar 19, 2024
2 parents ae6ae46 + e870453 commit 29c8a93
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions nodes/project-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = function (RED) {
// owned device, however an application owned device should not have a projectID.
// therefore, assume project owned if `projectID` is set
const OWNER_TYPE = RED.settings.flowforge.projectID ? 'instance' : 'application'
const featureEnabled = RED.settings.flowforge.projectLink.featureEnabled !== false

// #region JSDoc

Expand Down Expand Up @@ -686,7 +687,11 @@ module.exports = function (RED) {
node.topic = buildLinkTopic(node, node.project, node.subTopic, node.broadcast)

let configOk = true
if (node.broadcast !== true && OWNER_TYPE === 'application') {
if (featureEnabled === false) {
configOk = false
node.status({ fill: 'red', shape: 'dot', text: 'feature not available' })
node.warn('Project Link feature is not available for your current Team.')
} else if (node.broadcast !== true && OWNER_TYPE === 'application') {
configOk = false
node.status({ fill: 'red', shape: 'dot', text: 'unsupported source option' })
node.warn('Receiving direct messages is not supported for application assigned devices. Please update the nodes source option to use "Listen for broadcast messages".')
Expand Down Expand Up @@ -766,9 +771,18 @@ module.exports = function (RED) {
node.subTopic = n.topic
node.mode = n.mode || 'link'
node.broadcast = n.broadcast === true || n.broadcast === 'true'
mqtt.connect()
mqtt.registerStatus(node)
if (featureEnabled === false) {
node.status({ fill: 'red', shape: 'dot', text: 'feature not available' })
node.warn('Project Link feature is not available for your current Team.')
} else {
mqtt.connect()
mqtt.registerStatus(node)
}
node.on('input', async function (msg, _send, done) {
if (featureEnabled === false) {
done()
return
}
try {
if (node.mode === 'return') {
if (msg.projectLink?.callStack?.length > 0) {
Expand Down Expand Up @@ -853,20 +867,28 @@ module.exports = function (RED) {
node.returnLinkMessage(eventId, msg)
}
}

mqtt.connect()
mqtt.registerStatus(node)
// ↓ Useful for debugging ↓
// console.log(`🔗 LINK-CALL responseTopic SUB ${node.responseTopic}`)
mqtt.subscribe(node, node.responseTopic, { qos: 2 }, onSub)
.then(_result => {})
.catch(err => {
node.status({ fill: 'red', shape: 'dot', text: 'subscribe error' })
node.error(err)
})
if (featureEnabled === false) {
node.status({ fill: 'red', shape: 'dot', text: 'feature not available' })
node.warn('Project Link feature is not available for your current Team.')
} else {
mqtt.connect()
mqtt.registerStatus(node)
// ↓ Useful for debugging ↓
// console.log(`🔗 LINK-CALL responseTopic SUB ${node.responseTopic}`)
mqtt.subscribe(node, node.responseTopic, { qos: 2 }, onSub)
.then(_result => {})
.catch(err => {
node.status({ fill: 'red', shape: 'dot', text: 'subscribe error' })
node.error(err)
})
}

node.on('input', async function (msg, send, done) {
try {
if (featureEnabled === false) {
done()
return
}
const eventId = crypto.randomBytes(14).toString('hex')
/** @type {MessageEvent} */
const messageEvent = {
Expand Down

0 comments on commit 29c8a93

Please sign in to comment.