Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const deviceId = 'node-longhaul-sak-' + uuid.v4();
let protocol;
/* tslint:disable:no-var-requires */
switch (process.env.DEVICE_PROTOCOL) {
case 'amqp':
protocol = require('azure-iot-device-amqp').Amqp;
break;
case 'amqp-ws':
protocol = require('azure-iot-device-amqp').AmqpWs;
break;
case 'mqtt':
protocol = require('azure-iot-device-mqtt').Mqtt;
break;
case 'mqtt-ws':
protocol = require('azure-iot-device-mqtt').MqttWs;
break;
case 'http':
protocol = require('azure-iot-device-mqtt').Http;
break;
default:
debug('unknown protocol: ' + process.env.DEVICE_PROTOCOL);
process.exit(ERROR_EXIT_CODE);
}
/* tslint:enable:no-var-requires */
const createDevice = (callback) => {
debug('creating device: ' + deviceId);
timeout(registry.create.bind(registry), MAX_CREATE_TIME)({ deviceId: deviceId }, (err, deviceInfo) => {
if (err) {
debug('error creating device: ' + deviceId + ':' + err.toString());
callback(err);
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
/*jshint esversion: 6 */
var respondWithCode = require('../utils/writer').respondWithCode;
var debug = require('debug')('azure-iot-e2e:node')
var Mqtt = require('azure-iot-device-mqtt').Mqtt;
var MqttWs = require('azure-iot-device-mqtt').MqttWs;
var Amqp = require('azure-iot-device-amqp').Amqp;
var AmqpWs = require('azure-iot-device-amqp').AmqpWs;
var Http = require('azure-iot-device-http').Http;
/**
* return failure to the caller, passing the appropriate information back.
*
* @param {function} reject reject function from Promise
* @param {Error} err error to return
* @param {string} functionName name of function with failure
*/
var returnFailure = function(reject, err, functionName) {
var errorText = '';
if (functionName) {
errorText = 'failure from ' + functionName + ': ';
}
function mqttWsTest(deviceConnectionString, done) {
runTest(deviceConnectionString, require('azure-iot-device-mqtt').MqttWs, 'MQTT/WS', done);
}
var Protocol;
switch(protocolArg) {
case 'amqp-ws':
Protocol = require('azure-iot-device-amqp').AmqpWs;
break;
case 'http':
Protocol = require('azure-iot-device-http').Http;
break;
case 'mqtt':
Protocol = require('azure-iot-device-mqtt').Mqtt;
if (settleMethod !== 'complete') {
inputError('Cannot ' + settleMethod + ' messages with MQTT: messages are automatically completed.');
}
break;
case 'mqtt-ws':
Protocol = require('azure-iot-device-mqtt').MqttWs;
if (settleMethod !== 'complete') {
inputError('Cannot ' + settleMethod + ' messages with MQTT: messages are automatically completed.');
}
break;
default:
Protocol = require('azure-iot-device-amqp').Amqp;
break;
}
var sendInterval = program.sendInterval || 1000;
var sendCount = program.sendCount || Number.MAX_SAFE_INTEGER;
var receiveCount = program.receiveCount || Number.MAX_SAFE_INTEGER;
var uploadFilePath = program.uploadFile;
var deviceConnectionString;
var deviceId = program.args[0];