I am integrating MQTT-adonis module adonis-mqtt respo on git here in adonis-js
application while serving it throws an exception
TypeError: instance[method].bind is not a function
Can any one guide why this is appearing.
//event.js
'use strict'
const Event = use('Event');
const Mqtt = use('Mqtt');
// Listen to some Events of the library
Event.on('MQTT:Connected', 'Message.subscription')
Event.on('MQTT:Disconnected', 'Message.disconnected')
//Listeners/Message.js
class Message extends MqttListener {
get subscription () {
return 'Topic/Info'
}
async handleMessage (message, wildcardMatches) {
}
it appears that it is throwing exception here in this block
//node_modules/adonis-mqtt/Mqtt/Mqtt.js
this.client.on('connect', this._handleConnect.bind(this)) //here at this line
this.client.on('offline', this._handleDisconnect.bind(this))
this.client.on('close', this._handleDisconnect.bind(this))
this.client.on('end', this._handleDisconnect.bind(this))
this.client.on('message', this._handleMessage.bind(this))
EDIT:::
How to reproduce this:
pre-requisite:
clone this:
move to directory path
npm install
adonis serve --dev
Update:
while removing get from subscription function, it works with no error, but I am unable to get the required data in following code snippet
//node_modules/adonis-mqtt/Mqtt/Mqtt.js
async _registerListener (file) {
const filePath = path.join(this.listenersPath, file)
let task
try {
task = require(filePath)
} catch (e) {
if (e instanceof ReferenceError) {
debug(
'Unable to import task class <%s>. Is it a valid javascript class?',
file)
return
} else {
throw e
}
}
// Get instance of task class
const taskInstance = ioc.make(task)
if (!taskInstance.subscription || taskInstance.subscription === '') {
console.error(`MqttListener ${file} does not have a subscription string!`)
} else {
this.client.subscribe(taskInstance.subscription) // here
debug('Subscribed to topic %s', taskInstance.subscription)
console.log('Subscribed to topic %s', taskInstance.subscription)
this.listeners.push(taskInstance)
}
}
Update: 2
There are two folders in app one is Listeners and other is MqttListeners, thse both have same named file Test.js
, it is also forcing to keep both files. However changes in file exist in Listener folder doesnt make any impact. However removing get prefix from subscription function and console messages in handleMessage()
from MqttListners folder's file is seems to be perfect. Receiving published topics info