Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sendEvent: (message, sendCallback) => {
let amqpMessage = AmqpMessage.fromMessage(message);
amqpMessage.properties.to = this._d2cEndpoint;
/*Codes_SRS_NODE_DEVICE_AMQP_16_025: [The `sendEvent` method shall create and attach the d2c link if necessary.]*/
if (!this._d2cLink) {
this._amqp.attachSenderLink(this._d2cEndpoint, null, (err, link) => {
if (err) {
handleResult('AMQP Transport: Could not send', sendCallback)(err);
} else {
debug('got a new D2C link');
this._d2cLink = link;
this._d2cLink.on('error', this._d2cErrorListener);
this._d2cLink.send(amqpMessage, handleResult('AMQP Transport: Could not send', sendCallback));
}
});
} else {
debug('using existing d2c link');
send(deviceId: string, message: Message, done: Client.Callback): void {
const deviceEndpoint = endpoint.deviceMessagePath(encodeURIComponent(deviceId));
/*Codes_SRS_NODE_IOTHUB_SERVICE_AMQP_16_002: [The `send` method shall construct an AMQP request using the message passed in argument as the body of the message.]*/
let amqpMessage = AmqpMessage.fromMessage(message);
this._fsm.handle('send', amqpMessage, deviceEndpoint, handleResult('AMQP Transport: Could not send message', done));
}