nest-mqtt
nest-mqtt copied to clipboard
Issue when publishing binary buffer or Uint8Array
When trying to publish a proto binary buffer the object is converted to JSON string, but it should be published as it is since the client supports buffer / Uint8Array
One way to do it is to change the condition as follow:
if (typeof message === 'object' && !Buffer.isBuffer(message)) {
message = JSON.stringify(message);
}
Is it possible to apply this change ? Thanks Andrea
Code from mqtt.service.ts :
publish(topic: string, message: string | Buffer | object, opts?: IClientPublishOptions): Promise<Packet> {
return new Promise<Packet>((resolve, reject) => {
if (typeof message === 'object') {
message = JSON.stringify(message);
}
this.client.publish(topic, message, opts || null, (error, packet) => {
if (error) {
reject(error);
} else {
resolve(packet);
}
});
});
}
Thanks for your opinion. Welcome for your pull requests.